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" ''; };