-
-
Save dwinurhadia/998a942b560bd2418f94aecba204d32a to your computer and use it in GitHub Desktop.
Backup all MySQL databases into separate files
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/sh | |
| # backup each mysql db into a different file, rather than one big file | |
| # as with --all-databases - will make restores easier | |
| USER="backup" | |
| PASSWORD="s3cr3t" | |
| OUTPUTDIR=$(dirname $0)"/databases" | |
| MYSQLDUMP="/usr/bin/mysqldump" | |
| MYSQL="/usr/bin/mysql" | |
| databases=`$MYSQL --user=$USER --password=$PASSWORD --batch --skip-column-names -e "SHOW DATABASES;" | grep -v 'mysql\|information_schema'` | |
| for database in $databases; do | |
| $MYSQLDUMP \ | |
| --user=$USER --password=$PASSWORD \ | |
| --force \ | |
| --quote-names --dump-date \ | |
| --opt --single-transaction \ | |
| --events --routines --triggers \ | |
| --databases $database \ | |
| --result-file="$OUTPUTDIR/$database.sql" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment