Creating and managing on-demand and automatic backups

This page describes how to schedule and disable 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

Note: On-demand backups are available only for Second Generation instances.

To create an on-demand backup:

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.

    Go to the Cloud SQL Instances page

  2. Click the instance to open its Overview page.
  3. Click the Backups tab.
  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.

REST

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

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

HTTP method and URL:

POST https://www.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. Go to the Cloud SQL Instances page in the Google Cloud Console.

    Go to the Cloud SQL Instances page

  2. Select the instance for which you want to configure backups.
  3. Click Edit.
  4. In the Auto backups section, select Automate backups, and choose a backup window.
  5. 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]
    Under backupConfiguration you should see enabled: true and the time that you specified.

REST

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

  • project-id: The project ID
  • instance-id: The instance ID
  • start-time The time in the format "HH:MM"

HTTP method and URL:

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

Request JSON body:

{
  "settings":
  {
    "backupConfiguration":
    {
      "startTime": "start-time",
      "enabled": true,
      "pointInTimeEnabled": 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.

Disabling automated backups

To disable automated backups for an instance:

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.

    Go to the Cloud SQL Instances page

  2. Select the instance for which you want to disable backups.
  3. Click Edit.
  4. In the Auto backups section, uncheck Automate backups.
  5. Click Save.

gcloud

Edit the instance to disable backups:

gcloud sql instances patch [INSTANCE_NAME] --no-backup

REST

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

  • project-id: The project ID
  • instance-id: The instance ID
  • start-time The time in the format "HH:MM"

HTTP method and URL:

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

Request JSON body:

{
  "settings":
  {
    "backupConfiguration":
    {
      "startTime": "start-time",
      "enabled": false,
      "pointInTimeEnabled": false
    }
  }
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Setting and viewing a custom location for backups

Currently, you can only use the API to set custom locations for backups.

 

REST

To set the backup location for automated backups for an existing instance, use the instances settings.backupConfiguration.location parameter:

Before using any of the request data below, 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://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id

Request JSON body:

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

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

To set the backup location for on-demand backups, use the backupRuns location parameter:

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

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

HTTP method and URL:

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

Request JSON body:

{
  "location": "path",
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

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

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

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

HTTP method and URL:

GET https://www.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_REGION is the region where you want Cloud SQL to store the backup. For a complete list of valid region values, see the Instance locations.

Viewing backups

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

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.

    Go to the Cloud SQL Instances page

  2. Click the instance to open its Overview page.
  3. To view the recent backups, see the Operations page.

gcloud

  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

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 below, make the following replacements:

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

HTTP method and URL:

GET https://www.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:

Deleting a backup

You can delete automated and on-demand backups.

For Second Generation instances, deleting a backup might not free up as much space as the size of the backup. This is because Second Generation 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 (2nd Gen)

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.

    Go to the Cloud SQL Instances page

  2. Click the instance to open its Overview page.
  3. Click the Backups tab.
    The list of existing backups is displayed.
  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 text box and click Delete.

Console (1st Gen)

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.

    Go to the Cloud SQL Instances page

  2. Click the instance to open its Overview page.
  3. To view the recent backups, see the Operations page.
  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 text box 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

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

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

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

    HTTP method and URL:

    GET https://www.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 below, 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://www.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:

What's next

* See how to perform a point-in-time recovery.