-
-
Save mnathani/ebea31cf5be750c46f68 to your computer and use it in GitHub Desktop.
tarsnap database backup cron script
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 | |
# This script backups every MySQL database to its own file | |
#Some variables you can set how you like | |
USER='root' | |
PASSWORD='X' | |
OUTPUTDIR='/home/backup/butterfly-sql' | |
MYSQLDUMP="$(which mysqldump)" | |
MYSQL="$(which mysql)" | |
TARSNAP="$(which tarsnap)" | |
#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|mysql|cphulkd|eximstats|horde|leechprotect|logaholicDB|performance_schema|roundcube|whmxfer)'` | |
#Dump each database in turn and compress the output | |
for db in $databases; do | |
$MYSQLDUMP --opt --force --user=$USER --password=$PASSWORD $db > $OUTPUTDIR/$db"_"`date +%Y-%m-%d`.sql | |
done | |
$TARSNAP -c -f butterfly-mysql_`date +%F_%H-%M-%S` $OUTPUTDIR | |
#rm -f $OUTPUTDIR/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment