Table of Contents
Using Btrbk to backup my home partition
Due to the fiasco of running
rm -rf on my home partition, and wiping out all my backup snapshots, I realised that it is important to have some sort of offline backups. Snapper 1) creates snapshots, but manual operations are required to move those snapshots off to external backup devices (in order to offline backups). A better solution is desperately needed. I discovered Btrbk 2).
It is much harder to understand, please read the man page. I am just going to document what I did to my own machine.
I created an empty Btrfs partition with a subvolum name
home and a directory named
snapshots. I mount the partition itself under
/mnt/home. I mount the
home subvolume under
This is a snippet of my
# <file system> <mount point> <type> <options> <dump> <pass> #Entry for /dev/mapper/illustrious-home: UUID="a15feee3-8096-409e-ac20-10ae347754c3" /home btrfs ssd,discard,autodefrag,space_cache,subvol=home 0 2 #Entry for /dev/mapper/illustrious-home: UUID="a15feee3-8096-409e-ac20-10ae347754c3" /mnt/home btrfs ssd,discard,autodefrag,space_cache 0 2
Here is the top level directory layout of the partition that contains my home directory subvolume:
fangfufu@smithsonian:~$ ls /mnt/home home snapshots
Here is my Btrbk configuration:
lockfile /var/lock/btrbk.lock transaction_log /var/log/btrbk.log timestamp_format long-iso volume /mnt/home snapshot_preserve 24h 7d 4w snapshot_preserve_min latest target_preserve 24h 30d target_preserve_min latest snapshot_dir snapshots subvolume home target send-receive /mnt/storage/home-backups volume ssh://127.0.0.1/mnt/home ssh_identity /root/.ssh/id_rsa target_preserve 180d target_preserve_min latest snapshot_create no snapshot_dir snapshots subvolume home target send-receive /media/fangfufu/WD500GB/home-backups target send-receive /media/fangfufu/Seagate500GB/home-backups
Basically, my laptop is configured to save 24 hourly snapshots, 7 daily snapshots, 4 weekly snapshots. The external backup drive has 6 months of snapshots.
ssh://127.0.0.1/mnt/home paragraph basically follows the “Example: multiple btrbk instances” on the btrbk's Github page3). This allows
snapshot_dir to get cleared up locally. If you write everything in one paragraph, then btrbk refuses to clean up snapshots, because external hard drives are not connected. If you write another paragraph of
volume /mnt/home, then btrbk complains that the two snapshots are created at the same directory. The side effect of that is the funny
btrfs-receive CPU usage, when sending snapshot to external drives.
Btrbk needs to be run hourly, for the whole snapshot thing to work. In order to do that we create
/etc/cron.hourly/btrbk with the following content:
#!/bin/sh echo > /var/log/btrbk.log /usr/sbin/btrbk -q run > /dev/null 2>&1 return 0 #returning 0 to suppress cron warning emails.
Do remember to run
chmod +x /etc/cron.hourly/btrbk, so it can be executed.
Btrbk will attempt to send the Btrfs diffs to the external hard drive, if it is attached. If not, then only the snapshot will be created.
Sending snapshots to the external hard drive
All you have to do is type in
btrbk run as
root. Example output:
btrbk command line client, version 0.25.0 (Fri Jul 7 09:27:21 2017) Using configuration: /etc/btrbk/btrbk.conf WARNING: Skipping target "/media/fangfufu/Hitachi500GB/home-backups": Failed to fetch subvolume detail WARNING: Skipping target "/media/fangfufu/Seagate500GB/home-backups": Failed to fetch subvolume detail Using transaction log: /var/log/btrbk.log Creating subvolume snapshot for: /mnt/home/home [snapshot] source: /mnt/home/home [snapshot] target: /mnt/home/snapshots/home.20170707T092721+0100 Cleaning snapshots: /mnt/home/snapshots/home.* Deleted 0 subvolumes in: /mnt/home/snapshots/home.* WARNING: Skipping cleanup of snapshots for subvolume "127.0.0.1:/mnt/home/home", as at least one target aborted earlier Completed within: 0s (Fri Jul 7 09:27:21 2017) -------------------------------------------------------------------------------- Backup Summary (btrbk command line client, version 0.25.0) Date: Fri Jul 7 09:27:21 2017 Config: /etc/btrbk/btrbk.conf Legend: === up-to-date subvolume (source snapshot) +++ created subvolume (source snapshot) --- deleted subvolume *** received subvolume (non-incremental) >>> received subvolume (incremental) -------------------------------------------------------------------------------- /mnt/home/home +++ /mnt/home/snapshots/home.20170707T092721+0100 127.0.0.1:/mnt/home/home !!! Target "/media/fangfufu/Hitachi500GB/home-backups" aborted: Failed to fetch subvolume detail !!! Target "/media/fangfufu/Seagate500GB/home-backups" aborted: Failed to fetch subvolume detail NOTE: Some errors occurred, which may result in missing backups! Please check warning and error messages above.
Snapshots are accessible under
/etc/updatedb.conf, to stop your locatedb from picking up snapshots.