Skip to content

Instantly share code, notes, and snippets.

@aaronott
Created August 31, 2016 16:42
Embed
What would you like to do?
#!/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