Simple incremental backups using rsnapshot PDF Print E-mail
Thursday, 30 July 2009 17:31

I have a samba-shared drive on my Ubuntu machine at home which anything important is saved onto.  This, along with any websites I maintain, is backed up nightly using incremental backups.  This was quick & easy to set up and works really well.

I basically followed the instructions in the rsnapshot HOWTO.  The changes I needed to make are outlined below.  If you are lazy, you are Dave O'Loghlin, or you are me reading this at some point in the future while cursing a crashed server just download my /etc/rsnapshot.conf.

Salient points:

  • My backup disk is a 1TB external USB disk mounted on /media/backup_disk.  To ensure it is always mounted in the same place I mount using the UUID.  I needed to change the snapshot_root and no_create_root parameters accordingly:
      ###########################
      # SNAPSHOT ROOT DIRECTORY #
      ###########################

      # All snapshots will be stored under this root directory.
      #
      snapshot_root /media/backup_disk/

      # If no_create_root is enabled, rsnapshot will not automatically create the
      # snapshot_root directory. This is particularly useful if you are backing
      # up to removable media, such as a FireWire or USB drive.
      #
      no_create_root 1
  • I'm just interested in daily & weekly backups so I created the name & frequency of the intervals, thus:
      #########################################
      # BACKUP INTERVALS #
      # Must be unique and in ascending order #
      # i.e. hourly, daily, weekly, etc. #
      #########################################

      #interval hourly 6
      interval daily 7
      interval weekly 4
      #interval monthly 3
  • Next I gave it the list of directories (and websites) I want it to backup:
      ###############################
      ### BACKUP POINTS / SCRIPTS ###
      ###############################

      # LOCALHOST
      backup /home/ detritus/
      backup /etc/ detritus/
      backup /usr/local/ detritus/
      backup /media/shared/ detritus/
      backup /media/videos/ detritus/
      backup /var/log/rsnapshot detritus/
      backup /etc/passwd detritus/

      # DATABASE BACKUPS
      backup This e-mail address is being protected from spambots. You need JavaScript enabled to view it :/usr/home/cianer/databaseBackups/ websites/

      # CIANER.COM
      backup This e-mail address is being protected from spambots. You need JavaScript enabled to view it :/usr/www/cianer.com/ websites/

      # DOGSAID.IE
      backup This e-mail address is being protected from spambots. You need JavaScript enabled to view it :/usr/www/dogsaid.ie/ websites/
    CAVEAT 1: The gaps between words are TABS not spaces, and yank-yank-paste in vi converts them to spaces (at least in my version).  Consider yourself warned!
    CAVEAT 2: If your server uses symlinks (e.g. if /home is actually a symlink to /usr/home) then use the full path otherwise it'll copy the symlink & no more and you'll end up with no backups.  I'm actually in two minds about typing that as I know Dave will be reading this and he's the one who symlinked /home to /usr/home in the first place so deserves some of the pain.  =)
    CAVEAT 3: There are spaces between the cianer.com and the :/usr/ in the example above which shouldn't be there.  These were added by Joomla somehow & I don't know how to get rid of them, and don't care enough to find out.  Don't put spaces there in your config file!
  • Since I want to back up directories from another server I needed to create ssh keypairs so rsnapshot could log in without needing a password. Insert your own security warnings here.
  • Finally set up two cronjobs (one for daily backups, one for weekly) as root & job done!
    Note: The parameters passed to rsnapshot in the cronjob has to match the name of the intervals outlined in above:
      root@Detritus:~# crontab roots.crontab
      root@Detritus:~# crontab -l
      # DO NOT EDIT THIS FILE - edit the master and reinstall.
      # (roots.crontab installed on Tue Feb 19 22:28:37 2008)
      # min            hour  day/mon  month  day /week  command
        0              3     *        *      *          /usr/bin/rsnapshot daily
        0              0     *        *      1          /usr/bin/rsnapshot weekly

      root@Detritus:~#
 
Joomla Templates by Joomlashack