Overview of backups

This page describes how backups of your Cloud SQL instance work.

For step-by-step directions for scheduling backups or creating an on-demand backup, see Creating and Managing On-Demand and Automatic Backups.

For an overview of how to restore data to an instance from the backup, see Overview of restoring an instance.

What backups provide

Backups help you restore lost data to your Cloud SQL instance. Additionally, if an instance is having a problem, you can restore it to a previous state by using the backup to overwrite it. Enable automated backups for any instance that contains necessary data. Backups protect your data from loss or damage.

What backups cost

By default, for each instance, Cloud SQL retains seven automated backups, in addition to all on-demand backups. You can configure how many automated backups to retain. We charge a lower rate for backup storage than for other types of instances. You can retain more, but not less than seven automated backups.

See the pricing page for more information.

Backups versus exports

Backups are managed by Cloud SQL according to retention policies, and are stored separately from the Cloud SQL instance. Cloud SQL backups differ from an export uploaded to Cloud Storage, where you manage the lifecycle. Backups encompass the entire database. Exports can select specific contents.

Backup and restore operations can't be used to upgrade a database to a later version. You can only restore from a backup to an instance with the same database version.

To upgrade to a later version, you can export and then import your database to a new Cloud SQL instance.

About backup size

Cloud SQL backups are incremental. They contain only data that changed after the previous backup was taken. Your oldest backup is a similar size to your database, but the sizes of subsequent backups depend on the rate of change of your data. When the oldest backup is deleted, the size of the next oldest backup increases so that a full backup still exists.

Types of backups

Cloud SQL performs two types of backups:

On-demand backups

You can create a backup at any time. This could be useful if you are about to perform a risky operation on your database, or if you need a backup and you do not want to wait for the backup window. You can create on-demand backups for any instance, whether the instance has automatic backups enabled or not.

On-demand backups are not automatically deleted the way automated backups are. They persist until you delete them or until their instance is deleted. Because they are not automatically deleted, on-demand backups can have a long-term effect on your billing charges.

To view the status of an on-demand backup operation:

  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.
  1. Use the REST operations.list API call to get the operation ID
  2. Use the REST operations.get API call to get the operation's status.

Automated backups

Automated backups use a 4-hour backup window. The backup starts during the backup window. When possible, schedule backups when your instance has the least activity.

During the backup window, automated backups occur every day your instance is running. One additional automated backup is taken after your instance is stopped to safeguard all changes prior to the instance stopping. Up to seven most recent backups are retained, by default. Automated backups are halted if your instance has been stopped for more than 36 hours. You can configure how many automated backups to retain, but you can't retain fewer than the default (seven).

Where backups are stored

Backups locations include:

  • Default locations that Cloud SQL selects, based on the location of the original instance.
  • Custom locations that you choose when you do not want to use the default location.

Default backup locations

If you do not specify a storage location, your backups are stored in the multiregion that is geographically closest to the location of your Cloud SQL instance. For example, if your Cloud SQL instance is in us-central1, your backups are stored in the us multi-region by default. However, a default location like australia-southeast1 is outside of a multi-region. The closest multi-region is asia.

Custom backup locations

Cloud SQL lets you select a custom location for your backup data. This is useful if your organization needs to comply with data residency regulations that require you to keep your backups within a specific geographic boundary. If your organization has this type of requirement, it probably uses a Resource Location Restriction organizational policy. With this policy, when you try to use a geographic location that does not comply with the policy, you see an alert on the Backups page. If you see this alert, you need to change the backup location to a location the policy allows.

For a complete list of valid regional values, see Instance Locations. For a complete list of multi-regional values, see Multi-regional locations.

See Setting a custom location for backups and Viewing locations for backups.

Automated backup retention

Automated backup retention can be set to more, but not less than the default (seven).

See Setting automated backup retention.

Can I export a backup?

No, you can't export a backup. You can only export instance data. See Exporting data from Cloud SQL.

About the special backup user

Cloud SQL creates a special database user, cloudsqladmin, for each instance, and generates a unique instance-specific password for it. Cloud SQL logs in as the cloudsqladmin user to perform automated backups.

How backups affect instance operations

Writes and other operations are unaffected by backup operations.


Click the links in the table for details:

For this problem... The issue might be... Try this...
Can't see current operation status. The user interface only shows success or failure. Use these database commands to find out more.
Can't find the operation originator. The user interface doesn't show who started an operation. Use audit logging to find out.
Out of disk space during automated backup. Instance reached hard disk space limits. Check the file system size and quota.
Can't do backup after instance deleted. Instance was deleted. Recreate from an export, or contact customer support if within the grace period.
Automated backup seems stuck. Backup time is correlated with database size. Contact customer support if you really need to cancel the operation.
Restore fails. Dump file may contain database users who do not yet exist. Create the database users before restoring.
Operation isn't valid for this instance. Destination instance size is smaller than the source. Increase the destination instance size.
Increase number of days to keep automated backups. Only seven automated backups are retained. Manage your own manual backups.
Unknown error in backup failure. Backup might have timed out. Check these flags.
No notification about backup failure. Notifications are not supported for backup failures. Use REST API or gcloud commands to check the status of a backup.

Can't see current operation status

You can't see the status of an operation in the Google Cloud Console.

The issue might be

The Google Cloud Console reports only success or failure when done, and is not designed to return warnings.

Things to try

Connect to the database and run SHOW WARNINGS.

Can't find the operation originator

You want to find out who issued an on-demand backup operation.

The issue might be

The instance operations page in the Google Cloud Console does not show who initiated an operation.

Things to try

Look in the logs and filter by text to find the user. You may need to use audit logs for private information. Relevant log files include:

  • cloudsql.googleapis.com/sqlagent.out
  • cloudsql.googleapis.com/sqlserver.err
  • cloudaudit.googleapis.com/activity may also be available, if Cloud Audit Logs is enabled.

Can't do backup after instance deleted

You can't do a backup after deleting the instance.

The issue might be

Instance was deleted.

Things to try

  • The grace period for a Cloud SQL instance purge is four days. During this time, customer support can recreate the instance. After instances are purged, no data recovery is possible.
  • If you have done an export, you can create a new instance and then do an import to recreate the database. Exports are written to Cloud Storage and imports are read from there.

Automated backup is stuck

Automated backup is stuck for many hours and can't be canceled.

The issue might be

Backups can take a long time depending on the database size.

Things to try

If you really need to cancel the operation, you can ask customer support to force restart the instance.

Restore from backup fails

A restore operation can fail when one or more users referenced in the SQL dump file do not exist.

The issue might be

Before restoring a SQL dump, all the database users who own objects or were granted permissions on objects in the dumped database must exist. If they do not, the restore fails to recreate the objects with the original ownership and/or permissions.

Things to try

Create the database users before restoring from the SQL dump.

Operation isn't valid for this instance

You see the error message HTTP Error 400: This operation isn't valid for this instance from an API call to instances.restoreBackup.

The issue might be

You cannot restore from a backup of an instance with a storage size (XX GB) that is smaller than the backup size (YY GB).

Things to try

Edit the target instance to increase its storage size.

Increase number of days to keep automated backups

You want to increase the number of days that you can keep automatic backups from seven to 30 days, or longer.

The issue might be

Only seven backups are retained. Backups get pruned regularly due to the cost and size of retaining backups. Unfortunately, this means that the currently visible backups are the only automated backups you can restore from.

Things to try

To keep backups indefinitely, you can create an on-demand backup yourself, as they are not deleted in the same way as automated backups. On-demand backups remain indefinitely. That is, they remain until they are deleted or the instance they belong to gets deleted. Since that type of backup is not deleted automatically, it can affect billing.

Unknown error in backup failure

Backup failed and you see Unknown error.

The issue might be

The backup creation reaching the timeout.

Things to try

There are two flags that influence the backup creation: checkpoint_timeout and checkpoint_completion_target. At the start of the backup, a slow checkpoint is run and it takes checkpoint_completion_target multiplied by checkpoint_timeout.

For example, 900 sec * 0.9 sec = 810 sec = 13.5 min. For this reason, a timeout occurs. Decreasing the value of the checkpoint_completion_target fixes the issue in this case.

No notification about backup failure

An automated backup failed and you didn't receive an email notification.

The issue might be

Notifications are not supported for backup failures.

When an automated backup fails, an Operation error message appears in the Cloud SQL instance's Details page.

Things to try

You can find the status of a backup through either the REST API or gcloud commands. For example, first list the backups for an instance, and then describe a specific backup by its ID:

gcloud sql --project=PROJECT_ID backups list --instance=INSTANCE_ID
gcloud sql --project=PROJECT_ID backups describe BACKUP-ID --instance=INSTANCE_ID

What's next