Full system clone, snapshot using rsync

7,033

You can pass the -x option to rsync, so that it doesn't recurse into other filesystems (such as /proc, /sys, etc.). The easiest way to do that is to pass -x to rsnapshot. If you do have several disk filesystems (e.g. /home separate from /), list them all as backup points.

Whether you should back up everything depends on how fast you want recovery to be. For example everything under /usr that is not under /usr/local can be recovered by reinstalling the distribution. But that will increase your recovery time.

You can reconstruct a mostly identical system with just the complete content of /etc and /usr/local, plus the list of installed packages obtained with dpkg --get-selections. To restore, install the basic distribution, run dpkg --set-selections on the package list, then apt-get install and finally restore /etc/ and /usr/local.

The backup won't be bootable unless you make it so. If you have a copy of the whole disk, I think sudo chroot /path/to/backup/root grub-install /dev/sdb (where sdb identifies the disk containing the backup) should do the trick. Maybe you need to set up a correct device map first, I'm not sure.

You can make a clone of the whole disk; this is best done with the filesystems not mounted, otherwise you'll make a copy with an inconsistent filesystem. The easiest way to do this is to use gparted from a live CD/USB. You can also use parted on the command line, or dd if=/dev/sda of=/dev/sdb bs=16M to copy /dev/sda to /dev/sdb (be very careful as a one-character typo will erase your data with no warning).

If you've prepared things in advance, you can make the copy from a live system, and faster. * If you've set your disk as a (single) component in a RAID-1 array: add the second disk to the array, reconstruct the array, remove the second disk from the array (mdadm --add /dev/md0 /dev/sdb, wait, mdadm /dev/md0 --fail /dev/sdb --remove /dev/sdb). * If you've set up your filesystem(s) on LVM volumes, and you have enough room for a snapshot, you can copy the raw filesystem from the snapshot.

Once you've made the clone, you can use rsync to keep it up to date. This won't take care of keeping old file versions around; you can stick with rsnapshot for that.

Share:
7,033

Related videos on Youtube

Vincent
Author by

Vincent

Updated on September 17, 2022

Comments

  • Vincent
    Vincent over 1 year

    I have automated backups running on my ubuntu box using rsnapshot (rsync) basically following this tutorial. My concern is how to restore if everything is lost. Since it does not seem that I can backup the entire drive and that I have to choose individual folders and some like proc/ cause problems.

    Currently in my rsnapshot.conf I have (see below). Is there a way to just clone the entire drive? Or should I not do this?

    Questions:

    1, Can I backup in a way such that it is a clone of the drive so that it can be swapped with the current drive?

    2, If not yes to clone, If I had a total drive failure would I install a basic ubuntu and then replace all the files with the backups?

    3, Anything I might not know about that I should.

    Thanks

    ###############################
    ### BACKUP POINTS / SCRIPTS ###
    ###############################
    
    # LOCALHOST
    backup  /var/           localhost/
    backup  /home/          localhost/
    backup  /etc/           localhost/
    backup  /lib/           localhost/
    backup  /usr/           localhost/
    backup  /opt/           localhost/
    backup  /root/          localhost/
    backup  /sbin/          localhost/
    backup  /selinux/       localhost/
    backup  /srv/           localhost/
    ###backup /proc/          localhost/