1
votes

I have a GAE project and for that to store the data i have used Cloud SQL database. I need to take on demand backup of my Cloud SQL database and the backup should be stored in google storage.

Can anyone help me to how can i do this programatically using JAVA?

1

1 Answers

3
votes

You cannot export a backup (on-demand or automated), as documented here. What you can do however is to export your data to a SQL dump file or a CSV file, depending on your use case, and store it on Cloud Storage.

There is no Java utility to perform an export but Google exposes an API endpoint for you to trigger an export. Here's an example request using standard curl tool:

curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
     --header 'Content-Type: application/json' \
     --data '{"exportContext":
                {"fileType": "SQL",
                 "uri": "gs://<BUCKET_NAME>/<PATH_TO_DUMP_FILE>",
                 "databases": ["<DATABASE_NAME1>", "<DATABASE_NAME2>"] }}' \
   -X POST \
   https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/export

You'll find further details about exporting data in the documentation here.