Wednesday, October 19, 2011

Backup solution: rdiff-backup

It's time to finally get serious about my laptop backups.

I tried backup-manager and rsnapshot, but neither really met my needs for a simple, scriptable, push-to-remote-server-via-ssh backup solution.

Let's try rdiff-backup.

Here's what I think I want:

  1. Triggered by laptop connecting to the network and/or cronjob
  2. If the server's backup drive is not mounted, mount it
  3. Do a diff-based backups
  4. Unmount the backup drive
The heart of the backup is the rdiff-backup command. The rdiff-backup package must be installed on both client and server (they can be different versions).

 
# The basic rdiff-backup syntax is: rdiff-backup [options] [machine::]/path/to/original [machine::]/path/to/backup

# Here's a test command to backup my laptop /home directory to the server via ssh:
# option: --terminal-verbosity 5 (tell me a lot)
# option: --remote-schema (necessary for nonstandard ssh ports)
rdiff-backup --terminal-verbosity 5 --remote-schema 'ssh -p $PortNumber %s rdiff-backup --server' /home/me me@myserver.com::/mnt/Laptop/backups/me/ 
# Here's a test command to see how many backups are stored
rdiff-backup -l --terminal-verbosity 5 --remote-schema 'ssh -p $PortNumber %s rdiff-backup --server' me@myserver.com::/mnt/Laptop/backups/me 

You can see how this can be scripted to make things easy:


#!/bin/sh
# This script backs up my laptop to the server's /mnt/Laptop-backup/backups directory
 
# Do pre-backup stuff 
Schema="ssh -p $PortNumber %s rdiff-backup --server"
# Backup the home folder  
rdiff-backup --remote-schema '$Schema' /home/me me@myserver.com::/mnt/Laptop/backups/me 

# Backup /var, including the package list and cache and all the logs 
rdiff-backup --remote-schema '$Schema' /var me@myserver.com::/mnt/Laptop/backups/var 
# Backup /etc, including the firewall script and upstart/init scripts 
rdiff-backup --remote-schema '$Schema' /etc me@myserver.com::/mnt/Laptop/backups/etc 
# Backup /opt, mostly unpackaged non-debian stuff 
rdiff-backup --remote-schema '$Schema' /opt me@myserver.com::/mnt/Laptop/backups/opt 
# Do post-backup stuff
exit 0



What kind of pre- or post- backup actions? How about sanity checks, like that the server is available?

Since the server requires root to mount the backup drive, we need to create a socket for backups. The server will see which machine is asking to send or complete a backup, and mount/unmount the appropriate drive.
We need to write some logic to trigger the process.

2 comments:

  1. Your remote-schema doesn't work. Rdiff-backup seems to be fixated on using only 22.

    ReplyDelete
  2. Well, it seemed to work for me three years ago.

    I use something else now, so I'm not very motivated to investigate.

    ReplyDelete