Last active
December 22, 2016 18:35
-
-
Save phcorp/ab9b71277d624719eca84a65436d66e0 to your computer and use it in GitHub Desktop.
Prestashop database synchronization from local to remote staging server.
This file contains 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
#!/usr/bin/env bash | |
ssh_address="example@domain.com"; | |
dump_filename="dump.sql"; | |
site_remote_path="/home/example"; | |
site_remote_domain="staging.example.com" | |
local_db_host=$(php -r 'include("config/settings.inc.php");echo _DB_SERVER_;'); | |
local_db_name=$(php -r 'include("config/settings.inc.php");echo _DB_NAME_;'); | |
local_db_user=$(php -r 'include("config/settings.inc.php");echo _DB_USER_;'); | |
local_db_pass=$(php -r 'include("config/settings.inc.php");echo _DB_PASSWD_;'); | |
local_db_prefix=$(php -r 'include("config/settings.inc.php");echo _DB_PREFIX_;'); | |
mysqldump --host="$local_db_host" --user="$local_db_user" --password="$local_db_pass" "$local_db_name" $(mysql --host="$local_db_host" --user="$local_db_user" --password="$local_db_pass" -D "$local_db_name" -Bse "show tables like '$local_db_prefix%'") > "$dump_filename"; | |
echo "UPDATE ps_shop_url SET domain=\"$site_remote_domain\", domain_ssl=\"$site_remote_domain\", physical_uri=\"/\" WHERE 1;" >> "$dump_filename"; | |
echo "UPDATE ps_configuration SET value=\"$site_remote_domain\" WHERE name=\"PS_SHOP_DOMAIN\" OR name=\"PS_SHOP_DOMAIN_SSL\";" >> "$dump_filename"; | |
rsync -v -e ssh --progress "$dump_filename" "$ssh_address:$site_remote_path/upload/"; | |
rm "$dump_filename"; | |
remote_db_host=$(ssh "$ssh_address" echo "\$(php -r 'include(\"$site_remote_path/config/settings.inc.php\");echo _DB_SERVER_;')"); | |
remote_db_name=$(ssh "$ssh_address" echo "\$(php -r 'include(\"$site_remote_path/config/settings.inc.php\");echo _DB_NAME_;')"); | |
remote_db_user=$(ssh "$ssh_address" echo "\$(php -r 'include(\"$site_remote_path/config/settings.inc.php\");echo _DB_USER_;')"); | |
remote_db_pass=$(ssh "$ssh_address" echo "\$(php -r 'include(\"$site_remote_path/config/settings.inc.php\");echo _DB_PASSWD_;')"); | |
ssh "$ssh_address" "mysqldump --host=\"$remote_db_host\" --user=\"$remote_db_user\" --password=\"$remote_db_pass\" \"$remote_db_name\" | grep -e '^DROP \| FOREIGN_KEY_CHECKS' | mysql --host=\"$remote_db_host\" --user=\"$remote_db_user\" --password=\"$remote_db_pass\" \"$remote_db_name\";"; | |
ssh "$ssh_address" "mysql --host=\"$remote_db_host\" --user=\"$remote_db_user\" --password=\"$remote_db_pass\" \"$remote_db_name\" < \"$site_remote_path/upload/$dump_filename\";"; | |
ssh "$ssh_address" "rm $site_remote_path/upload/$dump_filename;"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment