Rsync – Full System Mirroring

Rsync is a command line utility traditionally used in synchronizing files between two computers over the network, but rsync can also be used as an effective backup tool.
This article explains how to use rsync to backup your whole Linux system setup to a second drive attached to your system. You can use a removable drive, such as an external USB hard drive, so that you can store the backups in a safe place away from your working environment.

I am running Debian 3.1 (Sarge) on a fanless LEX NEO configuration. As I have installed the whole system on a 1GB CF-card, I would like to have a mirror of it on another partition on my harddisk (Let’s say I’m going on vacation and desperately need another CF-card and the stores are already closed…). I’d like to be able to boot from that second source.

I have mounted /mirror to /dev/hdd1, my backup partition of the same size like my root partition (in my case the CF-card).
Now, let’s copy all the data over to our backup partition:

Make sure you exclude all of the following directories/files. I have specified the exclude list in a separate file excludes.cfg:

The rsync-command above we could run e.g. daily by cronjob. On a regular system this should not take more than 2 minutes as rsync only transfers the data that has been changed in a incremental manner. (besides, Rsync’s protocol is pretty smart, see Tom’s article on nope.ch).

Copy the original /etc/fstab over to /mirror/etc/fstab and edit it that the new partition get’s correctly mounted as /.
In my case this results in the following line:

Also, make sure, the directories we are never going to synchronize exist on your mirror partition as linux needs them as a mounting point:

Finally, configure grub to correctly boot from the mirrored partition. /boot/grub/menu.lst example:

now, run:

If the command fails and grub answeres with something like „/dev/hdd does not have any corresponding BIOS drive“, make sure, the device drive has been entered into /boot/grub/device.map, e.g.:

That’s it! We’re done. reboot and run the mirrored system from the grub menu.

2 Responses

  1. ddjjzz
    Feb 22, 2010 - 08:36 PM

    Awesome article! Thank you.
    However I have a dumb question. I’ve read manual page twice and it still doesn’t make sense for me: for what do you use „–delete“ option?

  2. iezzip
    Feb 22, 2010 - 09:01 PM

    --delete will delete files on destination that have been deleted on source. Without this option, you’ll get dangling files on the destination drive/path and only new or changed files get synchronized.

    Always use --delete on 1:1 archive synchronization!

Leave a Comment

css.php