WordPress Database Migration Bash Script
By: Wil Helser
I HATE migrating WordPress databases! Not that it’s hard or takes much time… just that it’s one of those mundane daily tasks that can pull me out of my zone if I’m not careful. So… I wrote a simple Bash script that will dump a WordPress database, update the URLs ( from local to production or staging, etc. ) and then push the dump to the new database. It’s not super sophisticated, but it gets the job done.
You can grab it on GitHub here …. The link is actually to a repo for my WordPress-related Bash scripts, but I’ve only written one so far. I have a few others that I use daily, but they’re written specifically for my particular set-up. I’m working on making them more flexible so they can be used on any system. I should have a few more up there in a few days.
Hope it helps a little!


By Ben Sequoia June 6, 2012 - 3:31 pm
Hello,
This looks like a great script for quickly migrating wordpress DBs on the shell. We were looking to build something just like this, and found your script.
One thing however: looking around on this topic, I discovered that people are saying that you cannot just simply find/replace the URLs (from local to prod. etc), because they are in serailzed strings. If the character lengths of local and prod are different, then things are going to break. The serialized string length needs to be updated as well.
This is mentioned here:
http://interconnectit.com/124/search-and-replace-for-wordpress-databases/
and here:
http://pluginbuddy.com/purchase/backupbuddy/
I might be wrong (and I’m not a shell script expert), but quickly looking at your script, it looks like it does not take this into account. What are your thoughts on maintaining serialized string length integrity?
Best,
Ben
By Wil Helser June 10, 2012 - 11:12 pm
Hi Ben! You’re right, my script doesn’t take that into account, thanks for sharing that information! I haven’t had a problem yet, but I’m still going to update my script. Thanks again for that information!