Posts Tagged ‘backup’

Articles

How BackInTime works

In Version control on May 19, 2010 by Matt Giuca Tagged:

I’ve just become a fan of the BackInTime backup utility for Linux. I previously rolled my own backup utility which used rsync, but it didn’t do incremental backups and I’ve become increasingly worried about overwriting my only good backup with a dud. I’ll only trust such a tool if I understand how it works, and BackInTime is extremely simple. I’ve briefly perused the source code but mostly figured out how it works by reading the command-line output and examining the directory structure it creates. So here’s a brief rundown of how it works, for technical users:

  1. Tests whether the drive has changed since last snapshot (using rsync), and if not, quit.
  2. cp -al <previous snapshot> <new snapshot>. This creates a complete recursive copy, but every single file is hard-linked to the old snapshot.
  3. rsync -aEAX –delete-excluded –delete –chmod=Fa-w,D+w <current directory> <new snapshot>. This copies every modified file over the top of the existing hardlink (deleting the hardlink and creating a new file), and sets it to read-only.
  4. Create a simple CSV file fileinfo.bz2 which contains each file’s original permission bits, owner and group.

That’s it. The important thing is I didn’t want my backup hidden away in a database or other opaque structure; I just want it to be files. Of course, the hard-linking makes the backups inexpensive, as only the modified files take up additional space in each snapshot.

You can restore a BackInTime backup, if you have to, just by copying the files over — however, they will be read-only, so it’s preferable if you use BackInTime’s restore function (sadly and confusingly this isn’t available from the command-line, only the GUI).  You can restore individual files or whole directories. The restore process is just:

  1. If the original file already exists, rename it to <filename>.backup.<date>.
  2. rsync the file over to the original location.
  3. Lookup the mode/owner/group in fileinfo.bz2 and set it on the file.

My only concern with this is that if you restore the entire backup over an existing copy, you will end up with .backup.<date> files all over the place, which would be hell to clean up. Also the “Restore” button has no prompt :/

Features also include:

  • Command-line, Gnome or KDE4 GUI support (though as mentioned, restoration is GUI-only).
  • Browse any snapshot from the GUI or in a regular file browser.
  • Graphical diff between any files across snapshots, via Meld.
  • Optionally auto-remove snapshots according to some very smart rules: “Keep all snapshots from today and yesterday; keep one snapshot for the last week and one for two weeks ago; keep one snapshot per month for all previous months of the year; keep one snapshot per year for all previous years; delete the rest.” This seems like a perfectly fine “logarithmic backup” rule, which I have turned on (it is off by default, which I like).
  • Ability to set rsync “exclude” rules by regex.

OK guys, I am sold.

  1. Tests whether the drive has changed since last snapshot, and if not, quit.
  2. cp -al <previous snapshot> <new snapshot>. This creates a complete recursive copy, but every single file is hard-linked to the old snapshot.
  3. rsync -aEAX –delete-excluded –delete –chmod=Fa-w,D+w <current directory> <new snapshot>. This copies every modified file over the top of the existing hardlink (deleting the hardlink and creating a new file), and sets it to read-only.