It happens from time to time when you need to copy a wordpress installation to a new domain. Let’s say you want to move your wordpress blog from olddomain.com to newdomain.com there are several ways to do so. You can use plugins, XML exports, but I found the simplest way to do so is to manually update the database.
Now here is a bash script I’ve made that will migrate your wordpress from one domain to another. Note that it will create a backup for you in your home folder, but you should still backup your database before doing so. Problems could occur If you’re using strange plugins.
Note that this assumes you already have copied the database to your need domain and all the worpress files. This script will replace in the database all instances of olddomain.com with newdomain.com.
#!/bin/bash #START VARS TO SET DBNAME='MY_BLOG_DB'; DBUSER='root'; DBPASS='very_sercure_pass'; OLDDOMAIN='olddomain.com'; NEWDOMAIN='newdomain.com'; #END VARS TO SET TODAY=`date +%Y-%m-%d.%s` #backup in home dir mysqldump -u $DBUSER --password=$DBPASS \ --databases $DBNAME > $HOME/${DBNAME}_${TODAY}.sql echo " UPDATE wp_options SET \ option_value = replace(option_value, '$OLDDOMAIN', '$NEWDOMAIN') \ WHERE option_value like '%$OLDDOMAIN%';\ \ UPDATE wp_posts SET guid = replace(guid, '$OLDDOMAIN','$NEWDOMAIN'), \ post_content = replace(post_content, '$OLDDOMAIN','$NEWDOMAIN'); " | mysql -u $DBUSER --password=$DBPASS $DBNAME
Hope this helps.