Skip to content

Instantly share code, notes, and snippets.

@thecancerus
Last active April 25, 2019 07:49
Show Gist options
  • Save thecancerus/431d77baf8ff5d866fa0e6aa14150b03 to your computer and use it in GitHub Desktop.
Save thecancerus/431d77baf8ff5d866fa0e6aa14150b03 to your computer and use it in GitHub Desktop.
prod-to-test.sh
#!/usr/bin/env bash
# Back up Script to Amazon S3
# Source:
# Author: Amit
DATE=$(date +%Y%m%d%H%M)
LOGFILE=/var/log/prod-restore/$DATE.log
EMAIL=''
mkdir -p /var/log/prod-restore
touch $LOGFILE
#rsync code
rsync -a [email protected]:/var/www/xyz.net/htdocs/ /var/www/test.xyz.net/htdocs/
#rsync db
rsync -a [email protected]:/var/www/xyz.net/db/ /var/www/test.xyz.net/db/
#import db
gunzip /var/www/test.xyz.net/db/xyz_net.sql.gz
mysql test_walnutedu_net < /var/www/test.xyz.net/db/xyz_net.sql
rm /var/www/test.xyz.net/db/xyz_net.sql
#run search-replace
wp search-replace 'https://xyz.net' 'http://test.xyz.net' --skip-columns=guid --allow-root --path='/var/www/test.xyz.net/htdocs/'
wp db query 'UPDATE `wp_postmeta` SET `meta_value` = "[email protected]" WHERE `wp_postmeta`.`meta_key` = "father_email_address"' --allow-root --path='/var/www/test.xyz.net/htdocs/'
wp db query 'UPDATE `wp_postmeta` SET `meta_value` = "[email protected]" WHERE `wp_postmeta`.`meta_key` = "mother_email_address"' --allow-root --path='/var/www/test.xyz.net/htdocs/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment