DDEV Database Backups

December 2022

DDEV Database Backups

I don't know how it happened but one day I lost the data in all my local databases. I was thankfully between projects but it was still devastating. Thankfully a few months ago I made the move to DDEV on wsl2 for my local development environment. I'm still learning all the fantastic configuration settings but in a classic RTFM moment I found their hooks. Hooks let you run tasks before or after the main command executes. This let's you automate setup tasks specific to your project.

I add the following to every DDEV project config.yaml file:

# take a db snapshot when stopping the site to ensure no accidental data loss
# to restore a snapshot use 'ddev snapshot restore' and follow the prompts
 - exec-host: "ddev snapshot --cleanup -y"
 - exec-host: "ddev snapshot"

And every time I run ddev stop this hook will delete all existing snapshots and create a new one. I'm never losing my local data again!