Database syncing

What opinions are there for database syncing?

The obvious one is wp db migrate pro. Is there any others I would like to work in the command line since I’m already there.

Seems like the only thing missing.

Thanks

Trellis uses wp cli and you can export the database with wp db export command. Works same with import after you deploy.

So I would vagrant ssh in order to export the database? Is there a guide that you know of to show examples of steps involved?

Thank you!

https://wp-cli.org/commands/db/

You can also use the forum’s search feature to read threads that have already addressed this :thumbsup:

And Migrate DB pro also has WP Cli Addon in case you’d prefer that, here’s a nice video showing it - https://deliciousbrains.com/wp-migrate-db-pro/doc/cli-addon/

1 Like

I’ve written up how you can use WP-CLI and SCP/rsync to keep production and staging in sync here:

4 Likes

Thank you all for the information. Couple options to consider and best workflow I’ll have to consider.

WP Migrate DB is better but I’ve made this based on roots/bedrock-capistrano and lavmeiker/capistrano-wpcli. Take a look and tell me what you think. :smile:

1 Like

Related tool:

1 Like

I use the following, with WP-CLI aliases (see above):

# export production alias to local
wp db export \ # backup the local database
&& wp db reset \ # optional - create a blank slate
&& wp @production db export - | wp db import - \ # export the production database and pipe it into our local database
&& wp search-replace '//production-url.com' '//local-url.test' --skip-columns=guid --report-changed-only \
&& wp cache flush
# export local db to staging alias
wp @staging db export \ # backup the staging database
&& wp @staging db reset \ # optional - create a blank slate on staging
&& wp db export - | wp @staging db import - \ # export the local database and pipe it into our staging database
&& wp @staging search-replace '//local-url.test' '//staging-url.com' --skip-columns=guid --report-changed-only \
&& wp @staging cache flush

Use inside vagrant ssh if using trellis, or create a @dev alias for vagrant

I have these commands set up in composer scripts. I use rsync for the uploads directory.

I’d like to incorporate this into Trellis but ansible scares me.

6 Likes