feat: prune old cld backups after sync

This commit is contained in:
m3tam3re
2026-06-20 10:20:29 +02:00
parent 14008a4bc9
commit b266deedb8
+11 -1
View File
@@ -27,6 +27,7 @@ in {
path = with pkgs; [ path = with pkgs; [
coreutils coreutils
findutils
openssh openssh
rsync rsync
util-linux util-linux
@@ -53,7 +54,9 @@ in {
exit 1 exit 1
fi fi
flock -n "$lock_file" \ (
flock -n 9
rsync \ rsync \
-aH \ -aH \
--no-owner \ --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" \ -e "ssh -i ${sshKey} -p ${targetPort} -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/var/lib/${serviceName}/known_hosts" \
${sourceDir} \ ${sourceDir} \
${targetUser}@${targetHost}:${targetDir} ${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"
''; '';
}; };