Created
November 1, 2015 10:11
-
-
Save RobbiNespu/04780e8d8928ab7c7bba to your computer and use it in GitHub Desktop.
0 0 * * * /usr/local/bin/mysql_backup.sh
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 | |
DB_BACKUP="/home/backup/mysql_backup" | |
DB_USER="root" | |
DB_PASSWD="replace_this_text_with_your_mysql_root_password_if_needed" | |
HN=`hostname | awk -F. '{print $1}'` | |
# Clear out backup directory | |
rm -rf $DB_BACKUP/*.sql | |
# Backup each database on the system | |
for db in $(mysql -e 'show databases' -s --skip-column-names|grep -viE '(staging|performance_schema|information_schema)'); | |
#do mysqldump --opt $db > "$DB_BACKUP/mysqldump-$HN-$db.sql" && sleep 5m; | |
do mysqldump --opt --events $db > "$DB_BACKUP/mysqldump-$HN-$db.sql"; | |
done | |
# Use this method if you need to specify a root user/password | |
#for db in $(mysql --user=$DB_USER --password=$DB_PASSWD -e 'show databases' -s --skip-column-names|grep -viE '(staging|performance_schema|information_schema)'); | |
#do mysqldump --user=$DB_USER --password=$DB_PASSWD --opt $db > "$DB_BACKUP/mysqldump-$HN-$db.sql" && sleep 5m; | |
#done | |
# Make it so only root can read the backups | |
chmod -R 600 $DB_BACKUP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment