Make sure to keep some snapshots around even if they stop coming.
This commit is contained in:
@@ -42,14 +42,24 @@ in
|
|||||||
# Cleanup old snapshots on standby (keep last 4 hours for HA failover)
|
# Cleanup old snapshots on standby (keep last 4 hours for HA failover)
|
||||||
systemd.services.cleanup-services-standby-snapshots = {
|
systemd.services.cleanup-services-standby-snapshots = {
|
||||||
description = "Cleanup old btrfs snapshots in services-standby";
|
description = "Cleanup old btrfs snapshots in services-standby";
|
||||||
path = [ pkgs.btrfs-progs pkgs.findutils ];
|
path = [ pkgs.btrfs-progs pkgs.findutils pkgs.coreutils ];
|
||||||
|
|
||||||
script = ''
|
script = ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
# Keep last 4 hours of snapshots (48 snapshots at 5min intervals)
|
|
||||||
find /persist/services-standby -maxdepth 1 -name 'services@*' -mmin +240 -exec btrfs subvolume delete {} \; || true
|
|
||||||
'';
|
|
||||||
|
|
||||||
|
# Keep at least 2 hours of snapshots (24 snapshots at 5min intervals)
|
||||||
|
MIN_KEEP=24
|
||||||
|
|
||||||
|
# Count existing snapshots
|
||||||
|
count=$(find /persist/services-standby -maxdepth 1 -name 'services@*' -type d | wc -l)
|
||||||
|
|
||||||
|
# Only delete old snapshots if we have more than the minimum
|
||||||
|
if [ $count -gt $MIN_KEEP ]; then
|
||||||
|
# Delete snapshots older than 4 hours
|
||||||
|
find /persist/services-standby -maxdepth 1 -name 'services@*' -mmin +240 -exec btrfs subvolume delete {} \; || true
|
||||||
|
else
|
||||||
|
echo "Only $count snapshots found, keeping all (minimum: $MIN_KEEP)"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
User = "root";
|
User = "root";
|
||||||
|
|||||||
Reference in New Issue
Block a user