Skip to content

Instantly share code, notes, and snippets.

@snez
Last active April 19, 2017 18:40
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 snez/7890664 to your computer and use it in GitHub Desktop.
Save snez/7890664 to your computer and use it in GitHub Desktop.
30-Day Rolling MySQL Database Backups
#!/bin/bash
export d=`date +%d`
export BACKUP_DIR="/home/user/backups/$d"
export USERNAME="username"
export PASSWORD="password"
export HOST="localhost"
mkdir -p $BACKUP_DIR
for DB in db1 db2 db3
do
echo "Backing up $DB"
mysqldump --add-drop-table --allow-keywords --databases $DB -h $HOST -u $USERNAME -p$PASSWORD > $BACKUP_DIR/$DB.sql
rm $BACKUP_DIR/$DB.sql.gz
gzip $BACKUP_DIR/$DB.sql
done
@gnacu
Copy link

gnacu commented Apr 19, 2017

Nice. Super clean, works great. This is the sort of code I like to see and put to use. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment