Created
October 3, 2014 07:36
-
-
Save ejoubaud/6a1bebbaa4b0d0d09277 to your computer and use it in GitHub Desktop.
Snapshot DB: Create snapshots of db fast. Inspired by Stellar. Useful to switch to different themes with starter data in Wordpress development much faster than WP Importer.
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 | |
TARGET_DB=wordpress_default | |
# This is meant for a dev env (VVV actually), you may want to use something more secure to store credentials, and possibly a user with target-db-specific privileges. | |
ROOT=root | |
ROOT_PW=root | |
mysql -u${ROOT} -p${ROOT_PW} -e'SHOW DATABASES;' | |
echo "Warning! This will copy the content of ${TARGET_DB}, which may take a lot of disk space (possibly more than you have." | |
read -p "What name for your snapshot? " snapshot | |
if [[ -z $snapshot ]]; then | |
echo "No snapshot name input, exiting" | |
exit 1 | |
fi | |
mysqldbcopy --source=${ROOT}:${ROOT_PW}@localhost --destination=${ROOT}:${ROOT_PW}@localhost ${TARGET_DB}:${snapshot} |
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 | |
TARGET_DB=wordpress_default | |
# This is meant for a dev env (VVV actually), you may want to use something more secure to store credentials, and possibly a user with target-db-specific privileges. | |
ROOT=root | |
ROOT_PW=root | |
mysql -u${ROOT} -p${ROOT_PW} -e'SHOW DATABASES;' | |
echo "Warning! This will destroy DB ${TARGET_DB} and replace it with snapshot db! If you don't know what you're doing, it's a terrible thing to do!" | |
read -p "Which database use as source snapshot ?" snapshot | |
if [[ -z $snapshot ]]; then | |
echo "No source DB selected, exiting" | |
exit 1 | |
fi | |
mysqladmin drop wordpress_default -u${ROOT} -p${ROOT} | |
mysqldbcopy --source=${ROOT}:${ROOT_PW}@localhost --destination=${ROOT}:${ROOT_PW}@localhost ${snapshot}:${TARGET_DB} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment