0

I'm currently working on adding an extra step to our companies CI/CD pipeline so we make backups of the database before making a deployment that could potentially run migrations on our database.

To make the backup I authenticate with Google Cloud Platform using the command: gcloud auth activate-service-account --key-file /path/to/keyfile.json

After authenticating I use the command: gcloud sql backups create --async --instance instance_name

My question is about what the implications of adding the async flag are. I understand that doing so means my pipeline will not wait for the backup to be completed before moving on to the next step, however, if the next step involves running migrations that could potentially break something, does that mean that the backup I made in the previous step could end up in an in-between state where the migration has been partially ran?

How does Google actually handle backup creation? Do they make a snapshot of the database at that point in time and then make the backup from that? Would it be safer to remove the --async flag in order to ensure that the backup has been completed before running any potential migrations?

I've tried looking at the documentation but it doesn't really go into detail about this.

patrickdamery
  • 113
  • 1
  • 5

2 Answers2

0

We can know the status of backup process using these commands:-

  1. Use the gcloud sql operations list command to get the operation ID.

  2. Use the gcloud sql operations describe command to get the operation's status. For more details see here

For --async command refer google doc. It looks like the execution will return to other jobs, and backup will go on in background.

Krish
  • 120
  • 3
  • I take it that means that creating a backup with the --async flag means there would be no guarantee that the backup would not end up with a partial migration implemented. Opted for just running the migration without the --async flag. – patrickdamery Jun 11 '21 at 14:06
0

I think that for the snapshot purpose, it is best not to use --async, unless you are really sure that your next operation in the CI/CD would not interfere with the snapshot operation.

That said, I think the snapshot would be completed but the next operation, if it has something to do with the cloudsql instance or databases, will fail if it is ran at the same time while the snapshot is running.

Just, as an exemple: you can not export multiple databases via gcloud sql export sql simulatneously. You have to wait for the first run to complete, else the second execution will fail!

Hope this help!

Craft
  • 171
  • 1
  • 5