common: backup_autoremove: Improved script quality

dehydrated
Felix Stupp 4 years ago
parent 6c7f35075b
commit 3bc9c9360d
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -2,7 +2,7 @@
set -euxo pipefail; set -euxo pipefail;
backupsToKeep={{ backups_to_keep }}; backupsToKeep={{ backups_to_keep | quote }};
function onlyDatedFiles() { function onlyDatedFiles() {
grep --perl-regexp '/\d+(-\d+)*(\.[^/]+)*$'; grep --perl-regexp '/\d+(-\d+)*(\.[^/]+)*$';
@ -16,6 +16,6 @@ find {{ backups_directory | quote }} -type f |
onlyDatedFiles | onlyDatedFiles |
getDirName | getDirName |
sort --unique | sort --unique |
while read dir; do while read -r dir; do
find "$dir" -type f | onlyDatedFiles | sort --reverse | tail --lines=+$((backupsToKeep + 1)) | xargs rm --force; find "$dir" -type f | onlyDatedFiles | sort --reverse | tail --lines=+$((backupsToKeep + 1)) | xargs rm --force;
done done

Loading…
Cancel
Save