Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to have an up-to-date clone of a (Debian) GNU/Linux system on an external HDD and therefore be able to replace the internal HDD with the external HDD at any time and being up and running in no time. Since the system is on a laptop, I can't rely on a hardware-based mirroring solution.

I wish the backup procedure to be as automatic and as hassle-free as possible. For instance, it could run automatically at shutdown whenever an external HDD is connected.

I already have an external HDD with a clone of system partitions.

The caveat is that the partition that hosts the / directory is encrypted with LUKS+dm-crypt and I would rather avoid entering passwords again for the backup.

I could mount the external encrypted partition automatically before shutdown.

Does a ready-made solution exists? Please only reply if it does, because if it doesn't, then I will post a specific question to implement a custom solution.

Thanks for your attention.

share|improve this question

1 Answer 1

The backup will be a lot faster if you only back up what's changed. This needs to be done at the file level, with encrypted containers mounted, because files carry a timestamp which allows the backup tool to skip files that haven't been modified since the last backup.

To do the file copying, rsync is the tool of choice. You need to synchronize each filesystem with the corresponding one on the external hard disk:

rsync -ax / /media/backup-hdd/root

Use a dedicated block device name and a dedicated mount point for each partition, to avoid relying on generic names such as sdb1 and /media/sdb1 which could be a different drive. This is done via udev; see Automatizing the sequence of mounting commands.

To run a script at shutdown time, put it in /etc/init.d and create symbolic links to it in /etc/rc0.d and /etc/rc6.d (0 for power off, 6 for reboot) called S01my-backup. The script will need to do several things:

  • Check if the backup drive is already mounted (by looking for the mount point in /proc/mounts).
  • If the backup drive isn't mounted, check if it's present (by looking for the block device in /dev).
  • If the backup drive isn't present, either give up or prompt the user to connect it.
  • If the encrypted volume isn't mounted, you need to prompt the user for the password. Once the encrypted volume is available, mount the filesystem(s).
  • Finally, run rsync.

If you don't want to have to mount the external encrypted volume, you can copy the encrypted volume wholesale. While simple, this has a major defect: it's very very slow, since you have to re-image the whole disk each time. Also, if this fails in the middle, you end up with an unreadable backup — the backup is well-formed only after a complete pass. You should also switch the source mount to read-only, otherwise you risk copying inconsistent data.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.