Last active
January 1, 2016 23:19
-
-
Save Marko-M/8215674 to your computer and use it in GitHub Desktop.
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 | |
# magento-transfer-2.sh | |
# Marko Martinovic | |
# | |
# Initiate on a destination web server | |
# Maintenance mode required | |
# Prints command traces | |
set -x | |
# Tables to ignore | |
IGNORE_TABLES=(dataflow_batch_export dataflow_batch_import log_customer log_quote log_summary log_summary_type log_url log_url_info log_visitor log_visitor_info log_visitor_online report_event index_event enterprise_logging_event_changes core_cache core_cache_tag core_session core_cache_tag) | |
# Source SSH | |
SRC_SSH_USER="" | |
SRC_SSH_HOST="" | |
SRC_SSH_PORT="22" | |
# Source MySQL | |
SRC_MYSQLDUMP_USER="" | |
SRC_MYSQLDUMP_PASS="" | |
SRC_MYSQLDUMP_DBNAME="" | |
SRC_MYSQLDUMP_HOST="localhost" | |
SRC_MYSQLDUMP_PORT="3306" | |
# Source document root path (absolute) | |
SRC_DOCROOT_PATH="" | |
# Destination MySQL | |
DST_MYSQL_USER="" | |
DST_MYSQL_PASS="" | |
DST_MYSQL_DBNAME="" | |
DST_MYSQL_HOST="localhost" | |
DST_MYSQL_PORT="3306" | |
# Destination document root path (absolute) | |
DST_DOCROOT_PATH="" | |
# rsync the code (incremental, supports non standard port) | |
rsync -avz -e "ssh -p $SRC_SSH_PORT" $SRC_SSH_USER@$SRC_SSH_HOST:$SRC_DOCROOT_PATH $DST_DOCROOT_PATH | |
set - # stop trace | |
IGNORE_STRING="" | |
for TABLE in "${IGNORE_TABLES[@]}"; do | |
IGNORE_STRING="$IGNORE_STRING --ignore-table=$SRC_MYSQLDUMP_DBNAME.$TABLE" | |
done | |
set -x # continue trace | |
ssh -C $SRC_SSH_USER@$SRC_SSH_HOST -p $SRC_SSH_PORT "(mysqldump -h\"$SRC_MYSQLDUMP_HOST\" -P\"$SRC_MYSQLDUMP_PORT\" -u\"$SRC_MYSQLDUMP_USER\" -p\"$SRC_MYSQLDUMP_PASS\" --no-data --compress $SRC_MYSQLDUMP_DBNAME && mysqldump $IGNORE_STRING -h\"$SRC_MYSQLDUMP_HOST\" -P\"$SRC_MYSQLDUMP_PORT\" -u\"$SRC_MYSQLDUMP_USER\" -p\"$SRC_MYSQLDUMP_PASS\" --no-create-db --no-create-info --skip-triggers --single-transaction --quick --compress $SRC_MYSQLDUMP_DBNAME) | gzip -9 -c" | gunzip | sed -E 's/DEFINER=`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g' | mysql -P"$DST_MYSQL_PORT" -h"$DST_MYSQL_HOST" -u"$DST_MYSQL_USER" -p"$DST_MYSQL_PASS" $DST_MYSQL_DBNAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment