You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
472 B
Bash
22 lines
472 B
Bash
5 years ago
|
#!/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
|