My team has a requirement that we be able to retrieve a backup of our database (hosted on Google Cloud SQL) and restore that database to a locally hosted instance of MySQL.
I know that Google Cloud SQL has the ability to schedule backups, but these don't appear to be available to download anywhere.
I also know that we are able to "export" our database to Google Cloud Storage, but we'd like to be able to schedule the "export".
The end goal here is to execute the following steps in some sort of an admin script:
Any ideas?
gcloud sdk commands now provide import/export functionality:
gcloud sql export sql <DATABASE_INSTANCE> \
gs://<CLOUD_STORAGE_BUCKET>/cloudsql/export.sql.gz \
--database <DATABASE_NAME>
This export can be downloaded using gsutil
. It can also be imported using mysqlimport
That's the problem I've encountered and my solution was:
sql-backuper
), download access key for it in JSONgcloud auth activate-service-account [email protected] --key-file /home/backuper/gcloud-service-account.json
(gcloud auth documentation)gcloud sql instances export [sql-instance-name] gs://[bucket-name]/[file-name].gz --database [your-db-name]
(gcloud sql documentation)
and
gsutil cp gs://[bucket-name]/[file-name].gz [local-file-name].gz
(gsutil cp documentation)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With