diff --git a/backup/README.md b/backup/README.md index f22548e..e46c21f 100644 --- a/backup/README.md +++ b/backup/README.md @@ -1,5 +1,13 @@ # Generic Backup Host +## Crontab + +Runs on the second of every month. + +``` +0 0 2 * * cd /home/USER/backups && bash prune.sh +``` + ## Filenames Container volume backups are of the format: diff --git a/backup/prune.sh b/backup/prune.sh index 38c4bca..5bdff32 100644 --- a/backup/prune.sh +++ b/backup/prune.sh @@ -1,15 +1,14 @@ #!/usr/bin/bash -# Prunes container data folders monthly on backup host -# - Regex has been tested and works -# - Script is not yet tested +# Prunes container data folders monthly on backup host. +# Removes all items but the backup from the first day of the month. +# Should run on the first day of every month - since it doesn't remove the backup +# from that time, it doesn't matter what time it's run -ARCHIVES=$(ls | grep -E "[0-9A-Za-z]+-data-\d{4}-\d{2}-([^0][0-9]|[0-9][^1])_.*") - -for archive in $ARCHIVES; do - if [ -d $archive ]; then - echo "Removing $archive" - rm -f $archive +for item in *; do + if [[ "$item" =~ [0-9A-Za-z]+-data-[0-9]{4}-[0-9]{2}-([^0][0-9]|[0-9][^1])_.* ]]; then + echo "Removing $item" + rm -f $item fi done