mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-11-13 12:13:36 +01:00
fix(youko): date restic store snapshots by name, not mtime
On its next run the unit deletes every snapshot whose name stamp is older than 14 days, whatever its mtime. Assisted-by: DeepSeek Harness 0.2.1-rc.2 (claude-opus-5-5)
This commit is contained in:
1 parent
3b3992468b
commit
92f59df25a
1 file changed
+11
-4
@@ -29,16 +29,23 @@ in
|
||||
path = [
|
||||
pkgs.btrfs-progs
|
||||
pkgs.coreutils
|
||||
pkgs.findutils
|
||||
];
|
||||
script = ''
|
||||
set -euo pipefail
|
||||
stamp=$(date +%Y%m%d%H%M%S)
|
||||
btrfs subvolume snapshot -r ${source} ${snapshotRoot}/backups.$stamp
|
||||
# Drop snapshots older than ${toString keepDays} days. The desktop cannot
|
||||
# reach this tree, so it cannot shorten the window.
|
||||
find ${snapshotRoot} -mindepth 1 -maxdepth 1 -type d -mtime +${toString keepDays} -print0 |
|
||||
xargs -0 -r -n1 btrfs subvolume delete
|
||||
# reach this tree, so it cannot shorten the window. Age comes from the
|
||||
# name: a snapshot's root directory keeps the source's mtime, not the
|
||||
# time it was taken, so `find -mtime` cannot date it.
|
||||
cutoff=$(date -d '-${toString keepDays} days' +%Y%m%d%H%M%S)
|
||||
for snap in ${snapshotRoot}/backups.*; do
|
||||
[ -e "$snap" ] || continue
|
||||
taken=''${snap##*/backups.}
|
||||
if [[ $taken =~ ^[0-9]{14}$ && $taken < $cutoff ]]; then
|
||||
btrfs subvolume delete "$snap"
|
||||
fi
|
||||
done
|
||||
'';
|
||||
unitConfig.RequiresMountsFor = source;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user