Created
February 1, 2015 16:46
-
-
Save oterox/cb1cb78689ea59639142 to your computer and use it in GitHub Desktop.
Mirrors a WordPress Installation to another host
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
#!/bin/bash | |
# | |
# Description: | |
# Mirrors a WordPress Installation to another host, accessible through a mirror subdomain | |
# | |
# | |
# Assumptions: | |
# mysql and ssh usernames are the same | |
# databases are on the same server and accessible | |
LOCAL_USER="###" | |
REMOTE_USER="###" | |
LOCAL_DATABASE="###" | |
REMOTE_DATABASE="###" | |
MYSQL_LOCAL_PASS="###" | |
MYSQL_REMOTE_PASS="###" | |
MYSQL_DUMP="dump.txt" | |
HOST="###.###.###.###" | |
ROOT_DOMAIN="###" | |
ROOT_MIRROR_DOMAIN="mirror.###" | |
WP_LOCAL_ROOT="###" | |
WP_REMOTE_ROOT="###" | |
DOMAINS="$WP_LOCAL_ROOT/domains.txt" | |
echo "# Dropping local database" | |
echo "DROP DATABASE $LOCAL_DATABASE;" | mysql --user=$LOCAL_USER --password=$MYSQL_LOCAL_PASS | |
echo "# Dumping remote database" | |
mysqldump --all-databases -u $REMOTE_USER --password=$MYSQL_REMOTE_PASS --extended-insert=FALSE --complete-insert=TRUE > $WP_LOCAL_ROOT/$MYSQL_DUMP | |
echo "# Replacing usernames" | |
sed -i "s:$REMOTE_USER:$LOCAL_USER:g" $WP_LOCAL_ROOT/$MYSQL_DUMP | |
while read line | |
do | |
DOMAIN=$line | |
echo "# Replacing domain: $DOMAIN" | |
sed -i "s:$DOMAIN:mirror\.$DOMAIN:g" $WP_LOCAL_ROOT/$MYSQL_DUMP | |
done < $DOMAINS | |
echo "SED GURU" | |
echo "# Replacing serialized theme settings" | |
sed -r -e 's:[#$%\"`´]:\\&:g' -e 's:s\:([0-9]*)\:\\\\\\\"http\://([a-z.]*)mirror:s\:\$((\1+7))\:\\\\\\"http\://\2mirror:g' -e "s:.*:echo \"&\":e" -i $WP_LOCAL_ROOT/$MYSQL_DUMP | |
echo "# Importing modified dump" | |
mysql --user=$LOCAL_USER --password=$MYSQL_LOCAL_PASS < $WP_LOCAL_ROOT/$MYSQL_DUMP | |
rm $WP_LOCAL_ROOT/$MYSQL_DUMP | |
echo "# Syncing WordPress files" | |
rsync -az $REMOTE_USER@$HOST:$WP_REMOTE_ROOT/* $WP_LOCAL_ROOT/ | |
scp $REMOTE_USER@$HOST:$WP_REMOTE_ROOT/wp-config.php $WP_LOCAL_ROOT/ | |
echo "Replacing wp-config content" | |
sed -i -e "s:$REMOTE_USER:$LOCAL_USER:g" -e "s:$MYSQL_REMOTE_PASS:$MYSQL_LOCAL_PASS:g" -e "s:$ROOT_DOMAIN:$ROOT_MIRROR_DOMAIN:g" $WP_LOCAL_ROOT/wp-config.php | |
echo "# LOL" | |
rm -f sed* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment