Backing up your Debian/Ubuntu VPS to Rackspace Cloud Files
There are quite a number of tutorials available on backing up to Amazon S3, which is popular due to its redundancy and low cost (15cents per gigabyte). I prefer Rackspace Cloud Files though due to its lower upload fees (8cents vs 10cents per gigabyte of bandwidth). We will use duplicity to create the backups because it is bandwidth efficient and also allows us to encrypt our backups.
We will also be setting up the cloudcity script to make it easier to automate the backup and restore process.
First set up build essential so that you can do necessary compiling later.
apt-get install build-essential
Debian Lenny and Ubuntu < 10.04 come with older versions of Duplicity. We need to add additional repositories to install a newer version of duplicity from.
On Debian Lenny
add this line
deb http://www.backports.org/debian lenny-backports main contrib non-free
Next run the following commands in succession
apt-get install debian-backports-keyring
apt-get -t lenny-backports install duplicity
On Ubuntu 9.10 and earlier
sudo add-apt-repository ppa:duplicity-team/ppa
On older (pre 9.10) Ubuntu systems:
sudo nano /etc/apt/sources.list
Add the relevant Duplicity source; for Ubuntu 8.04 it would be:
deb http://ppa.launchpad.net/duplicity-team/ppa/ubuntu hardy main
deb-src http://ppa.launchpad.net/duplicity-team/ppa/ubuntu hardy main
Next run these commands
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 7A86F4A2
sudo apt-get update
sudo apt-get install duplicity
Check that the installed version is > 0.5
Setup your GPG keys for encryption of your backups
You’ll be walked through a few options for your key, select the following:
Key type – DSA and Elgamal (Default)
Key size – 2048 bits (Again, the default)
Expiration – Do not expire
Name, Comment and Email – You can enter whatever you like here
Password – Make sure you remember whatever you type, there’s no way to get it back if you forget!
When it talks about “generating entropy” to make the key, it means that the server needs to be in use in order for it to get some random numbers. Just go refresh a webpage on the server a few times, or run some commands in another terminal window.
Create backups of your keys by following the steps here:
Copy the backups to a safe and secure location – OFF this computer.
Download and extract the tgz of the latest release. Then install it.
tar xzvf rackspace-python-cloudfiles-48dd7c8.tar.gz
python setup.py install
Browse to http://github.com/jspringman/cloudcity/blob/master/cloudcity
Copy the text of the cloudcity script and edit the following lines at minimum:
# Cloud Files information you can get from https://manage.rackspacecloud.com/
#This is the password you typed in when creating your GPG keys earlier
# Specify the name of the container/directory in your Cloud Files account where the backup files are to be stored
# List ONLY the directories that you want to backup, for instance
INCLUDE_LIST=( “/home” “/root” “/var/www”)
Edit the other parameters as desired.
Create a file for the script
and paste the edited script contents discussed above.
Next give it permissions to run
chmod +x cloudcity.sh
Ok you’re ready to backup!
When completed, you will see
You may wish to setup a cron job to call this script every night.
To view restore options
Be sure to keep a copy of cloudcity.sh!
Restoring on another computer
In the event of a catastrophic crash, the computer you are restoring your backups to will need to be set up the same way as above but with ONE difference; do not create GPG keys again, but restore your keys (that you’d backed up earlier) following the steps here
Now use cloudcity.sh to restore your backed up files!
Note: Here is a similar tutorial on backing up your MySQL databases to Rackspace Cloud Files