Last active
April 19, 2017 18:40
-
-
Save snez/7890664 to your computer and use it in GitHub Desktop.
30-Day Rolling MySQL Database Backups
This file contains 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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. Super clean, works great. This is the sort of code I like to see and put to use. Thanks.