Scripts used for snap-sync snapshot replication onto an external usb drive
Find a file
2022-10-15 21:11:30 +02:00
scripts Initial commit 2022-10-15 21:05:53 +02:00
services Initial commit 2022-10-15 21:05:53 +02:00
LICENSE.txt Initial commit 2022-10-15 21:05:53 +02:00
README.md Reference specific line 2022-10-15 21:11:30 +02:00

Incremental sync-snap with cleanup

These are simple scripts I use for incrementally backuping my system running on btrfs whenever I connect my USB drive to my computer(s).

One could of course also simply use other tools like btrbk to automatically backup/replicate btrfs snapshots. One would just have to change the commands used to btrbk run and let btrbk itself handle the cleanup locally and on the external drive. For a desktop system I still like to be able to manually snapshot or cleanup using snapper-gui and since snap-sync does not automatically prune old snapshots, we need a simple cleanup script that runs after the snap-sync replication.

Based on this it's also possible to use a network target to simply replicate snapshots onto a NAS or similar.

Config

You should have a subvolume present already on your backup drive using something like snap-sync -c "root home" -d "latest incremental backup" pointing to snapshot_root configured in clean-snap-sync-external.sh. After first replication snap-sync automatically uses the same subvolume again so that you just have to set the UUID of your external drive you placed your initial snapshot on in the bash scripts in the scripts folder.

If you are going to enable snap-sync-cleanup.service, edit the snapshot root and the amount of snapshots to keep on the external drive in clean-snap-sync-external.sh as well.

Edit both services in the services folder and edit the path to the scripts. In my case I just keep them on the external drive my replicated snapshots reside on.

You also have to edit the .mount target in all service files to point to your usb drive. You can get the correct mount target by running systemctl list-units -t mount.

Install

Place the services in the services folder in /etc/systemd/system/, run systemctl daemon-reload and enable each of them:

snap-sync.service for backuping a new snapshot onto your disk

snap-sync-cleanup.service for deleting any snapshots older than the amount you've configured (only runs if snap-sync.service succeeded)

The next time you connect your external drive a snap-sync notification should pop up, starting the replication process.



TODO

  • Proper config file
  • setup script
  • AUR package?