Skip to content

Instantly share code, notes, and snippets.

@lastguest
Forked from wookiecooking/development_server.sh
Created January 10, 2014 18:16
Show Gist options
  • Save lastguest/8359574 to your computer and use it in GitHub Desktop.
Save lastguest/8359574 to your computer and use it in GitHub Desktop.
#!/bin/sh
#current info
CUR_URL=development.server.com
CUR_DB_HOST=database_host
CUR_DB_NAME=database_name
CUR_DB_USER=database_user
CUR_DB_PASS=database_password
CUR_PATH=/path/to/site/
#new info
NEW_URL=production.server.com
NEW_DB_HOST=new_database_host
NEW_DB_NAME=new_database_name
NEW_DB_USER=new_database_user
NEW_DB_PASS=new_database_password
#make MySQL backup filename
BACKUPMYSQLFILE=mysqlbackup.sql
#Make zip file backup name
BACKUPFILE=siteexport.tgz
#export Database
mysqldump -h localhost -u $CUR_DB_USER -p$CUR_DB_PASS $CUR_DB_NAME > $CUR_PATH$BACKUPMYSQLFILE
#find and replace old URLs in SQL file
sed -i “s/${CUR_URL}/${NEW_URL}/g” $CUR_PATH$BACKUPMYSQLFILE
#find and replace old Database Info in wp-config.php file
sed -i.backup -e”s/define(‘DB_NAME’, ‘${CUR_DB_NAME}’);/define(‘DB_NAME’, ‘${NEW_DB_NAME}’);/g” -e”s/define(‘DB_USER’, ‘${CUR_DB_USER}’);/define(‘DB_USER’, ‘${NEW_DB_USER}’);/g” -e”s/define(‘DB_PASSWORD’, ‘${CUR_DB_PASS}’);/define(‘DB_PASSWORD’, ‘${NEW_DB_PASS}’);/g” -e”s/define(‘DB_HOST’, ‘${CUR_DB_HOST}’);/define(‘DB_HOST’, ‘${NEW_DB_HOST}’);/g” ${CUR_PATH}wp-config.php
#change to the directory of the site, zip it up and move it into the document root
cd ${CUR_PATH} && tar -czf ../${BACKUPFILE} .
mv ../$BACKUPFILE $CUR_PATH
#!/bin/sh
OLD_URL=http://someURL.com/
NEW_PATH=/path/to/site/
NEW_DB_HOST=some_host
NEW_DB_NAME=database_name
NEW_DB_USER=database_user_name
NEW_DB_PASS=database_password
#download and extract site backup zip file
wget {$OLD_URL}siteexport.tgz
tar -xsf siteexport.tgz -C {$NEW_PATH}
#import data into database
mysql -h {$NEW_DB_HOST} -D {$NEW_DB_NAME} -u {$NEW_DB_USER} -p’{$NEW_DB_PASS}’ < {$NEW_PATH}mysqlbackup.sql
#clean up files
rm {$NEW_PATH}siteexport.tgz
rm {$NEW_PATH}mysqlbackup.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment