Categories
Linux Python Sysadmin

Backup Your Dropbox Files with rdiff-backup

The Problem

Teresa and I use a single Dropbox account to share files between our computers. I also use the same account to store (and sync) plain-text notes on my iPad and iPhone (I use the apps PlainText and iA Writer). In case things go wrong with these apps, the syncing, or with Dropbox itself, I want to backup my Dropbox files and keep past snapshots of the backups so I can go back in time.

The Solution

rdiff-backup can do this. It is a command-line tool written in Python that:

…backs up one directory to another, possibly over a network. The target directory ends up a copy of the source directory, but extra reverse diffs are stored in a special subdirectory of that target directory, so you can still recover files lost some time ago. The idea is to combine the best features of a mirror and an incremental backup.

To make this all happen, I have Dropbox installed, signed-in, and running on my Linux desktop/server, which runs Ubuntu 11.04 Natty with Gnome 2.

Install rdiff-backup thusly:

    # aptitude install rdiff-backup

I use the directory /backup/ to hold all my backup targets, so I can run rdiff-backup like this:

    $ rdiff-backup  \
        --exclude $HOME/Dropbox/.dropbox \
        --exclude $HOME/Dropbox/.dropbox.cache \
        $HOME/Dropbox /backup/Dropbox

Every time I run rdiff-backup like this, it creates a new snapshot of my Dropbox files. Old snapshots are kept until I decide to purge them (if at all). To purge any snapshots older than two months, for example, I run this command:

    $ rdiff-backup --force --remove-older-than 2M /backup/Dropbox

I run the above two commands in an @hourly crontab script to keep this all happening automatically.

Browsing Past Snapshots

rdiff-backup has its own commands for digging into the files stored in the past snapshots, but it requires exactly knowing the filenames and backup times. Another tool, rdiff-backup-fs solves this problem by mounting the rdiff-backup backup directory as a FUSE filesystem, allowing me to grep and find my way through a directory tree of all snapshots.

After installing FUSE and rdiff-backup-fs, I mount my Dropbox snapshot tree with this command:

    $ rdiff-backup-fs ~/mnt /backup/Dropbox

Note that the order of the arguments for mounting source and target are backwards compared to the canonical mount command.

A long listing of my 10-oldest snapshots looks like this:

    $ ls -lF ~/mnt/ | head -10
    total 0
    dr-xr-xr-x 1 root root 4096 2013-03-10 13:52 2013-01-06T05:00:01/
    dr-xr-xr-x 1 root root 4096 2013-03-10 13:52 2013-01-06T06:00:01/
    dr-xr-xr-x 1 root root 4096 2013-03-10 13:52 2013-01-06T07:00:01/
    dr-xr-xr-x 1 root root 4096 2013-03-10 13:52 2013-01-06T08:00:01/
    dr-xr-xr-x 1 root root 4096 2013-03-10 13:52 2013-01-06T09:00:01/
    dr-xr-xr-x 1 root root 4096 2013-03-10 13:52 2013-01-06T10:00:01/
    dr-xr-xr-x 1 root root 4096 2013-03-10 13:52 2013-01-06T11:00:01/
    dr-xr-xr-x 1 root root 4096 2013-03-10 13:52 2013-01-06T12:00:01/
    dr-xr-xr-x 1 root root 4096 2013-03-10 13:52 2013-01-06T13:00:01/

I can then explore all my snapshots at once with any tools wish.

When done, I unmount the rdiff-backup-fs filesystem with:

    $ /bin/fusermount -u ~/mnt
Categories
Philosophy Python

School

[xkcd's 11th Grade]

Interestingly, Python was first released when I was in Grade 11. Via xkcd.

Categories
China Python

Post Holiday Rest and Relaxation

Well, Lily and I had an excellent holiday. We visited family in NE China, wore lots of clothes to keep warm, ate really well, and enjoyed the fireworks and the stars. (In fact, back in Beijing, people are still setting off fireworks for the rest of the week.) It was a great experience for me to celebrate the Spring Festival in China. One fun moment was buying ice cream bars from a street vendor at -20°C! At that temperature, a cardboard box is all you need for refrigeration.

Since coming home to Beijing, I’ve rested lots, and been working at home for the week since the office is closed. (I need to make up for all the work I missed since I took my holiday earlier than everyone else.) But I got it all done and it’s Friday night. I’m looking forward to going out and watching the sunset and then maybe I’ll go out for pizza.

Also this week, for some reason, I’ve gone crazy playing and hacking around in Python. Maybe I missed my computer lots on my holiday. (I think so!) I wrote a command-line equivalent to the Unix cal(1) command which prints calendars like this for any month and/or year:

   February 2003
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

It’s not that big of a deal though since Python has this as a built in module. But it needed a command-line interface, so now my windows box has a cal command. I’m also working with a full-text indexer to index all the textfiles (and email messages) on my computer to aid with searching for stuff I’ve archived long ago. I am also planning to write a simple equivalent to the GNU locate command, to just help find locations of files (not their contents) on my computer.

Of course, when I come up with something useful, I need to stick it on my webpage to share with the world. Fun, fun, fun!