How to Easily Backup Your Site in DVD

I know I promised to talk about the new product I am working on. But I will have to wait couple more days for that. Today I will describe how I setup a backup system for my sites. I have always found that backing up sites in a some CD or DVD very useful. It feels more reliable when you can keep a hard copy with you. Let’s review the other options:

1. Remote Server Backup:
First Interlogy started on virtual host in 1999. Then it turned out to be very restrictive to not having a real machine with root access and all. So, we have moved it to RackSpace which was great but too expensive. Currently interlogy lives on a ServerBeach dedicated machine. So things change, remote server backups are mostly only useful for emergency situations. They are not long term and most of the times you are leaving your data in the hands of someone you have almost no control over.

I think there is a really good opportunity in the market for a service to provide permanent remote backup. A simple service that mirrors your web hosting account for a small monthly free. You simply enter your FTP login and password, and let it do the rest. A bonus would be to make an AJAX based cool interface that would let you easily browse an old backup from your browser.

2. Saving Your Site in Your Hard Drive
Saving the data on your hard disk is also pretty risky, since I have had my hard disks blow up on me. Twice in the last 5 years. It also takes a very long time to download especially big web sites so you have to come up with a robust process that will not require you to restart everything from scratch if you accidentally unplug your DSL modem. The backup tool also needs to not block your current work if you are working on the same machine.

My Solution: DVD Backup using Rsync
My current web site DVD backup process works really well. My complete site and development environments are archived silently in the background on my powerbook laptop. When, Patrick, our part-time graphic designer uploads a psd file on his development site, the file is also mirrored on my computer in a matter couple of hours without me even aware of it. The backup is currently about 3GBs. Once in a while I burn this backup into a DVD and have a warm and fuzzy feeling about keeping my data in a long-term storage.

Requirements
Implementing an rsync based local mirror is actually pretty easy. Especially if you have a Mac OS X like me. There are windows versions of rsync, but I will describe how to do it on UNIX local machine. This tutorial also assumes your remote server is UNIX based. I have implemented this on my main machine, OS X 10.4 Tiger installed Powerbook G4 laptop.

Step 1. Setup Passwordless Remote SSH Login
We will first setup SSH authorized keys so that our background process can connect to the remote server without a password prompt.
1) First, let’s make keys on your local machine. Go to “~/.ssh/authorized_keys” on your shell. Run this command but enter no password when asked:
ssh-keygen -t rsa
2) Open “id_rsa.pub” file and copy the contents.
3) SSH to your remote server and paste the public key into “~/.ssh/authorized_keys”
Now, you can test it by sshing to your server. You should be asked no password.

Step 2. Prepare Local Backup Folder:
Now, create a folder on your local machine to sync your remote site in. A good place might be “~/.backup” or “~/backup”. Under this folder create separate folder for your sites, such “~/backup/domain.com”.

Step 3. Run rsync for the first time:
On your command prompt, go to your backup folder and run rsync for the first time:
rsync -a -e ssh login@domain.com:~/public_html/ ~/backup/domain.com/

Step 4. Automate the process:
Put your command into a single shell script. However, we do not want to run it multiple times. Here is what your backup.sh should look like:

#!/bin/sh
PROC_EXISTS=`ps -A | grep backup.sh | grep -v grep | wc -l`
echo $PROC_EXISTS
if [ $PROC_EXISTS -lt 1 ]; then
  rsync -a -e ssh login@domain.com:~/ ~/backup/domain.com/
else
  echo "Backup is already running..."
fi

Now, add this script into your cronjob by calling “crontab –e” so that it runs every hour and pulls the changed or new files from the server:
5 * * * * /Users/LOGIN/backup/backup.sh 2>>/Users/login/backup/errors.log

Rsync is really cool. It will only get the changed files. It has a very low footprint. If you would like to learn more about it, here is a good tutorial.

If you have data in your mysql also run a process to save it in a text file, so that this file will also be backed up:
22 2 * * * /usr/bin/mysqldump –all-databases | gzip > /home/LOGIN/mysql/all.sql.gz

3 Responses to “How to Easily Backup Your Site in DVD”

  1. Josh says:

    Pretty cool.. I’m doing something similar with RYSNC+SSH but I have remote backup storage space at ByteFortress (www.bytefortress.net)

  2. Matthew C. Kriner says:

    Nice post :-) Regards, S.

Leave a Reply

Security Code: