feat: prune old cld backups after sync
This commit is contained in:
@@ -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"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user