Migrating data between local and development server

The question:

I’ve been working away at a medium-size WordPress site. So far I’ve just been hosting the site on my local machine and showing it to internal consultants over our local network. Things are working well, and now it’s time to show it off to the client. I’ve been using git all along, so pushing it to the dev server was a breeze. I duplicated the local DB and pushed it to the dev server manually, which was fairly easy except that I had to manually change a few URL entries.

Now my question is: what’s the best way to keep two instances of WordPress synced? I still have more work to do locally and the DB is going to need to get pushed up again. How do other people manage this in an automated way?

One thought I had was to write a git hook to pull the MySQL data down when I push from my local machine and have a hook on the other end to import the data when the dev server pulls. However, if I do this I’ll have to worry about changes to the wp_options table.

Does anyone have any strategies for making this sort of thing easy?

Thanks!

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

Assuming your wp-config.php is already in place and in order:

  • Step 1. Mysqldump your development database
  • Step 2. Replace all instances of development.domain.com to production.domain.com^^
  • Step 3. Login to MySQL, run a SOURCE command to import data e.g. source /path/to/file

^^ How to replace all instances of old domain with new: (1) Copy the script below. (2) chmod +x it. (3) Run it.

Usage: ./script.sh development-dump.sql > production-dump.sql

#!/bin/sed -f
s/'([^\']*)development.domain.com([^\']*)'/'1production.domain.com2'/g

Method 2

This has been discussed a few times so I’d suggest going over these threads then asking about any gaps you still see.

What process do you use for WordPress development?

How to: Easily Move a WordPress Install from Development to Production?

Ultimately keeping the database in sync is the issue most struggle with. I simply don’t really worry about it. I’ll import some posts/CPT’s if we have a new content type but that’s about it the rest I do manually.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment