Automated snapshots with Btrfs
Sun, Oct 1, 2023 02:00 CEST
Tags: Arch, Btrfs, Backup, Snapshots, Snapper, Snap-Pac, Pacman
To easily rollback /
.
Install snapper
pacman -S snapper
Make sure to have followed
snapper
’s recommendations regarding Btrfs subvolumes layout.
Note that snapper
creates a subvolume for snapshots at /.snapshots
but with
an unnecessary parent dependency on @
.
To allow snapper
to go through the configuration step, make sure you have
unmounted any subvolume (or other) mounted at /.snaphosts
and deleted any
corresponding directory.
umount /.snapshots
rm -r /.snapshots
Create configuration for the root subvolume
snapper -c root create-config /
Then delete the subvolume automatically created by snapper
btrfs subvolume delete /.snapshots
And replace it with an independent @snapshots
subvolume (if you had already
created it, mkdir /.snapshots && mount -a
should suffice).
Existing configurations can be listed with
snapper list-configs
You can edit configurations under /etc/snapper/configs/
.
To enable automatic timeline snapshots simply install cronie
and enable the corresponding systemd system service:
pacman -S cronie
systemctl enable --now cronie
To enable automatic pacman transactions snapshots for /
, install snap-pac
:
pacman -S snap-pac
You can configure snap-pac
at /etc/snap-pac.ini
.
To enable automatic pacman transactions snapshots for /boot
, create the
following pacman post-transaction hook:
# File: /etc/pacman.d/hooks/95-bootbackup.hook
[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Path
Target = usr/lib/modules/*/vmlinuz
[Action]
Depends = rsync
Description = Backing up /boot...
When = PostTransaction
Exec = /usr/bin/rsync -a --delete /boot /.boot.bak
Note that since the backup is stored on the root subvolume, it should be possible to access previous backups by restoring previous snapshots of the root subvolume.
To enable automatic snapshots on boot, enable snapper-boot.timer
:
systemctl enable --now snapper-boot.timer
Existing snapshots can be listed with
snapper list
See also: