0

I've made a custom command to my ddev, creating a database backup with a single command (yes, I'm lazy, sorry).

I was thinking if there's some way to hook a ddev command, e.g. ddev poweroff to run another command or command sequence together.

The idea is to make a backup of all databases in a specific directory when I run the ddev poweroff.

Anyone have a clue about it?

Thanks

rfay
  • 9,963
  • 1
  • 47
  • 89

1 Answers1

1

Sure, pre-stop exec-host hooks can invoke ddev directly. Here's an example of a pre-stop hook that does both a snapshot and a traditional db dump:

hooks:
  pre-stop:
    - exec-host: ddev snapshot --name=$(date +%Y%m%d%H%M)
    - exec-host: mkdir -p .tarballs && ddev export-db --file=.tarballs/db.$(date +%Y%m%d%H%M).sql.gz

For more info on hooks, see DDEV hook docs.

Hope that helps!

rfay
  • 9,963
  • 1
  • 47
  • 89