Create On-Demand & Automatic Backups of Cloud SQL Instances
Ensure data safety by backing up your Cloud SQL instances. This guide shows you how to create both manual and automatic Cloud SQL backups.
Ensure data safety by backing up your Cloud SQL instances. This guide shows you how to create both manual and automatic Cloud SQL backups.
If you have a good backup strategy, you can easily restore data if your GCP Cloud SQL instances start having issues. Unlike exports (another restoration option), Cloud SQL backups cover the entire database and are managed by Cloud SQL.
You can create Cloud SQL backups automatically if it is important that you have up-to-date data according to your business needs and required point-in-time recovery (PITR), or you can create backups on-demand with a manual process.
In this guide, we’ll show you how to create backups manually and how to schedule automatic backups for your Cloud SQL instances.
Manual backups are a good practice ahead of performing any kind of risky operation on your database. For example, maybe you are about to migrate database schema.
Instead of waiting for the backup window to capture an automatic backup, you can create an on-demand backup so if the operation goes poorly, you don’t risk losing any data. You can also create on-demand backups if automatic backups are not enabled and it’s been a long time since your last backup for that instance.
Create the backup in the gCloud CLI using the following command:
You can include --async if the next operation you are running is low risk, and it is a way of allowing your backup to be created in the background while you run other operations. You might not want to include --async if the next operation is risky since your backup might not complete in time.
By default, backups are created in the location of the original instance. To change the desired location for your backup, you can specify it with a parameter:
And just like that, you’ve created a backup of your specific Cloud SQL instance in a specific location. Now, we’ll look at scheduling your backup creation.
Automated backups are a good way to ensure that you always have a recent backup you can use to restore a failing instance.
To schedule automatic backups, you need to set a daily 4-hour window when your instance is least active. The automatic backup process will start at some point during that window.
Keep in mind that the backup-start-time uses a 24-hour format and is based in the UTC time zone. Furthermore, the start time is when the 4-hour-long backup window will begin, and the backups can start at any moment within the 4-hour window. You need to edit the instance to have a specific backup start time like so:
For example, let's say you have a Cloud SQL instance named "DOG" and you wanted to set the back-up-start-time to 1:30 UTC. Your input into the gcloud CLI would be:
After this, you must confirm the changes you have made. Ensure that you have set the correct backup start time for the correct instance like so:
You can confirm these changes when checking the backupConfiguration section. Make sure that you can see enabled: true along with the backup start time that you specified. This will mean your automated backups have now been scheduled to the time parameters you chose.
Creating or scheduling Cloud SQL backups only takes a few steps, so you can do it manually if you want to.
However, conducting these steps does require context-switching and you either create a backup right away or create them on a regular schedule. What if you want to create backups as a step in a workflow, or only create them under certain conditions?
With Blink, you can create a simple automation like this one that follows these steps above so creating a backup is always a click away.
This automation in the Blink library runs the following steps:
You can embed this automation into workflows so you can ensure backups when they are most needed. This gives you flexibility to optimize your backup storage and customize your process.
Get started with Blink and streamline your Cloud SQL backup process today.
Blink is secure, decentralized, and cloud-native. Get modern cloud and security operations today.