add local retention script
This commit is contained in:
parent
891dc82a1b
commit
e549409a18
1 changed files with 23 additions and 0 deletions
23
local-retention.sh
Executable file
23
local-retention.sh
Executable file
|
@ -0,0 +1,23 @@
|
|||
#1/usr/bin/env sh
|
||||
|
||||
list_after_n() {
|
||||
echo "$1" | sort -r | tail -n +"$2" | tr '\n' ' '
|
||||
}
|
||||
|
||||
ARCHIVE_DIR=${ARCHIVE_DIR:-"/archive"}
|
||||
FILE_QUOTA=${FILE_QUOTA:-7}
|
||||
|
||||
old_archives=$( find "$ARCHIVE_DIR" -maxdepth 1 -type f -printf "%f\n" )
|
||||
old_dirs=$( find "$ARCHIVE_DIR" -maxdepth 1 -mindepth 1 -type d -printf "%f\n" )
|
||||
|
||||
last_n_archives=$( list_after_n "$old_archives" "$FILE_QUOTA" )
|
||||
last_n_dirs=$( list_after_n "$old_dirs" "$FILE_QUOTA" )
|
||||
|
||||
for archive in $last_n_archives; do
|
||||
rm "$ARCHIVE_DIR/$archive"
|
||||
done
|
||||
|
||||
for dir in $last_n_dirs; do
|
||||
rm -r "$ARCHIVE_DIR/$dir"
|
||||
done
|
||||
|
Loading…
Reference in a new issue