Yet Another Backup Script: mrbStudio

Posted on Jun 13, 2012 in All Articles, Featured Articles, Files, Linux and Open Source, Programming, Technology

Some years ago I decided that I needed backups. Our systems are more fragile than we tend to think; hardware break downs, hard disks failures, laptop thefts, accidents, software malfunctions or user errors can strip us of our precious data. By data I mean both things we can’t afford to lose (like your work files or photographs) or things it would take a great amount of time to replace (like your OS installation along with a ton of custom settings).

I tried to think of a backup policy that would work for me, an advanced user. I knew I wanted something that would be easy to access, like a copy of an original directory and maybe versions, so I can return my files to a point in time. After that I searched the net for tested policies and solutions on the matter. What I liked best was rsync (which I already used for simple backups) and hard links. I think this guide was the one that grabbed my attention. I didn’t use the script which it includes, but I learnt all about hard links and how to use them to reserve space.

After that I proceeded to write my own script, mrbStudio, which I use since then for my backups and that have saved my ass more than a few times.

What it does? It copies the directory you want to backup to a backup directory, while preserving any special information you may need (file attributes, ownerships, links, devices, etc). Only the first time though it copies the whole directory. Next time, it uses the most recent backup as a starting point (hard-linking to it or snapshotting if you use btrfs) and copies only the files that have changed since. This saves time and space. It could save more space if something like rdiff was used but that would make my backups inaccessible through easy means. I want my backups accessible, that is a priority.

I won’t go in much detail. Since mrbStudio helped me many times and became part of my system maintenance routine, I thought I should share it. Cleaning, restructuring the code and adding documentation for this task, also helped me make it better.

Its features:

  •  Versioned backups of local and remote filesystems (through ssh) to a local filesystem.
  •  Easy to run once you create your configuration files, no need to postpone your backups again.
  •  Hard links or btrfs snapshots are used for backup versions in order to save time and space.
  •  Easy way to exclude files from backups.
  •  Automatic mounting of local and/or remote filesystems if needed.
  •  Backups are exact copies of the original directories, no special software needed to access them, only a shell.
  •  Script is compact and easy to modify. You need an extra feature? You can implement it fast.

Running it is easy. First you have to create a configuration file. Let’s say you want to backup your home to /media/backups/. Create a home.mrbStudio text file like this:


Now call mrbStudio with the above file as parameter:

$ mrbStudio home.mrbStudio

That’s it, congratulations, your first backup is ready. Next one will take less time (and space).

You will understand it much better once you take a look at the examples that come with the script.

You can find the latest version at github:

Extra tip!

Btrfs is almost mainstream these days and performs so well that I use it for my rootfs and for one of my backup disks. A cool feature of btrfs is subvolumes, which you can mount as partitions. Getting what am I going to say? I just installed grub in a small partition on my usb hard disk I use for backups and now, by editing just two files (fstab and grub.conf), I can boot into my backups through usb! How cool is that?

I get my main system (a laptop) stolen? I find a replacement system, I edit two lines of two files on my usb disk and I can boot into my system and continue my work like nothing happened. When I find the time I can make the system more permanent, like copy it to the internal disk of the new system.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>