Last active
September 14, 2016 13:25
-
-
Save bmatthewshea/4f05d082b13f07afdcf003e3ab417d0d to your computer and use it in GitHub Desktop.
FIND command to reduce backups in folder - saving only 1st of month if older than 90 days
This file contains hidden or 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 | |
DS=`date "+%Y-%m-%d %H:%M:%S"` | |
FINDPATH=/opt/mysql-backups | |
LOG="$FINDPATH"/mysql-backup-removal.log | |
### find >= 90 day - but leave/exclude a 1st day of month forever... | |
find "$FINDPATH"/backupname_* -name 'backupname_??-01-*' -prune -o -mtime +90 -exec ls {} \; -exec rm {} \; >> "$LOG" | |
## EXAMPLE CRONTAB USE | |
# $ crontab -e | |
# (ADD:) | |
## run on 2nd of month/each month: | |
# 0 0 2 * * /home/username/scripts/.cron_prune_backups.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment