Btrbk local regular snapshots time machine - nutthawit/alpine-dotfile GitHub Wiki
The simplest use case is to only create snapshots of your data. This will obviously not protect it against hardware failure, but can be useful for:
- protection against inadvertent changes or deletions
- keeping past states of copies from rsync or similar tools
Let's assume you need regular snapshots of your / directory (root filesystem), which is located in the subvolume named @ of the volume /mnt/btr_pool. The snapshots are to be stored in btrbk_snapshots
Prerequisite
Configuration
First create btrbk_snapshots directory
mkdir /mnt/btr_pool/btrbk_snapshots
And create /etc/btrbk/btrbk.conf with following content:
compat busybox
timestamp_format long
snapshot_preserve_min 8h
snapshot_preserve 16h
snapshot_dir /mnt/btr_pool/btrbk_snapshots
subvolume /mnt/btr_pool/@
[!CAUTION] The compat busybox is required, to tell
btrbkusereadlinkfrombusyboxinstead ofcoreutils. Read more
snapshot_dir is directory in which the btrfs snapshots are created. For more options that btrbk.conf support look at https://digint.ch/btrbk/doc/btrbk.conf.5.html
Start a dry run (-n, --dry-run):
btrbk run -n
If you see output like the one below, it means it is working correctly.
/mnt/btr_pool/@
+++ /mnt/btr_pool/btrbk_snapshots/@.20251003T0753
If it works as expected, configure a busybox crond to run btrbk hourly:
mkdir /etc/periodic/30min
touch /etc/periodic/30min/btrbk && chmod +x /etc/periodic/30min/btrbk
vi /etc/periodic/30min/btrbk
Add following content to /etc/periodic/30min/btrbk:
#!/bin/sh
exec /usr/bin/btrbk -q run
Add 30min entry to /etc/crontabs/root:
# do daily/weekly/monthly maintenance
# min hour day month weekday command
*/15 * * * * run-parts /etc/periodic/15min
*/30 * * * * run-parts /etc/periodic/30min
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
Start crond service
rc-service crond start
rc-update add crond
rc-service crond restart
Snapshots will now be created every 30 min. All snapshots are preserved for at least 8 hours (snapshot_preserve_min), whether they are created by the cron job or manually by calling sudo btrbk run on the command line. Additionally, 16 hourly snapshots are preserved (snapshot_preserve).
[!TIP] If you want to start root_fs snapshot immediately run:
btrbk snapshot @Read more
You can read more on https://github.com/digint/btrbk?tab=readme-ov-file#example-local-regular-snapshots-time-machine
See also
https://github.com/digint/btrbk?tab=readme-ov-file#example-local-regular-snapshots-time-machine
Todo
- Currently it's not work with sync-cron, instead we must used async-cron