joe.terrarum.net

Using rdiff-backup on Dreamhost

Introduction

rdiff-backup is a *nix-based utility that combines "the best features of a mirror and an incremental backup". It wil mirror a directory but also keep enough meta-data available to recreate the directory at any point in time.

I installed rdiff-backup on my Dreamhost account to backup my websites. Though I use version control, I sometimes forget to commit files frequently enough. Having rdiff-backup run once an hour helps me with this as well as provides protection against the version control repository becoming corrupt. Plus, having a backup copy never hurts.

Installing librsync

The prerequisite for rdiff-backup is librsync. Download and install it:

mkdir build
cd build
wget http://path/to/librsync-0.9.7.tar.gz
tar xzvf librsync-0.9.7.tar.gz
cd librsync-0.9.7
./configure --prefix=/home/username/local

The --prefix switch will install librsync to the /home/username/local directory. Since you only have access to your home directory with Dreamhost, everything needs installed local to that rather than system-wide.

make
make install

Installing rdiff-backup

Download the development version from the rdiff-backup homepage.

cd build
wget http://path/to/rdiff-backup-1.1.14.tar.gz
tar xzvf rdiff-backup-1.1.14.tar.gz
cd rdiff-backup-1.1.14.tar.gz
python setup.py build_ext --include-dirs=/home/username/local/include/ --library-dirs=/home/username/local/lib
python setup.py install --prefix=/home/username/local

Modifying rdiff-backup

Due to the security restrictions with Dreamhost and reading the /home directory, rdiff-backup will fail to run. Therefore, the /home/username/local/lib/python2.3/rdiff-backup/Main.py file needs modified. This patch should work.

Configuring Your Environment

With the new libraries and programs in the ~/local directory, you'll need to modify your .bash_profile to get your shell to recognize them:

export PYTHONPATH=$PYTHONPATH:/home/username/local/lib/python2.3/site-packages
export PATH=$PATH:/home/username/local/bin

Then either re-login or run

source .bash_profile

Running rdiff-backup

Again, because of Dreamhost's security restrictions, running rdiff-backup will be a little different. The general idea will be to tell rdiff-backup to exclude everything in your home directory, then include the folders you want, and specify a destination directory.

cd
rdiff-backup --include ./directory1 --include ./directory2 --include ./directory3 --exclude . . backups

This command will backup directory1, directory2, and directory3 to the directory backups and exclude everything else.

Automating rdiff-backup

To automate rdiff-backup, you'll need to make a shell script and a cron job. The shell script should look something like this:

#!/bin/bash
export PYTHONPATH=$PYTHONPATH:/home/username/local/lib/python2.3/site-packages
export PATH=$PATH:/home/username/local/bin

cd /home/username

/home/username/local/bin/rdiff-backup \
        --include ./directory1 \
    --include ./directory2 \
    --include ./directory3 \
    --exclude . . ./home/username/backups

You can now create a cron job with the action:

/bin/sh /home/username/backup-script.sh

I specified absolute paths to everything since I had a little difficulty initially setting the cron job up.

Conclusion

You should now have a working, automated, backup plan for your websites on Dreamhost. Granted, these backups are not offsite, but they will still help you with file corruption and accidental deletes.