Created
November 4, 2012 15:42
-
-
Save gvsrepins/4012342 to your computer and use it in GitHub Desktop.
SSH:MySQL Backup
This file contains hidden or 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 | |
# This script backups every MySQL database to its own file | |
#Some variables you can set how you like | |
USER='username' | |
PASSWORD='password' | |
OUTPUTDIR='/var/backup' | |
MYSQLDUMP='/usr/bin/mysqldump' | |
MYSQL='/usr/bin/mysql' | |
#Clean up any old backups | |
rm -f $OUTPUTDIR/* | |
#Get a list of databases names except the system one | |
databases=`$MYSQL --user=$USER --password=$PASSWORD -e 'SHOW DATABASES;' | grep -Ev '(Database|information_schema)'` | |
#Dump each database in turn and compress the output | |
for db in $databases; do | |
echo Backing up $db | |
$MYSQLDUMP --opt --hex-blob --force --user=$USER --password=$PASSWORD $db | gzip > $OUTPUTDIR/$db.gz | |
chown user-backup $OUTPUTDIR/$db.gz | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment