This page describes how backups of your Cloud SQL instance work. It explains how you can use backups to restore your data to the same or another instance.
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 Restore from a backup.
What backups provide
Backups help you restore lost data to your Cloud SQL instance. You can also restore an instance that is having problems from a backup. Enable automated backups for any instance that contains necessary data. Backups protect your data from loss or damage.
Enabling automated backups, along with binary logging, is also required for some operations, such as clone and replica creation.What backups cost
By default Cloud SQL retains 7 days of automated backups, plus all on-demand backups, for an instance. You can configure how many automated backups to retain. We charge a lower rate for backup storage than for other types of instances.
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.
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 if you do not delete them.
To view the status of an on-demand backup operation:
- Use the
gcloud sql operations list
command to get the operation ID - Use the
gcloud sql operations describe
command to get the operation's status.
- Use the REST
operations.list
API call to get the operation ID - 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.
Automated backups occur every day when your instance was running at any time in the past 36 hours and by default up to seven most recent backups are retained. You can configure how many automated backups to retain, from one to 365.
Automated backups are halted if your instance has been stopped for more than 36 hours. Backup and transaction log retention values can be changed from the default setting. Learn more.
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 multi-region 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 and transaction log retention
Automated backups are used to restore a Cloud SQL instance. A combination of automated backups and transaction logs are used to perform a point-in-time recovery.
While transaction logs are counted in days, automated backups are not guaranteed to occur on a day boundary. Different units are used for these retention settings. Automated backup retention is a count and can be set from one to 365 backups. Transaction log retention is in days and can be set from one to seven. The default value for both is seven.
The lower bounds are useful for test instances, because logs and backups are deleted faster. For transaction logs, disk size doesn't grow as much with lower bounds. Using the higher values for automated backups retention let you restore from further back in time.
See Setting automated backup retention.
See Setting transaction log 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
For MySQL instances, the FLUSH TABLES WITH READ LOCK
flag is not
used for backups. This means that writes and other operations are unaffected
by backup operations.
Typically, backups complete within a few seconds, but if a large amount of data has been written since the last backup, the backup takes longer to complete.
If there is a pending operation at the time of the backup attempt, Cloud SQL usually makes several attempts within the window to complete the backup. Operations that block backup are long-running Cloud SQL instance operations such as import, export, update (for example, an instance metadata change), and instance restart.
During a long-running operation, such as loading data, you can temporarily disable automated backups.
Troubleshooting
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.googlapis.com/mysql-general.log
- cloudsql.googleapis.com/mysql.err
- cloudaudit.googleapis.com/activity may also be available, if Cloud Audit Logs is enabled.
Out of disk space during automated backup
You see the error message [ERROR] InnoDB: Write to file ./ibtmp1 failed at
offset XXXX, YYYY bytes should have been written, only 0 were written.
The issue might be
The instance reached a hard limit during an automated backup. Temporary files can expand beyond available disk space during a backup.
Things to try
Check that the disk is not full or out of disk quota. You can either manually increase the disk size or enable auto storage increase.
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 ten minute timeout. There is a ten minute timeout set on the automated backup, and the backup is supposed to finish in that time.
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