Skip to content

Instantly share code, notes, and snippets.

@aaronott
Created August 31, 2016 16:42
Show Gist options
  • Save aaronott/e490cb13dcb2905bc4f71c654d090540 to your computer and use it in GitHub Desktop.
Save aaronott/e490cb13dcb2905bc4f71c654d090540 to your computer and use it in GitHub Desktop.
#!/bin/sh
DBNAME=<database>
DBUSER=<dbuser>
DBPASS=<good-strong-password?>
DBHOST=localhost
DESTDIR=/path/to/backup/dir
NAME=<site-name>
RETENTION=2
let MMIN=($RETENTION*60*24)-30
DATE=`date +%Y-%m-%d-%H-%M`
if [ ! -d $DESTDIR ]
then
/bin/mkdir -p $DESTDIR
fi
/usr/bin/find $DESTDIR -type f -name '*.sql.gz' -mmin +$MMIN | xargs /bin/rm -rf
/usr/bin/mysqldump -h $DBHOST -u$DBUSER -p$DBPASS $DBNAME | gzip - > $DESTDIR/$NAME-$DATE.sql.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment