Creating and managing on-demand and automatic backups

This page describes how to schedule and turn off automatic backups, create and manage on-demand backups, and view backups for your Cloud SQL instance.

For more information about how backups work, see Overview of backups.

Creating an on-demand backup

To create an on-demand backup:

Console

  1. In the Google Cloud Console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click the instance name to open its Overview page.
  3. Select Backups from the SQL navigation menu.
  4. Click Create backup.
  5. On the Create backup page, add a description, if needed, and click Create.

gcloud

Create the backup:

gcloud sql backups create \
--async \
--instance=INSTANCE_NAME

You can provide a description of the backup using the --description parameter.

To create a backup in a custom location:

gcloud sql backups create \
--async \
--instance=INSTANCE_NAME \
--location=BACKUP_LOCATION

REST v1

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

REST v1beta4

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Scheduling automated backups

To schedule automated backups for an instance:

Console

  1. In the Google Cloud Console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click the instance name to open its Overview page.
  3. Select Backups from the SQL navigation menu.
  4. Click Edit, next to Settings.
  5. Choose a window of time for your data to be automatically backed up.
  6. Click Save.

gcloud

  1. Edit the instance to specify a backup start time:
    gcloud sql instances patch INSTANCE_NAME --backup-start-time=HH:MM
    The `backup-start-time` parameter is specified in 24-hour time, in the UTC±00 time zone, and specifies the start of a 4-hour backup window. Backups can start any time during the backup window.
  2. Confirm your changes:
    gcloud sql instances describe INSTANCE_NAME
    In the backupConfiguration section, confirm that you see enabled: true and the time that you specified.

REST v1

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID (primary or replica)
  • start-time The time in the format "HH:MM"
  • enabled: Set to true for a primary instance. Set to false for a replica instance

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

Request JSON body:

{
  "settings":
  {
    "backupConfiguration":
    {
      "startTime": "start-time",
      "enabled": enabled,
      "binaryLogEnabled": true
    }
  }
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

You can enable binary logging at the same time by setting pointInTimeEnabled to true within the backupConfiguration object.

REST v1beta4

You can enable binary logging at the same time by setting binaryLogEnabled to true within the backupConfiguration object.

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID (primary or replica)
  • start-time The time in the format "HH:MM"
  • enabled: Set to true for a primary instance. Set to false for a replica instance

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

Request JSON body:

{
  "settings":
  {
    "backupConfiguration":
    {
      "startTime": "start-time",
      "enabled": enabled,
      "binaryLogEnabled": true
    }
  }
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Setting a custom location for backups

Only use a custom backup location if required by regulation. If not required, use the default multi-region backup location.

You can use a custom location for on-demand and automatic backups. For a complete list of valid location values, see the Instance locations.

To update an instance with a custom location:

Console

  1. In the Google Cloud Console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click the instance name to open its Overview page.
  3. Click Edit.
  4. In the Configuration options section, expand Backups.
  5. Expand Location options.
  6. Click Multi-region (default) or Region.
  7. Select the location from the Location drop-down menu.
  8. Click Save.

gcloud

For reference information, see gcloud sql instances patch.

gcloud sql instances patch INSTANCE_NAME \
--backup-location=BACKUP_LOCATION
  

REST v1

Use the instance's settings.backupConfiguration.location parameter for the backup location.

Before using any of the request data, make the following replacements:

  • region: The project region
  • backup-region: The backup region
  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

Request JSON body:

{
  "region": "region"
  "settings":
  {
    "backupConfiguration":
    {
      "location": "backup-region",
      "enabled": true,
    }
  }
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

REST v1beta4

Use the instance's settings.backupConfiguration.location parameter for the backup location.

Before using any of the request data, make the following replacements:

  • region: The project region
  • backup-region: The backup region
  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

Request JSON body:

{
  "region": "region"
  "settings":
  {
    "backupConfiguration":
    {
      "location": "backup-region",
      "enabled": true,
    }
  }
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Viewing a list of backups

To view a list of backups and details about a backup, use the following options.

The Cloud Console does not show skipped or failed backups in the backup history. To see skipped backups, use gcloud or the API.

Console

  1. In the Google Cloud Console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click the instance name to open its Overview page.
  3. Select Backups from the SQL navigation menu to view recent backups, along with creation time and type of backup..

gcloud

  • List the backups of the instance:
    gcloud sql backups list \
    --instance INSTANCE_NAME
    

    You can filter and control the results using the standard list parameters. For a complete list, see the gcloud sql backups list command reference page.

  • View the details of a backup by specifying the backup ID from the output of the backups list command.
    gcloud sql backups describe BACKUP_ID \
    --instance INSTANCE_NAME
        

REST v1

You can also use the APIs Explorer on the BackupRuns:list page to send the REST API request.

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

REST v1beta4

You can also use the APIs Explorer on the BackupRuns:list page to send the REST API request.

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Viewing a list of backups during an outage

When an instance is in a region that is having an outage, you can only view backups for that instance using a wildcard (-) with the backupRuns.list API. The wildcard returns all backups in the project. You can then restore the backup to a new or existing instance in a region that is not having an outage. See Restoring to a different instance.

gcloud

  1. List the backups for every instance in a project:
    gcloud sql backups list --instance -

    The command returns information similar to the following:

    {
          "kind": "sql#backupRun",
          "status": "SUCCESSFUL",
          "enqueuedTime": "2020-01-21T11:25:33.818Z",
          "id": "backup-id",
          "startTime": "2020-01-21T11:25:33.858Z",
          "endTime": "2020-01-21T11:26:18.663Z",
          "type": "AUTOMATED",
          "windowStartTime": "2020-01-21T10:00:00.479Z",
          "instance": "instance-id",
          "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns/backup-id",
          "location": "us"
          "backupKind": "SNAPSHOT"
        }
  2. Find the backup for the instance you need. To restore this backup, see Restoring to a different instance.

REST v1

  1. List all the backups in a project:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID, or - for a list of all backups in the project

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/v1beta4/projects/project-id/instances/-/backupRuns

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

  2. Find the backup for the instance you need. To restore this backup, see Restoring to a different instance.

REST v1beta4

  1. List all the backups in a project:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID, or - for a list of all backups in the project

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/v2/projects/project-id/instances/-/backupRuns

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

  2. Find the backup for the instance you need. To restore this backup, see Restoring to a different instance.

Viewing locations for backups

To see the locations of the backups taken for an instance, use backupRuns:

Console

  1. In the Google Cloud Console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click the instance name to open its Overview page.
  3. Select Backups from the SQL navigation menu.
  4. In the backups list, the Location column lists the type of location (multi-region or region) and the specific multi-region or region for each backup.

gcloud

For reference information, see gcloud sql instances describe.

  1. List the backups of the instance:
    gcloud sql backups list \
    --instance INSTANCE_NAME
    

    You can filter and control the results using the standard list parameters. For a complete list, see the gcloud sql backups list command reference page.

  2. To list the details of one backup, use the ID from the output of the backups list command.
    gcloud sql backups describe BACKUP_ID \
    --instance INSTANCE_NAME
    

REST v1

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

In the previous examples:
  • REGION is the region for the original instance.
  • BACKUP_LOCATION is the location where you want Cloud SQL to store the backup.
 

REST v1beta4

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

In the previous examples:
  • REGION is the region for the original instance.
  • BACKUP_LOCATION is the location where you want Cloud SQL to store the backup.

Setting automated backup retention

To set the number of automated backups to retain:

Console

  1. In the Google Cloud Console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click the instance name to open its Overview page.
  3. Select Backups from the SQL navigation menu.
  4. Click Edit.
  5. In the Automate backups section, expand Advanced options.
  6. Enter the Number of backups to store at a time.
  7. Click Save.

gcloud

Edit the instance to set the number of automated backups to retain. The number can't be less than the default (seven).

gcloud sql instances patch instance-name 
--retained-backups-count=num-to-retain

REST v1beta4

Before using any of the request data, make the following replacements:

  • unit: Optional: The retention unit can either be an integer or a string. The currently supported (and default) values are 1 or "COUNT".
  • num-to-retain: The number of automated backups to retain, from 1 to 365.
  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

Request JSON body:

{
  "settings":
  {
    "backupConfiguration":
    {
      "backupRetentionSettings":
      {
        "retentionUnit": unit,
        "retainedBackups": "num-to-retain"
      }
    }
  }
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Deleting a backup

You can delete automated and on-demand backups.

For MySQL instances, deleting a backup might not free up as much space as the size of the backup. This is because the backups are incremental, so deleting an older backup might transfer some of its contents to a more recent backup to preserve the integrity of the newer backup.

Console

  1. In the Google Cloud Console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click the instance name to open its Overview page.
  3. Select Backups from the SQL navigation menu.
  4. Click more actions More actions icon. for the backup you want to delete.
  5. Select Delete.
  6. In the Delete backup window, type Delete into the field and click Delete.

gcloud

Delete a backup of a Cloud SQL instance:

gcloud beta sql backups delete BACKUP_ID \
--instance INSTANCE_NAME
      

For a complete list of parameters, see the gcloud beta sql backups delete command reference page.

REST v1

  1. List the backups to obtain the ID for the backup you want to delete:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

  2. Delete the backup:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID
    • backup-id: The backup ID

    HTTP method and URL:

    DELETE https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/backupRuns/backup-id

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

REST v1beta4

  1. List the backups to obtain the ID for the backup you want to delete:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

  2. Delete the backup:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID
    • backup-id: The backup ID

    HTTP method and URL:

    DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns/backup-id

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

Disabling automated backups

To disable automated backups for an instance:

Console

  1. In the Google Cloud Console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. Click the instance name to open its Overview page.
  3. Select Backups from the SQL navigation menu.
  4. Click Manage automated backups
  5. Uncheck Automate backups.
  6. Click Save and restart.

gcloud

Edit the instance to disable backups:

gcloud sql instances patch INSTANCE_NAME 
--no-backup

REST v1

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id

Request JSON body:

{
  "settings":
  {
    "backupConfiguration":
    {
      "enabled": false,
      "binaryLogEnabled": false
    }
  }
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

REST v1beta4

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

Request JSON body:

{
  "settings":
  {
    "backupConfiguration":
    {
      "enabled": false,
      "binaryLogEnabled": false
    }
  }
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Point-in-time recovery

Learn more about point-in-time recovery.

What's next