Skip to content

Instantly share code, notes, and snippets.

@bmatthewshea
Last active September 14, 2016 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmatthewshea/4f05d082b13f07afdcf003e3ab417d0d to your computer and use it in GitHub Desktop.
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
#!/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