Last active
August 29, 2015 14:22
-
-
Save seangreen/097cfe1b62fcffcae85f to your computer and use it in GitHub Desktop.
Shell Script to import Magento LIVE DB to DEV DB
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 | |
# Author: Sean Grünböck / studio19.at | |
# Version: 1.1 | |
# Date: 26.06.2015 | |
# Usage: This script is used to import a LIVE Magento DB to a STAGING or DEV Environment. The script should be located in the Magento Home directory, that you want to import the DB into. | |
# Dependencies: This script needs mage-dbdump.sh by sonassi for DB dumping - has to be located in both Magento Installs (LIVE + CURRENT) | |
# (https://www.sonassi.com/knowledge-base/quicker-dumping-of-a-magento-mysql-database-for-branching/) | |
### VARIABLES ## | |
# LIVE path (path of LIVE Magento install - relative to current path) | |
LIVEPATH="../" | |
# URL of LIVE Mage installation | |
LIVEURL="" | |
# URL of CURRENT Mage installation | |
CURRENTURL="" | |
NOW=$(date +"%Y-%m-%d_%H-%M") | |
### ACTIONS ### | |
# Export STAGE DB | |
./mage-dbdump.sh -d | |
# GZIP + Rename STAGE DB Dump | |
#mv var/db.sql var/db-stage-backup.$NOW.sql | |
gzip -c var/db.sql > var/db-stage-backup_$NOW.sql.gz | |
rm var/db.sql | |
echo "Staging Dump backed up" | |
# Export LIVE DB | |
(cd $LIVEPATH; ./mage-dbdump.sh -d) | |
# move LIVE DB to UPGRADE | |
mv $LIVEPATH/var/db.sql var/db.sql | |
# rename URLS in Magento config | |
sed -i "s/$LIVEURL/$CURRENTURL/g" var/db.sql | |
# rename https to http in Magento Config | |
sed -i "s/https:\/\/$CURRENTURL/http:\/\/$CURRENTURL/g" var/db.sql | |
# import DB | |
./mage-dbdump.sh -r | |
# GZIP + Rename LIVE DB Dump | |
#mv var/db.sql var/db-live-backup.$NOW.sql | |
gzip -c var/db.sql > var/db-live-backup_$NOW.sql.gz | |
rm var/db.sql | |
echo "Live Dump backed up" | |
# clean cache | |
rm -rf var/cache/* | |
echo "Cache cleaned" | |
# | |
echo "DB Dump powered by Sonassi" | |
echo "dbimport-live script by Sean Grünböck @ studio19.at" | |
echo "######## ALL DONE! #######" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At some point I should change this to make it possible to immediately switch braintree to sandbox mode and to change the recipient of sales emails to test@...