Home > Support > HOWTO List > Linux > Backup using SSHFS and rdiff-backup

Working with Linux howtos

We have had a few customers who have much more data to back up, and taking a copy of that every day uses a LOT of disk space and can be time consuming. The answer is rdiff-backup . It does incremental backups whenever you run it, only backing up the difference from the initial complete backup. This saves you, and us, a lot of cost in disk and backup space.

Since we have enabled sftp on backupspace.rimuhosting.com you can now use rdiff-backup. The problem being that you can't send it directly to the server because of the limited commands, however you can mount it using sshfs (aka sshmnt ) and then do an rdiff-backup to it.

With this in mind, I have written a script which will automatically do this. Its tested and going on debian/ubuntu and Centos.
Steps to get this going

  1. Install sshfs and rdiff-backup ( see below for install instructions)
  2. Check you have /dev/fuse - otherwise mknod /dev/fuse -m 0666 c 10 229
  3. Download this script http://b.ri.mu/files/rdiff-backup-sshfs.sh
  4. Add your ssh key to backupspace. This automates login without password.
    ssh username@backupspace.rimuhosting.com "mkdir .ssh/;chmod 700 .ssh" scp .ssh/id_rsa.pub username@backupspace.rimuhosting.com:.ssh/authorized_keys
  5. Edit the script, it has several variables.
  6. Set the USERNAME variable at the top - this is your backupspace username
  7. Set the INCLUDES variable , configs and directories you want to backup using spaces between them. Escape all spaces and odd characters.
  8. Set the EXCLUDES for larger files you dont want backup. This uses standard regex.
  9. Create yourself a mysql user that can SELECT and LOCK TABLES if you want to backup databases. ( Details in the comments of script)
  10. Insert the user/pass variables into the script and set MYSQLBACKUP=1
  11. Set the OLDERTHAN variable - The time interval is an integer followed by the character s, m, h, D, W, M, or Y, indicating seconds, minutes, hours, days, weeks, months, or years respectively. ie 4W is 4 weeks
  12. If you have any special arguments you want to pass add them in ARGS variable
  13. chmod +x backup.sh (or whatever you named it)
  14. Do a test run manually ./backup.sh check for errors.
  15. If all goes well copy the backup file into /etc/cron.daily/backup or some similar name and you're done.

Things to note: First time will take a while to sync things. Pays to test with a smaller dir of files. If you have any errors at all, have a look at the code and uncomment some of the debugging to check what its doing. If you get really stuck just drop an email into support and let us know.

To restore or list what backups you have, mount backup space

sshmnt username@backupspace.rimuhosting.com /mnt/

List the backups

rdiff-backup -l /mnt/vpsname

Restore from the backups

rdiff-backup -r now /mnt/file /local/file #you can set up a new vps using current backups

rdiff-backup -r 10D /mnt /tmp/file # 10 day old backups etc

rdiff-backup -r /mnt/hostname/rdiff-backup-data/increments/file.2003-03-05T12:21:41-07:00.diff.gz /local/file


Installing sshfs and rdiff-backup


apt-get install sshfs rdiff-backup


You will need to enable the DAG/rpmforge  repos

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

yum update

yum install sshfs rdiff-backup

OR download the rpms manually from http://dag.wieers.com/rpm/packages/rdiff-backup/ & http://dag.wieers.com/rpm/packages/fuse-sshfs/