1. Normal non-incremental backups
First, you need to setup ssh public and private keys. Do you know how?
On the server where you are doing the backup (we will call it the backup server), generate a private and public key pair, with an empty passphrase. You can do this using:
ssh-keygen -t rsa
Then upload the public key that is located in your .ssh/id_rsa.pub in the backup server, and put it in the VPS in:
/root/.ssh/authorized_keys2
Check that from the backup server, you can ssh the VPS without typing any password. Then apt-get install rsync on both servers. From the backup server, you must then be able to type:
rsync --delete -e ssh -azvp hostname-of-vps.com:/var/www /local/destination
with of course /local/destination being a local path in your backup server.
Best is then to do an automated backup of all of your database using a small script on the VPS. Something like that will do:
#!/bin/sh
pushd /var/www
mysqldump -c --all-databases >backup.sql
gzip backup.sql
popd
2. Using automysqlbackup to backup your databases as well
You can use the automysqlbackup to make a dump every day of your database. You'll find this script at sourceforge, it's quite easy to understand it, so we wont discuss how it works. Just to let you know, we use /var/www/sql_backup as destination so then we just need to backup the full /var/www and then everything is included in the rsync backup, including dumps of databases.
3. Incremental backups using dirvish
First, prepare a dirvish user on the server you wish to backup. This server must have the rights to run rsync, so edit /etc/sudoers and add a line like this:
dirvish ALL = NOPASSWD: /usr/bin/rsync
then from the backup server, you need to access to this file. As root, on the backup server, generate a key with ssh-keygen (the way described above), with an empty passphrase. Copy the resulting .ssh/id_rsa.pub in the /home/dirvish/.ssh/authorized_keys2 file of the server to backup. Then try to login. It shouldn't prompt for any password.
Next, install dirvish on the backup computer (where you backups will be stored):
apt-get install dirvish
Then edit /etc/dirvish/master.conf with a content like this one:
bank:
/backup
index: text
exclude:
lost+found/
/proc
/sys
/etc/mtab
/var/cache/apt
core
*~
.nfs*
/tmp/*
Runall:
host1.example.com
host2.example.com
image-default: m%d
expire-default: +7 days
rsh: ssh -o "BatchMode yes" -o "StrictHostKeyChecking no"
The bank: thing is where you will be storing your backup. There can be more than one. Runall: is what you will backup. It can be anything. For each of the runall lines, you need to create a folder. For this example, you will need to do this:
mkdir -p /backup/host1.example.com/dirvish
mkdir -p /backup/host2.example.com/dirvish
then cd in the first dir and edit default.conf. Add the following to the file:
rsync-client: sudo rsync
client: dirvish@node0103.gplhost.com
tree: /var/www/sites
Now you're almost ready. You just need to initialize a first backup. Do this with this simple command:
dirvish --vault host1.example.com --init
This will create the first rsync backup, so it can take a long time. Be patient. Once done, you have nothing more to do. The package of dirvish includes already the necessary cron events to do the next incremental backups.
That's it, you are good to go! Quite easy, right?
Editing this page means accepting its license.