User Tools

Site Tools


public:using_btrbk_to_backup_my_home_partition

This is an old revision of the document!


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.

Partition layout

I created an empty Btrfs partition with two subvolumes - home and snapshots. I mount the partition itself under /mnt/home. I mount the home subvolume under /home.

This is a snippet of my fstab:

# <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

Btrbk configuration

Here is my Btrbk configuration:

fangfufu@smithsonian:~$ cat /etc/btrbk/btrbk.conf
transaction_log            /var/log/btrbk.log
timestamp_format           long-iso

snapshot_preserve       24h 7d 4w
snapshot_preserve_min   1d

target_preserve         no
target_preserve         6m

volume /mnt/home
    snapshot_dir snapshots
    subvolume home
        target send-receive /media/fangfufu/Hitachi500GB

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.

Doing backup

Generating snapshots

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
exec /usr/sbin/btrbk -q run

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:

root@smithsonian:~# btrbk run
--------------------------------------------------------------------------------
Backup Summary (btrbk command line client, version 0.25.0)

    Date:   Wed Jul  5 22:08:18 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.20170705T220818+0100
*** /media/fangfufu/Hitachi500GB/home.20170705T220818+0100

Accesing snapshots

Snapshots are accessible under /mnt/home/snapsots.

You should add /mnt/home into the PRUNEPATHS in /etc/updatedb.conf, to stop your locatedb from picking up snapshots.
public/using_btrbk_to_backup_my_home_partition.1499290315.txt.gz · Last modified: 2018/03/31 00:38 (external edit)