DDEV provides a snapshot command for taking and restoring database snapshots.
By default it generates a snapshot name based on your project name and timestamp.
When you work with multiple git branches (who doesn't?) and frequently need to revert to a previous project state, it can become hard to track which database snapshot relates to which version of your codebase.
This little bash script makes snapshots with a name based on:
- the current git branch
- the current (latest) git commit hash
- the current timestamp
- an optional message to provide more info
Usage example:
./snapshot.sh -m "before D11 core upgrade"Output:
Creating database snapshot 2026-08-12-144610_main_98abe3c2_before_D11_core_upgrade
Created database snapshot 2026-08-12-144610_main_98abe3c2_before_D11_core_upgrade
Restore this snapshot with 'ddev snapshot restore 2026-08-12-144610_main_98abe3c2_before_D11_core_upgrade'
The script is available as a Gitlab snippet: https://gitlab.com/-/snippets/6029816: