jehna1
jehna1

Reputation: 3130

Is there a "correct" way to sync databases between live and dev servers?

I'm usually using git as the version control system to my WordPress code. But there's something missing from git. I can sync my project's files easily, but syncing databases is always a huge pain.

Is there a "correct" way to sync databases between live and dev servers?

I could include a database dump to the version control and update it every time, but that doesn't seem intuitive. Especially when in some cases WordPress tends to save information concerning the live server to the database.

P.S. I'm not talking about database structure, since there are ORM techniques for that, but the actual content of the pages.

Upvotes: 2

Views: 3287

Answers (3)

JP Lew
JP Lew

Reputation: 4469

you can try my script: https://github.com/jplew/SyncDB

SyncDB is bash deploy script meant to take the tedium out of synchronizing local and remote versions of a Wordpress site. It allows developers working in a local environment (eg. MAMP) to rapidly "push" or "pull" changes to or from their production server with a single terminal command.

I migrate content back and forth between live and dev constantly, so I reduced the process down to a single shell command:

./syncdb

Upvotes: 2

Jason McCreary
Jason McCreary

Reputation: 73031

Due to WordPress being a production-ready system, most data is stored environment specific. Fortunately, migrating the database is rarely required (i.e. only when launching the site).

You can do so with the following steps:

  • Export the source environment database
  • Import the database to the destination environment
  • Export the wp_posts table
  • Replace any environment specific URLs (i.e. dev.whatever.com with whatever.com)
  • Re-import the wp_posts table

Since most runtime configurations are in wp_config.php there's rarely a problem with the wp_options table. However, you can export it if you wish.

Note: This was taken from my article on Configuring WordPress for Multiple Environments.

There are also plugins that help with this process.

Upvotes: 0

invisal
invisal

Reputation: 11181

You can have a master-slave replication or master-master replication in MySQL.

Master-slave replication

  • The production server will be master server and the development server will be slave server. Master server will pass new data to slave server. However, if you make change at slave server, it will not update to production server.

Master-master replication

  • Setup both server as master, if production server changes, development server will change as well and vise versa.

Further reading

Upvotes: 1

Related Questions