Skip to content

Files

Latest commit

 

History

History

gcp_cloud_function_sql_export

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Google Cloud Function - SQL Backup Exporter to GCS

Triggers GCP Cloud SQL export backups to GCS.

Solution documentation:

https://cloud.google.com/solutions/scheduling-cloud-sql-database-exports-using-cloud-scheduler

  • main.py - the code
  • requirements.txt - the pip modules to bootstrap
  • deploy.sh - upload the code and deps

Upload the function to GCF in the current GCP project - this script will call gcloud functions deploy with the required switches:

./deploy.sh

Solution Dependencies

Serverless Framework

Instead of deploy.sh you can alternatively use the Serverless framework for which a serverless.yml config is provided:

serverless deploy

If this is your first time using Serverless then you'll need to install the GCP plugin:

serverless plugin install --name serverless-google-cloudfunctions

The serverless.yml config expects to find $GOOGLE_PROJECT_ID and $GOOGLE_REGION environment variables.

Serverless requires additional permissions for the service account: Deployment Manager Editor and Storage Admin to create deployments and staging buckets.

You can also build a serverless artifact to .serverless/ without deploying it (generates Google Deployment Manager templates and a zip file - useful to check what would be uploaded / ignored):

serverless package