digint / btrbk

Tool for creating snapshots and remote backups of btrfs subvolumes
https://digint.ch/btrbk/
GNU General Public License v3.0
1.64k stars 120 forks source link

Feature request: Notify on outdated backups #483

Open ckotte opened 2 years ago

ckotte commented 2 years ago

I couldn't find a command or an additional script to "throw an alert" if the latest backups are too old.

# sudo -u btrbk btrbk list latest
SOURCE_SUBVOLUME     SNAPSHOT_SUBVOLUME                                   STATUS  TARGET_SUBVOLUME
/mnt/btrfs/@         /mnt/btrfs/@snapshots/btrbk/root.20220714T1600       -       /run/media/user/backup/btrbk-system/laptop/root.20220714T1600
/mnt/btrfs/@var-log  /mnt/btrfs/@snapshots/btrbk/var-log.20220714T1600    -       /run/media/user/backup/btrbk-system/laptop/var-log.20220714T1600
/mnt/btrfs/@home     /mnt/btrfs/@snapshots/btrbk/home.20220714T2000       -       /run/media/user/backup/btrbk-system/laptop/home.20220714T2000

I use a laptop and an external USB disk to store my snapshots and I would like to get notified if my latest backups are i.e. two weeks old.

Any suggestions how this could be implemented?

I could then use this to create a dedicated timer and service which is executed every day and sends a warning message if the backups are too old.

However, this only works if snapshot_create ondemand is used since the target is not available if the USB disk is disconnected. If I use snapshot_create always then I always have daily/hourly snapshots, but I don't know if they are available on my backup disk.

# sudo -u btrbk btrbk list latest 
WARNING: Skipping target "/run/media/user/backup/btrbk-system/laptop": Failed to fetch subvolume detail
WARNING: ... Command execution failed (exitcode=1)
WARNING: ... sh: sudo -n readlink -v -e '/run/media/user/backup/btrbk-system/laptop'
WARNING: ... readlink: /run/media/user/backup/btrbk-system/laptop: No such file or directory
WARNING: Skipping target "/run/media/user/backup/btrbk-system/laptop": Failed to fetch subvolume detail
WARNING: Skipping target "/run/media/user/backup/btrbk-system/laptop": Failed to fetch subvolume detail
SOURCE_SUBVOLUME     SNAPSHOT_SUBVOLUME                                   STATUS
/mnt/btrfs/@         /mnt/btrfs/@snapshots/btrbk/root.20220714T1600       -
/mnt/btrfs/@var-log  /mnt/btrfs/@snapshots/btrbk/var-log.20220714T1600    -
/mnt/btrfs/@home     /mnt/btrfs/@snapshots/btrbk/home.20220714T2000       -

Maybe some additional info about snapshots send to a target can be stored in a cache directory? Otherwise, I would need to parse the logfile.

digint commented 2 years ago

Maybe some additional info about snapshots send to a target can be stored in a cache directory?

This is not possible, by design btrbk is stateless and will not store any data other than the subvolumes itself. That said, I could make an exception for a specific feature, but I believe the most straight-forward solution is to have a wrapper around btrbk for this (e.g. update some timestamp on success, check periodically in timer).

I'm not sure if I fully understand what exactly you want to check, and that might be the biggest challenge for a notification feature (every user has his own requirements here I fear).

ckotte commented 1 year ago

I meant implementing a command as mentioned above with two new options in btrbk.conf. One option about the age and one option about the command that should be executed if the latest snapshots are too old.

The problem is: If I forgot to connect my external flash drive, new backups won't be connected and I might have two weeks old backups... If I get a notification via my custom command I would be reminded about old backups and I should connect my flash drive..