Last active
August 29, 2015 13:59
-
-
Save kmadac/10459776 to your computer and use it in GitHub Desktop.
backup mysql database for particlar domain by mysqldump
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
Script will create testing databases and creates backup of all databses which belongs to domain testdom123.sk. | |
Result of the script is file testdom123.sk.sql. | |
Restore can be done by applying the file back to mysql: | |
mysql -u root -plol < testdom123_sk.sql |
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 | |
TAIL=`which tail` | |
MYSQLDUMP=`which mysqldump` | |
DOMAIN='testdom123.sk' | |
DOMAIN_DB=${DOMAIN//\./_} | |
DBPASS=lol | |
MYSQL="mysql -u root -p$DBPASS -e" | |
# Start preparation | |
$MYSQL "create database testdom123_sk_1" | |
$MYSQL "create database testdom123_sk_2" | |
$MYSQL "create database testdom123_sk_3" | |
$MYSQL "CREATE TABLE states (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, state CHAR(25), population INT(9));" -D testdom123_sk_1 | |
$MYSQL "create database testdom234_sk_1" | |
# preparation finished | |
# get database names to backup | |
databases=`$MYSQL "SHOW DATABASES LIKE '$DOMAIN_DB%'" -B | $TAIL -n +2` | |
# back up databases | |
$MYSQLDUMP --databases $databases --password=$DBPASS --user=root > $DOMAIN_DB.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment