Linux HOME Backup with rdiff-backup

Posted by JD 10/24/2009 at 13:01

You’ve heard it over and over. Backup, Backup, Backup. You are magically supposed to know how to do it and make it happen. This time, I’ll show exactly how I backup my HOME directory and manage those backups with rdiff-backup.

I’ve gone into why rdiff-backup was selected previously, but the main reasons were:

  1. Incremental
  2. Versioned
  3. Compressed
  4. Latest backup is available as a mirror so restore 1 file at a time or all at once

Install rdiff-backup

Run synaptic package manager or whatever package manager you prefer and install the rdiff-backup package.

Select a backup location on a different disk drive or over the network on a different computer

I have another Linux machine called romulus on my network. It has an external disk array with lots of storage available. It has both sshd and rdiff-backup on the system. Further, ssh logins are key-based, so there it no prompt for a password between these 2 systems for my backup user accounts. You can easily set ssh keys up yourself.

Copy this script and modify it for your needs

Sorry, the lines below with 1., 2., 3. should be comments (#). That is an unintended interaction with the blog engine that I use.

backup_to_srv.sh

#!/bin/sh
\# A carefully determined exclusion list – exclude from backups
EXCLUDE=“—exclude-symbolic-links —exclude /.gnupg \
—exclude *
/.cpan \
—exclude /.cache \
—exclude *
/.kde/share/apps/kpdf \
—exclude /.gkrellm2 \
—exclude *
/.miro/icon-cache \
—exclude /.miro/mozilla \
—exclude *
/.smplayer/screenshots \
—exclude /.mozilla-thunderbird \
—exclude *
/.vlc \
—exclude /.mozilla/firefox//chrome/sagetoo \
—exclude /.mozilla/firefox//extensions \
—exclude /.mozilla/firefox//sessionstore \
—exclude /.mozilla/firefox//Cache”

\# Capture some important information
\# installed packages
sudo dpkg —get-selections > ${HOME}/installed-software
\# my crontab
crontab -l > ${HOME}/crontab.${LOGNAME}

\# Remove all flash files and cache
rm -rf ${HOME}/.macromedia/*

TARGET=“romulus::media/Lap-Backup/xubuntu/${LOGNAME}”
/usr/bin/rdiff-backup $EXCLUDE ${HOME} “$TARGET
/usr/bin/rdiff-backup —remove-older-than 90D —force “$TARGET

TARGET=“romulus::media/Lap-Backup/xubuntu/Work”
/usr/bin/rdiff-backup $EXCLUDE /Data/Work “$TARGET
/usr/bin/rdiff-backup —remove-older-than 90D —force “$TARGET

Discussion of the script.

  • The blog software I use is messing with the comments inside the script. Sorry. Lines beginning with 1,2, 3, 4 or \# are comments.
  • This is a trivial script meant to show how to do it. It works for me today, but it isn’t production ready.
  • Exclude directories and files that really don’t need to be backed up. Further, I don’t keep any large files in this area – podcasts are placed in a different area. Files that change all the time may not be a good choice for this type of backup, unless they are really, really important.
  • Having your HOME is only part of a backup, you want the list of apps too. Refresh the list daily. This list can be easily installed for system recovery.
  • LOGNAME variable needs to be used since cron doesn’t inherit the full set of environment variables.
  • Cleanup / remove any files or folders you don’t want kept around – I don’t want Adobe Flash cookies, so removing them every day is good enough for me.
  • Tell rdiff-backup to run and where to place the files by TARGET
  • Tell rdiff-backup to remove any backups that are older than 90 days, force that in case I did a manual backup more than once a day
  • Backup another disk area – Work in this case and remove any backups over 90 days old.

Setup Crontab to Run

Add this line to your crontab with a

  • $ crontab -e
41 4 * * * $HOME/bin/backup_to_srv.sh

So at 4:41 am, the script we created will run automatically, every day, provided the computer is on. Obviously, you need to point to the name and location of your script. Don’t forget to make the script executable with a chmod +x $HOME/bin/backup_to_srv.sh cmd.

Storage Needs?

The HOME directory currently has 3.9GB.
The backup with 90 days of incremental backups is: 10.1GB, but I’ve recently installed a new podcast catcher and didn’t prevent it from storing media files in the backup area initially. That meant that files pulled down and removed a few days later take lots of backup space for 90 days. On the other hand, 10GB is a trivial amount of storage to have 90 days worth of backups available. Normally, there is under 2GB of data in HOME. On servers with 5 GB, only 1GB additional is typically required for 30 days of backups with rdiff-backup.

Why did I chose 90 days? Well, I normally use 30 days for servers, but my home directory usually contains PDF documents, PDF books, open office documents, stock market tracking database and custom shell scripts that I’ve created. I figure if I delete something and don’t miss it within 90 days, it really wasn’t that important. I don’t delete scripts. Anything else is captured by accident, but since it is under 20GB, I don’t really care. It isn’t worth the effort to find ways to reduce the amount at this point.

If I were backing up 2,000 desktops in a company, perhaps I’d be more cautious and extremely specific with the user HOMEs for which files were backed up without introducing liabilities to the company.

Differential, compressed backups are great. With 90 days at 3.9GB each, that would mean about 351GB used with full backups, but with compressed and differential, only 10GB is used at this point.

If a backup fails or doesn’t happen 1 night, does it really matter? The next night, rdiff-backup will either remove the failed attempted backup (as corrupt) and create a fresh DIFF backup or just create a fresh new copy with a HUGE diff from the day prior. That big diff will slowly migrate through the 90 days, until it is removed. Does it matter with 10GB of storage? Probably not in the grand scheme.

Differential Backup Report

rdiff-backup will provide a report for all the backups. See the expanded section for a current report. The command to do that is

$ /usr/bin/rdiff-backup —list-increment-sizes romulus::media/Lap-Backup/xubuntu/HOME

Anyway, I hope this helps someone start using rdiff-backup.

Did the script work for you? Did I get something wrong? Please let me know in the comments.

Trackbacks

Use the following link to trackback from your own site:
https://blog.jdpfu.com/trackbacks?article_id=361