From b266deedb8390262a21d59f5a448389522391af7 Mon Sep 17 00:00:00 2001 From: m3tam3re Date: Sat, 20 Jun 2026 10:20:29 +0200 Subject: [PATCH] feat: prune old cld backups after sync --- hosts/AZ-CLD-1/services/var-backup-sync.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hosts/AZ-CLD-1/services/var-backup-sync.nix b/hosts/AZ-CLD-1/services/var-backup-sync.nix index d0204da..72ff366 100644 --- a/hosts/AZ-CLD-1/services/var-backup-sync.nix +++ b/hosts/AZ-CLD-1/services/var-backup-sync.nix @@ -27,6 +27,7 @@ in { path = with pkgs; [ coreutils + findutils openssh rsync util-linux @@ -53,7 +54,9 @@ in { exit 1 fi - flock -n "$lock_file" \ + ( + flock -n 9 + rsync \ -aH \ --no-owner \ @@ -69,6 +72,13 @@ in { -e "ssh -i ${sshKey} -p ${targetPort} -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/var/lib/${serviceName}/known_hosts" \ ${sourceDir} \ ${targetUser}@${targetHost}:${targetDir} + + echo "Removing /var/backup files older than 7 days" + find ${sourceDir} -type f -mtime +7 -print -delete + + echo "Removing empty directories under /var/backup" + find ${sourceDir} -mindepth 1 -depth -type d -empty -print -delete + ) 9>"$lock_file" ''; };