common: Configured auto remove of backups
parent
32957fc899
commit
102de98479
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euxo pipefail;
|
||||
|
||||
backupsToKeep={{ backups_to_keep }};
|
||||
|
||||
function onlyDatedFiles() {
|
||||
grep --perl-regexp '/\d+(-\d+)*(\.[^/]+)*$';
|
||||
}
|
||||
|
||||
function getDirName() {
|
||||
grep --only-matching --perl-regexp '^.+(?=/[^/]+)';
|
||||
}
|
||||
|
||||
find {{ backups_directory | quote }} -type f |
|
||||
onlyDatedFiles |
|
||||
getDirName |
|
||||
sort --unique |
|
||||
while read dir; do
|
||||
find "$dir" --type f | onlyDatedFiles | sort --reverse | tail --lines=+$((backupsToKeep + 1)) | xargs rm;
|
||||
done
|
Loading…
Reference in New Issue