btrbk

Btrbk is a backup tool for BTRFS subvolumes, taking advantage of btrfs specific capabilities to create atomic snapshots and transfer them incrementally to your backup locations. I have been using this tool in all the linux distributions i’ve used including Alpine Linux .

Configuration files

btrbk config file (alpine - homepc2)

prabu@homepc2 ~> cat /etc/btrbk/btrbk.conf |grep -v '^ *#'|grep "\S"
transaction_log            /var/log/btrbk.log
compat busybox
stream_buffer              512m
incremental                yes
lockfile                   /var/lock/btrbk.lock
snapshot_preserve_min   2d
target_preserve_min     no
target_preserve         7d 4w 12m 0y
archive_preserve_min    latest
archive_preserve        12m 0y
ssh_identity /etc/btrbk/ssh/id_rsa
volume /mnt/btrfs
  snapshot_dir               _btrbk_snap
  snapshot_create            always
  target send-receive      /mnt/backup/_btrbk
  subvolume  @
    target_preserve         7d 4w 1m 0y
  subvolume  @home
  subvolume  @audio
  subvolume  @video
  subvolume  @photos
  subvolume  @docs
  subvolume  @myhome

Configuration for hourly backup(crontab)


prabu@homepc-lm:/etc$ sudo crontab -l
# Edit this file to introduce tasks to be run by cron.
#
...
#03 * * * * /usr/local/bin/btrbk -c /etc/btrbk/btrbk_hourly.conf run
33 * * * * /usr/local/bin/btrbk -c /etc/btrbk/btrbk_hourly.conf run

Configuration for daily backup(anacron)

prabu@homepc-lm:/etc$ cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HOME=/root
LOGNAME=root

#current backup system in use
1   	7   	daily-btrbk 	/usr/bin/btrbk -q -c /etc/btrbk/btrbk.conf run

Configuration for daily backup in alpine

prabu@homepc2 /e/btrbk [1]> doas cat /etc/crontabs/root
# do daily/weekly/monthly maintenance
# min	hour	day	month	weekday	command
*/15	*	*	*	*	run-parts /etc/periodic/15min
0	*	*	*	*	run-parts /etc/periodic/hourly
0	2	*	*	*	run-parts /etc/periodic/daily
0	3	*	*	6	run-parts /etc/periodic/weekly
0	5	1	*	*	run-parts /etc/periodic/monthly
@reboot /usr/sbin/anacron -s

prabu@homepc2 /e/btrbk> cat /etc/anacrontab
#current backup system in use
1	7	daily-btrbk	/usr/bin/btrbk -q -c /etc/btrbk/btrbk.conf run⏎

Archive to external HDD

Archive in homepc

Dry run with progress:

sudo btrbk  --progress -c ~/scripts/btrbk_external_homepc.conf -n archive /mnt/backup/_btrbk/ /mnt/ext_part1/_btrbk/homepc-lm/

Actual Archive with progress:

  $sudo btrbk  --progres -c ~/scripts/btrbk_external_homepc.conf archive /mnt/backup/_btrbk/ /mnt/ext_part1/_btrbk/homepc-lm/

--------------------------------------------------------------------------------
Archive Summary (btrbk command line client, version 0.30.0)

    Date:   Sun Mar  7 10:06:48 2021

Legend:
    ++.  created directory
    ---  deleted subvolume
    ***  received subvolume (non-incremental)
    >>>  received subvolume (incremental)
    [-]  no action
--------------------------------------------------------------------------------
/mnt/backup/_btrbk/data.*
*** /mnt/ext_part1/_btrbk/homepc-lm/data.20210116
>>> /mnt/ext_part1/_btrbk/homepc-lm/data.20210207
>>> /mnt/ext_part1/_btrbk/homepc-lm/data.20210307

/mnt/backup/_btrbk/@home.*
*** /mnt/ext_part1/_btrbk/homepc-lm/@home.20210211
>>> /mnt/ext_part1/_btrbk/homepc-lm/@home.20210307

/mnt/backup/_btrbk/@.*
***  /mnt/ext_part1/_btrbk/homepc-lm/@.20210214
>>> /mnt/ext_part1/_btrbk/homepc-lm/@.20210307

Archive in onepc

Dry run with progress:


prabu@onepc-lm:~$sudo btrbk --progress -c scripts/btrbk_external_onepc.conf -n archive /mnt/backup/_btrbk/ /mnt/ext_part1/_btrbk/onepc-lm

Actual Archive run with progress:

prabu@onepc-lm:~$ sudo btrbk --progress -c scripts/btrbk_external_onepc.conf archive /mnt/btrfs/_btrbk_snap/ /mnt/ext_part1/_btrbk/onepc-lm/
--------------------------------------------------------------------------------
Archive Summary (btrbk command line client, version 0.27.1)

    Date:   Sun Mar  7 14:02:59 2021

Legend:
    ++.  created directory
    ---  deleted subvolume
    ***  received subvolume (non-incremental)
    >>>  received subvolume (incremental)
    [-]  no action
--------------------------------------------------------------------------------
/mnt/btrfs/_btrbk_snap/@.*
 *** /mnt/ext_part1/_btrbk/onepc-lm/@.20210113
 >>> /mnt/ext_part1/_btrbk/onepc-lm/@.20210207
 >>> /mnt/ext_part1/_btrbk/onepc-lm/@.20210307

Archive in alpine Linux

The following added on the client homepc


# mkdir /etc/btrbk/ssh/
# ssh-keygen -t rsa -b 4096 -f /etc/btrbk/ssh/id_rsa -C kprabuanand@gmail.com -N ""
# scp /etc/btrbk/ssh/id_rsa.pub prabu@192.168.1.3:
# btrbk  --progress archive /mnt/btrfs/_btrbk_snap/ ssh://192.168.1.3/mnt/NAS/_btrbk/homepc2

Repeated the above steps on homepc

root@homepc:~# mkdir -p /etc/btrbk/ssh
root@homepc:~# cd /etc/btrbk/ssh/
root@homepc:/etc/btrbk/ssh# ssh-keygen -t rsa -b 4096 -f /etc/btrbk/ssh/id_rsa -C kprabuanand@gmail.com -N ""
Generating public/private rsa key pair.
Your identification has been saved in /etc/btrbk/ssh/id_rsa
Your public key has been saved in /etc/btrbk/ssh/id_rsa.pub
The key fingerprint is:
SHA256:OzmUhuMgUL9L5u1vI8LQ/4JG3QRQWRjYxOxeWBF8A0M kprabuanand@gmail.com
The key's randomart image is:
+---[RSA 4096]----+
|  . .O+BE+       |
| . .. B o.o      |
|.   .. + . .     |
| .   .o.o.       |
|  ..=oo+S        |
|  .=o=o+.o       |
|   +ooo =        |
|    =.+ oo       |
|   . ..*o.       |
+----[SHA256]-----+
root@homepc:/etc/btrbk/ssh#

The following added on the server(pi) In the file “/etc/ssh/sshd_config” the following entry was added under Authentication section:

pizero2W:~$ doas cat /etc/ssh/sshd_config|grep AuthorizedKeysFile
AuthorizedKeysFile	.ssh/authorized_keys

mkdir -p /root/.ssh
chmod 700 /root/.ssh
cat /home/prabu/id_rsa.pub >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys

With the above setup the archive was done using the below command.

prabu@homepc2 ~> doas btrbk --progress archive /mnt/btrfs/_btrbk_snap/ /mnt/ext_part1/_btrbk/homepc2/

References


© Prabu Anand K 2020-2026