Created
July 19, 2015 21:01
-
-
Save patmandenver/c739a7a66339b596a678 to your computer and use it in GitHub Desktop.
Bash Script to purge old Database files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Script to purge old database backups | |
# Run via cron job | |
# | |
######################################### | |
######################################### | |
# | |
# Config section | |
# | |
######################################### | |
BACKUP_DIR="/data/db-nightly-backups" | |
DAYS_TO_KEEP=15 | |
######################################### | |
# | |
# Delete Old Datbases older than $DAYS_TO_KEEP | |
# | |
######################################### | |
# for testing you can switch mtime for days to mmin for minutes | |
NUM_FILES_REMOVED=`find $BACKUP_DIR -maxdepth 1 -mtime +$DAYS_TO_KEEP -name "*.database.*" | wc -l` | |
# for testing you can switch mtime for days to mmin for minutes | |
if ! find $BACKUP_DIR -maxdepth 1 -mtime +$DAYS_TO_KEEP -name "*.database.*" | xargs -I{} rm -rf {}; | |
then | |
echo "DB purge failed. Exiting." 1>&2 | |
exit 3 | |
fi | |
######################################### | |
# | |
# purge Complete now notify! | |
# | |
######################################### | |
echo "" | |
echo "================================" | |
echo "" | |
echo " DATABASE purge Complete" | |
echo "" | |
echo " Databases Removed : $NUM_FILES_REMOVED" | |
echo "" | |
echo " Only keeping $DAYS_TO_KEEP DAYS" | |
echo "================================" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment