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
    
Thank you very much for your detailed answer -- I have up-voted it -- but I asked explicitly for a ready-made solution because I would rather avoid tinkering with scripts for such a critical task. I thought that backing up an encrypted GNU/Linux system was a solved problem, but it seems that I was mistaken. –  Elena Oct 29 at 12:48
1  
@Elena Your problem is not backing up an encrypted system, but backing up to an encrypted volume. What most people do is encrypt individual archives; there are turnkey solutions for that (I often use Duplicity, which uses GnuPG for encryption). –  Gilles Oct 29 at 13:07
    
Thanks. I already backup important files to archives, and I will see how I could improve my procedure by using Duplicity. Anyway, maybe my question is malformed. Sorry but I am not an expert. At the highest abstraction level, I would just like to be up and running as quickly as possible after a HDD failure, with a system that is as close as possible to the original system, all by using an automatic procedure. I have read everything that I have found about backups but I have yet to understand how sysadmins have solved what looks like a recurring problem for laptop owners. –  Elena Oct 29 at 14:09

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.