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
490 B
Bash
22 lines
490 B
Bash
#!/usr/bin/env bash
|
|
|
|
set -euxo pipefail;
|
|
|
|
backupsToKeep={{ backups_to_keep | quote }};
|
|
|
|
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 -r dir; do
|
|
find "$dir" -type f | onlyDatedFiles | sort --reverse | tail --lines=+$((backupsToKeep + 1)) | xargs rm --force;
|
|
done
|