Managing Instance Backups

This page describes how to use Cloud Tools for PowerShell to manage data backups. Assuming you've enabled automatic backups in an instance’s settings, you can use Cloud Tools for PowerShell to do periodic, automatic backups of data in the form of a backup run. Note that this backup is not the same as replication of data. In the event of database corruption, the database can be restored to a backup and any bad backups can be deleted.

Reverting to a Backup

A backup for an instance can be restored in order to revert to a prior set of data. This is useful if something goes wrong during the data submission process. The restoration will be automatically propagated into any replica instances.

The following code snippet restores the most recent backup run for the instance gootoso:

# Restore to the last backup run
$backup = Get-GcSqlInstanceBackup "gootoso" | Select-Object -first 1
Restore-GcSqlInstanceBackup $backup.Id "gootoso"

To learn more about backups and restoring from them, see Overview of Backups and Overview of Restoring an Instance.

Removing Backup Runs

Cloud SQL retains up to seven backup runs for each instance. Second generation instance backups take up the regular amount of storage space but are billed at a reduced rate. If a particular backup run is no longer needed for an instance, it may be a good idea to remove it.

See pricing for more information.

The following snippet removes the backup run with ID 203948 from the instance gootoso:

Remove-GcSqlBackupRun "gootoso" 203948

You can use Get-GcSqlBackupRun to list backup runs. For example, this snippet lists backup runs for the instance "gootoso":

Get-GcSqlBackupRun "gootoso"