Please check out my new repository mandrasch/ddev-pull-wp-scripts for the latest version of this script. The command is now called ‚ddev pull backup‘.
The open source developer tool DDEV recently updated its providers / pull integration. You can now finetune the import behavior and overwrite all steps, e.g. the files_import_command. This offers an amazing developer experience for import scripts. (I already worked with DDEV custom commands before, but the new providers integration enables a more robust way of using and sharing these import steps.)
I made a quick script demonstrating the import of a backup file created with the open source plugin BackWPup, check it out here: mandrasch/ddev-pull-backwpupfile. Please make sure you update to DDEV 1.18.2 before using the following steps, see DDEV update instructions for more information.
1. Install BackWPup plugin and create a backup job
Install the BackWPup plugin and create a new backup job after plugin activation on your live site. You can use the standard settings, just set job destination to „Backup to folder“ (see second screenshot).
2. Run the backup job and download the backup
3. Rename the backup
Rename the downloaded backup file to backup.zip
4. Clone or Fork the ddev-pull-backwpupfile repository
Clone or fork the repository via „Use this template“ on GitHub:
Clone / check out this repository on your local harddrive.
5. Set up the ddev project
Go to the cloned folder on your local laptop and run the following terminal commands:
- ddev config –project-type=wordpress
- ddev start
6. Move the backup.zip to the project folder
Move the previously downloaded backup zip file to your cloned project folder.
7. Import the backup
Just run the following command which will import the database and wordpress files from backup. This will take care of replacing the URLs in database as well (migration):
- ddev pull backwpupfile
(This will run the steps defined in .ddev/providers/backwpupfile.yaml. You could add more WPCLI commands here as well since DDEV has built-in WPCLI support)
8. You’re done!
- ddev launch
to open the website in your browser. You can now safely try out theme changes, plugin and wordpress updates locally in your DDEV project.
Optional – Use WP Pusher:
You can use the WordPress plugin wppusher.com to git-control themes or plugins, e.g. your child theme. The repository already contains a child theme for the twentytwentyone theme. This can be added to your wordpress site the following way:
The providers script only imports files and directories which are not tracked by git. Therefore the twentytwentyone-child is not overwritten when you run ddev pull backwpupfile. (The sync behavior is based on .gitignore settings, rsync is called with –include-from=‘.gitignore‘ –exclude=’*‘. See .gitignore for details on how to git track a child theme).
If you update your child theme in the repository, you can update it via WP admin dashboard (or setup push-to-deploy via webhooks)
Optional note on SSH:
If your webhost offers SSH, rsync and mysqldump access, there are more professional workflows possible. But using a manually downloaded backup file from BackWPUp enables you to use this workflow for almost all webhosts. If I find the time I’ll provide an rsync example for WordPress as well – or maybe someone else will implement this, happy to share it here then. 😉 For first steps see rsync.yaml.example and database syncing tipps without storing passwords locally (drud/ddev/discussions/2940#discussioncomment-1665163).
Update January 2022: See https://github.com/mandrasch/ddev-wp-groundstation for a rsync/ssh workflow.
I’m excited seeing more adoption of this DDEV feature in future!
See also my former blog post with more details about DDEV and WordPress https://matthias-andrasch.eu/blog/2021/ddev-wordpress-cli-clone-a-live-site-to-your-local-laptop/ (slightly outdated now).
If you want to start fresh, see the DDEV WordPress quick start: https://ddev.readthedocs.io/en/stable/users/cli-usage/#wordpress-quickstart