Backup setup commands (btrfs, rdiff-backup, ssh)

Once btrfs-tools is installed these are the commands to create a single partition volume and add a filesystem to it. First step is to wipe the existing partition table with wipefs, then use mkfs.btrfs to create the filesystem. This is the best way to create a backup disk, even if it is for more than one PC. A single partition shared by multiple repos doesn’t waste space like a separate partition for each repo would.
  • wipefs -a <device>
  • mkfs.btrfs -L <label> <device>
After creating the filesystem, use blkid to find out the UUID of the new filesystem and add a line like this to /etc/fstab 
  • UUID=… /local/mount/path btrfs compress,noauto 0 2
I use paths off /mnt/media to mount my removable disks. If you want to backup as something other than root then be sure to give permissions to the user account concerned, chown is one simple way of doing this.
With the above line in fstab the volume will not automount which is handy for a removable disk that might not be present at startup. Just type mount /local/mount/path to mount the disk when it is inserted. The mount line should ensure files are compressed when they are stored or updated but it leaves the type of compression to be chosen by the default setting of btrfs tools.


The next step we want to cover is how to set up ssh for passwordless connections to the remote computer. For my setup, serverpc is the computer that will host every backup. When I need to change disks, I can quickly shut down serverpc and then bring it back up again (the disks are supposed to hotswap but they seem to fail quite quickly so I have been given to coldswapping).

This means serverpc needs the openssh-client package installed and each target computer (mainpc and mediapc) needs openssh-server installed.

My current backup scheme assigns a pair of 2 TB disks to backup mainpc and a combination of a 2 TB disk and two 1 TB disks to backup mediapc and serverpc so there are two sets of disks for each. And that’s without making use of rdiff’s differential backup capability for multiple generations per disk.

Using the instructions from my previous post I need to follow these steps after installing the respective packages on each computer.

  • On serverpc create the key pair for SSH:
    • ssh-keygen -t rsa
    • The file will be saved in .ssh/id_rsa
    • Press enter to put in an empty passphrase when prompted (twice)
  • Use serverpc to ssh into the target (mainpc in this example) and create the directory there for the key to be copied to.
    • ssh user@a.b.c.d mkdir -p ssh
    • Enter yes when asked to continue connecting
    • Enter the password for that user on the remote system when prompted
  • Copy the public key from serverpc to target
    • cat .ssh/id_rsa.pub | ssh user@a.b.c.d ‘cat >> .ssh/authorized_keys’
    • Enter the password for the user on the remote system when prompted
  • Ensure the correct permissions are set on the remote filesystem
    • ssh user@a.b.c.d “chmod 700 .ssh; chmod 640 .ssh/authorized_keys”
    • Enter the password for the user on the remote system when prompted
  • Test the login to see that no password is needed
    • ssh user@a.b.c.d

Finally I can do my backups with rdiff-backup. All computers need to have the rdiff-backup package installed and the same versions preferably.

Usually what I do is mount the disk and then change into the directory I want the backup to go into. Then I can use these types of commands to do the backup:

  • To backup one of the remote systems using SSH to connect to that system
    • rdiff-backup -v5 user@a.b.c.d::/path/to/files .
    • This is telling rdiff-backup to use verbosity level 5, and the files will be backed up to the current directory, assuming I changed to that directory as mentioned above.
  • To backup serverpc’s local files:
    • rdiff-backup -v5 /path/to/files .
    • Again we assume the current directory is the backup path.
rdiff-backup has been generally good to use but there has been one instance (on the PC doing the backups) of for some reason the backup disk not being mounted properly. We mount disks to a path off /mnt which is hosted on the installation volume. The problem is when no mount exists, this just looks like an ordinary directory and stuff being copied to there will fill up the install disk instead of the disk that is supposed to be mounted. As I couldn’t identify any files to be deleted in the path, I was forced to reinstall the OS.

As a precaution, when I reinstalled Debian, I set up a separate partition for /mnt on the backup host computer,  with a size of 100 MB.