Export WP database for import using WP-CLI on Vagrant Box

THE SHORT

Export

sudo mysqldump -u root -pPASSWORD DBNAME > filename.sql

Import

wp db import filename.sql


THE LONG

So this turns out to be very painless. The server dump is exactly what WP-CLI needs to import.

REMOTE

  1. sudo mkdir backup
    • Make a directory for the file.
  2. sudo chown -f -R ec2-user:group backup
    • Set permissions to the directory for my SSH user.
  3. cd backup
    • Enter the directoy
  4. Run sudo mysqldump -u root -pPASSWORD DBNAME > filename.sql
    • Initially I was getting permission errors and that was because my EC2-USER needed control of the output directory.

LOCAL

  1. Download filename.sql to my Vagrant folder
  2. vagrant ssh
    • into the box for WP-CLI access
  3. wp db import /vagrant/filename.sql
  4. wp search-replace old-site.com new-site.dev --test-run
    • Test the operation first
  5. wp search-replace old-site.com new-site.dev

NOTES

  • Make sure plugins and themes are in the correct directories
  • Any errors in your PHP code will break the WP-CLI since it loads WP
  • WP Codex recommends to not change the GUID. You can skip the GUID in search and replace with wp search-replace 'http://example.dev' 'http://example.com' --skip-columns=guid

Leave a Comment