civicrm / cv

CiviCRM CLI Utility
28 stars 30 forks source link

Suggestion: Database backup? #198

Open timatidg opened 5 months ago

timatidg commented 5 months ago

I take advantage of the wonderful CV commands available when doing an CiviCRM upgrade, but I don't know of any way to use the command line to read the database information from settings.php and back up the mySQL database. (I have to update a whole bunch of sites and, if this existed, it would mean I would not have to look up each site's details manually, but could just use the same command on all sites.)

I researched if this feature exists anywhere, and I can't find anything. I wish I had the skills to code it and help, but I don't.

colemanw commented 5 months ago

Sorry this command doesn't currently exist. You may be interested to follow this discussion: https://lab.civicrm.org/dev/core/-/issues/5277

MegaphoneJon commented 5 months ago

This conversation may be more relevant: https://github.com/civicrm/cv/pull/191

There's lots of times to backup a db that aren't related to portability - e.g. I back up the db before an upgrade.

My MySQL credentials are stored in a pass repo that my Ansible uses for lookup. But you could use cv vars:show and jq to do this:

PASS=`cv vars:show | jq -r '.["CIVI_DB_PASS"]'`; USER=`cv vars:show | jq -r '.["CIVI_DB_USER"]'`; NAME=`cv vars:show | jq -r '.["CIVI_DB_NAME"]'`; mysqldump -u$USER -p$PASS $NAME > backup.sql