new prune-old-backups cron script.
This commit is contained in:
@@ -10,6 +10,12 @@ declare -A STORAGE_ALERT
|
||||
# storage in GiB
|
||||
STORAGE_ALERT=(["/"]=5)
|
||||
|
||||
# when set to 0, all backups are kept
|
||||
PRUNE_DOWN_TO=0
|
||||
|
||||
# the directory with backups to cleanup
|
||||
PRUNE_DIRECTORY="/home/ubuntu/data"
|
||||
|
||||
SERVER_DOMAIN="localhost"
|
||||
|
||||
DISCORD_SERVER_NAME="<YOUR SERVER>"
|
||||
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
LOCATION=`dirname "$0"`
|
||||
|
||||
source "${LOCATION}/../config.sh"
|
||||
|
||||
# TODO: The maximum number of backups to keep (when set to 0, all backups are kept)
|
||||
maxNrOfBackups="$PRUNE_DOWN_TO"
|
||||
|
||||
# TODO: The directory where you store the Nextcloud backups
|
||||
backupMainDir="$PRUNE_DIRECTORY"
|
||||
|
||||
#
|
||||
# Delete old backups
|
||||
#
|
||||
if [ ${maxNrOfBackups} != 0 ]
|
||||
then
|
||||
nrOfBackups=$(ls -l ${backupMainDir} | grep -c ^d)
|
||||
|
||||
if [[ ${nrOfBackups} > ${maxNrOfBackups} ]]
|
||||
then
|
||||
echo "Removing old backups..."
|
||||
ls -t ${backupMainDir} | tail -$(( nrOfBackups - maxNrOfBackups )) | while read -r dirToRemove; do
|
||||
echo "${dirToRemove}"
|
||||
rm -r "${backupMainDir}/${dirToRemove:?}"
|
||||
echo "Done"
|
||||
echo
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user