Manage final backups

MySQL  |  PostgreSQL  |  SQL Server

This page describes how to managefinal backups for your Cloud SQL instance. Before youdelete an instance, you can take a final backup of the instance. You can then restore the final backup to a new or existing instance. This way, you can recreate any instances that you delete accidentally or use these instances for any disaster recovery scenarios.

Unlike automated and on-demand backups, which are associated with an instance, you can take a final backup before you delete the instance. Cloud SQL stores this backup beyond the lifetime of the instance.

You can use existinggcloud CLI commands to list, describe, update, and delete a final backup. If you're using custom roles, then add the following permissions to the roles:

  • cloudsql.backupRuns.list
  • cloudsql.backupRuns.get
  • cloudsql.backupRuns.update
  • cloudsql.backupRuns.delete

For more information about these permissions, seeRequired permissions. Also, for more information about how backups work, seeAbout Cloud SQL backups.

Required permissions

Note: You create a final backup before you delete an instance. For more information, seeDelete instances.

Google Cloud console

To manage final backups in a Google Cloud project, you need the following permissions:

TaskRequired permissions
List final backupscloudsql.backupRuns.list
Describe a final backupcloudsql.backupRuns.get
Update a final backupcloudsql.backupRuns.update
Delete a final backupcloudsql.backupRuns.delete

gcloud CLI

To manage final backups in a Google Cloud project, you need the following permissions:

ActionCommandRequired permissions
List final backupsgcloud sql backups listcloudsql.backupRuns.list
Describe a final backupgcloud sql backups describecloudsql.backupRuns.get
Update a final backupgcloud sql backups patchcloudsql.backupRuns.update
Delete a final backupgcloud sql backups deletecloudsql.backupRuns.delete

REST

To manage final backups in a Google Cloud project, you need the following permissions:

ActionMethodRequired permissions
List final backupsBackups.ListBackupscloudsql.backupRuns.list
Describe a final backupBackups.GetBackupcloudsql.backupRuns.get
Update a final backupBackups.UpdateBackupcloudsql.backupRuns.update
Delete a final backupBackups.DeleteBackupcloudsql.backupRuns.delete

View a list of final backups

You can view a list of final backups and details about a backup by using the Google Cloud console,gcloud CLI, or the Cloud SQL API.

The Google Cloud console doesn't show skipped or failed backups in the backup history. To see these types of backups, usegcloud or the Cloud SQL API.

Console

  1. In the Google Cloud console, go to theCloud SQL Backups page.

    Go to Cloud SQL Backups

    This page lists all backups, including final backups, that are associated with a Google Cloud project.

  2. To view details about a final backup, click the backup. AFinal backup dialog appears. This dialog displays the following information:

    • The date and time of when the instance, which was used to create the final backup, wasdeleted
    • The name and version of the deleted instance
    • A date-and-time stamp of how long Cloud SQL retains the final backup
    • A description of the final backup

gcloud

  1. To get a list of all final backups that are associated with a Google Cloud project, use thegcloud sql backups list command:

    gcloudsqlbackupslist\--filter="type=FINAL"

    Note: By using this command, you can retrieve information about the backups, including their IDs. You need a backup ID to view details about a final backup.

    Also, you can filter and control the results of running this command by using standard list parameters. For a complete list, see thegcloud sql backups list command reference page.

  2. To view details about a final backup, use thegcloud sql backups describe command:

    gcloudsqlbackupsdescribe\BACKUP_NAME

    You obtain theBACKUP_NAME from the output of running thegcloud sql backups list command. TheBACKUP_NAME has the following format:projects/PROJECT_ID/backups/BACKUP_ID.

REST v1

Get a list of final backups

Use this example to get a list of all final backups that are associated with a Google Cloud project. For a complete list of parameters for this call, see theBackups.ListBackups page.

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/backups?filter=type=FINAL

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "status": "SUCCESSFUL",      "backupInterval": {            "startTime": "2020-01-21T11:25:33.858Z",            "endTime": "2020-01-21T11:26:18.663Z",         }      "type": "FINAL",      "instance": "INSTANCE_ID",      "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",      "location": "us"      "description": "final backup",      "backupKind": "SNAPSHOT",      "dataDiskSizeGB": "10",      "expiryTime": "2020-01-30T11:26:18.663Z",      "backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",      "satisfies_pzs": false,      "satisfies_pzi": false}

View details about a final backup

Use this example to view the details about a final backup. For a complete list of parameters for this call, see theBackups.GetBackup page.

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

  • PROJECT_ID: the project ID.
  • BACKUP_ID: the backup ID. You obtain this ID from the output of running the previous call.

HTTP method and URL:

GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "status": "SUCCESSFUL",      "backupInterval": {            "startTime": "2020-01-21T11:25:33.858Z",            "endTime": "2020-01-21T11:26:18.663Z",         }      "type": "FINAL",      "instance": "INSTANCE_ID",      "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",      "location": "us"      "description": "final backup",      "backupKind": "SNAPSHOT",      "dataDiskSizeGB": "10",      "expiryTime": "2020-01-30T11:26:18.663Z",      "backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",      "satisfies_pzs": false,      "satisfies_pzi": false    }

REST v1beta4

Get a list of final backups

Use this example to get a list of all final backups that are associated with a Google Cloud project. For a complete list of parameters for this call, see theBackups.ListBackups page.

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/backups?filter=type=FINAL

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "status": "SUCCESSFUL",      "backupInterval": {            "startTime": "2020-01-21T11:25:33.858Z",            "endTime": "2020-01-21T11:26:18.663Z",         }      "type": "FINAL",      "instance": "INSTANCE_ID",      "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",      "location": "us"      "description": "final backup",      "backupKind": "SNAPSHOT",      "dataDiskSizeGB": "10",      "expiryTime": "2020-01-30T11:26:18.663Z",      "backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",      "satisfies_pzs": false,      "satisfies_pzi": false}

View details about a final backup

Use this example to view the details about a final backup. For a complete list of parameters for this call, see theBackups.GetBackup page.

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

  • PROJECT_ID: the project ID.
  • BACKUP_ID: the backup ID. You obtain this ID from the output of running the previous call.

HTTP method and URL:

GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "status": "SUCCESSFUL",      "backupInterval": {            "startTime": "2020-01-21T11:25:33.858Z",            "endTime": "2020-01-21T11:26:18.663Z",         }      "type": "FINAL",      "instance": "INSTANCE_ID",      "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",      "location": "us"      "description": "final backup",      "backupKind": "SNAPSHOT",      "dataDiskSizeGB": "10",      "expiryTime": "2020-01-30T11:26:18.663Z",      "backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",      "satisfies_pzs": false,      "satisfies_pzi": false    }

Update a final backup

You can updatehow long Cloud SQL retains a final backup for an instance and the description for the backup by using the Google Cloud console,gcloud CLI, or the Cloud SQL API.

Console

  1. In the Google Cloud console, go to theCloud SQL Backups page.

    Go to Cloud SQL Backups

    This page lists all backups, including final backups, that are associated with a Google Cloud project.

  2. To update a final backup, click the backup. AFinal backup dialog appears.
  3. To update how long Cloud SQL retains the final backup, complete the following actions:
    1. Click theEdit retention icon next to theBackup retained until field.
    2. Click theSelect date icon next to theRetain backup until field.
    3. In the calendar, select the new date that indicates how long Cloud SQL retains the final backup.
    4. ClickUpdate. You're returned to theCloud SQL Backups page.
  4. To update the description of the final backup, complete the following actions:
    1. Click the final backup.
    2. Click theEdit description icon next to theDescription field.
    3. In theDescribe this backup field, enter the updated description for the final backup.
    4. ClickUpdate. You're returned to theCloud SQL Backups page.

gcloud

  1. To get a list of all final backups that are associated with a Google Cloud project, use thegcloud sql backups list command:

    gcloudsqlbackupslist\--filter="type=FINAL"

    Note: By using this command, you can retrieve information about the final backups, including their IDs. You need a backup ID to update a final backup.

    Also, you can filter and control the results of running this command by using standard list parameters. For a complete list, see thegcloud sql backups list command reference page.

  2. To update the description and retention period of a final backup, use thegcloud sql backups patch command:

    gcloudsqlbackupspatch\BACKUP_NAME\--description=DESCRIPTION/--expiry-time=DATE-AND-TIME-STAMP|--ttl-days=NUMBER-OF-DAYS

    You obtain theBACKUP_NAME from the output of running thegcloud sql backups list command. TheBACKUP_NAME has the following format:projects/PROJECT_ID/backups/BACKUP_ID.

    For the--expiry-time and--ttl-days flags, use the following guidelines:

    • For the--expiry-time flag, specify a date-and-time stamp of when Cloud SQL deletes the final backup automatically.
    • For the--ttl-days flag, specify the retention period of the final backup (from 1 to 365 days). This is known astime to live (TTL). The retention period starts from the current date and time, and the maximum retention period that Cloud SQL allows is 1 year (or 365 days).
    Use either the--expiry-time or the--ttl-days flag, not both flags.

REST v1

Get a list of final backups

Use this example to get a list of all final backups that are associated with a Google Cloud project. For a complete list of parameters for this call, see theBackups.ListBackups page.

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/backups?filter=type=FINAL

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "status": "SUCCESSFUL",      "backupInterval": {            "startTime": "2020-01-21T11:25:33.858Z",            "endTime": "2020-01-21T11:26:18.663Z",         }      "type": "FINAL",      "instance": "INSTANCE_ID",      "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",      "location": "us"      "description": "final backup",      "backupKind": "SNAPSHOT",      "dataDiskSizeGB": "10",      "expiryTime": "2020-01-30T11:26:18.663Z",      "backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",      "satisfies_pzs": false,      "satisfies_pzi": false}

Update the retention period

You can update the retention period of a final backup in one of the following ways:

  • Retention days: Modify the number of days that Cloud SQL retains the backup.
  • Expiration time: Provide an updated date-and-time stamp for when Cloud SQL deletes the backup automatically.
Update a final backup by either modifying the retention days or by providing a updated expiration time. Don't use both ways.
Update the retention days

Use this example to update the number of days that Cloud SQL retains the final backup. For a complete list of parameters for this call, see theBackups.UpdateBackup page.

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

  • PROJECT_ID: the project ID.
  • BACKUP_ID: the backup ID. You obtain this ID from the output of running the previous call.
  • TTL_DAYS: the retention period of the final backup (from 1 to 365 days). This is known astime to live (TTL). The retention period starts from the current date and time, and the maximum retention period that Cloud SQL allows is 1 year (or 365 days).

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days

Request JSON body:

{        "backup": {            expiration: {            "ttl_days":TTL_DAYS,            }         },}

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "kind": "sql#operation",      "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",      "status": "DONE",      "user": "user@example.com",      "insertTime": "2024-02-15T00:10:22.078Z",      "operationType": "UPDATE_BACKUP",      "name": "OPERATION_ID",      "targetId": "BACKUP_ID",      "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",      "targetProject": "PROJECT_ID"}
Update the expiration time

Use this example to provide an updated date-and-time stamp for when Cloud SQL deletes the backup. For a complete list of parameters for this call, see theBackups.UpdateBackup page.

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

  • PROJECT_ID: the project ID.
  • BACKUP_ID: the backup ID. You obtain this ID from the output of running the previous call.
  • DATE_AND_TIME_STAMP: a date-and-time stamp of when Cloud SQL deletes the final backup automatically.

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time

Request JSON body:

{        "backup": {            expiration: {            "expiry_time":DATE_AND_TIME_STAMP,            }         },}

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "kind": "sql#operation",      "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",      "status": "DONE",      "user": "user@example.com",      "insertTime": "2024-02-15T00:10:22.078Z",      "operationType": "UPDATE_BACKUP",      "name": "OPERATION_ID",      "targetId": "BACKUP_ID",      "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",      "targetProject": "PROJECT_ID"}

Update the description

Use this example to update the description of the final backup. For a complete list of parameters for this call, see theBackups.UpdateBackup page.

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

  • PROJECT_ID: the project ID.
  • BACKUP_ID: the backup ID. You obtain this ID from the output of running the previous call.
  • DESCRIPTION: the updated description for the final backup.

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description

Request JSON body:

{        "backup": {            "description":DESCRIPTION,         },}

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "kind": "sql#operation",      "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",      "status": "DONE",      "user": "user@example.com",      "insertTime": "2024-02-15T00:10:22.078Z",      "operationType": "UPDATE_BACKUP",      "name": "OPERATION_ID",      "targetId": "BACKUP_ID",      "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",      "targetProject": "PROJECT_ID"}

REST v1beta4

Get a list of final backups

Use this example to get a list of all final backups that are associated with a Google Cloud project. For a complete list of parameters for this call, see theBackups.ListBackups page.

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/backups?filter=type=FINAL

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "status": "SUCCESSFUL",      "backupInterval": {            "startTime": "2020-01-21T11:25:33.858Z",            "endTime": "2020-01-21T11:26:18.663Z",         }      "type": "FINAL",      "instance": "INSTANCE_ID",      "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",      "location": "us"      "description": "final backup",      "backupKind": "SNAPSHOT",      "dataDiskSizeGB": "10",      "expiryTime": "2020-01-30T11:26:18.663Z",      "backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",      "satisfies_pzs": false,      "satisfies_pzi": false}

Update the retention period

You can update the retention period of a final backup in one of the following ways:

  • Retention days: Modify the number of days that Cloud SQL retains the backup
  • Expiration time: Provide an updated date-and-time stamp for when Cloud SQL deletes the backup automatically.
Update a final backup by either modifying the retention days or by providing a updated expiration time. Don't use both ways.
Update the retention days

Use this example to update the number of days that Cloud SQL retains the final backup. For a complete list of parameters for this call, see theBackups.UpdateBackup page.

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

  • PROJECT_ID: the project ID.
  • BACKUP_ID: the backup ID. You obtain this ID from the output of running the previous call.
  • TTL_DAYS: the retention period of the final backup (from 1 to 365 days). This is known astime to live (TTL). The retention period starts from the current date and time, and the maximum retention period that Cloud SQL allows is 1 year (or 365 days).

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days

Request JSON body:

{        "backup": {            expiration: {            "ttl_days":TTL_DAYS,            }         },}

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=ttl_days" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "kind": "sql#operation",      "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",      "status": "DONE",      "user": "user@example.com",      "insertTime": "2024-02-15T00:10:22.078Z",      "operationType": "UPDATE_BACKUP",      "name": "OPERATION_ID",      "targetId": "BACKUP_ID",      "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",      "targetProject": "PROJECT_ID"}
Update the expiration time

Use this example to provide an updated date-and-time stamp for when Cloud SQL deletes the backup. For a complete list of parameters for this call, see theBackups.UpdateBackup page.

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

  • PROJECT_ID: the project ID.
  • BACKUP_ID: the backup ID. You obtain this ID from the output of running the previous call.
  • DATE_AND_TIME_STAMP: a date-and-time stamp of when Cloud SQL deletes the final backup automatically.

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time

Request JSON body:

{        "backup": {            expiration: {            "expiry_time":DATE_AND_TIME_STAMP,            }         },}

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=expiry_time" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "kind": "sql#operation",      "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",      "status": "DONE",      "user": "user@example.com",      "insertTime": "2024-02-15T00:10:22.078Z",      "operationType": "UPDATE_BACKUP",      "name": "OPERATION_ID",      "targetId": "BACKUP_ID",      "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",      "targetProject": "PROJECT_ID"}

Update the description

Use this example to update the description of the final backup. For a complete list of parameters for this call, see theBackups.UpdateBackup page.

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

  • PROJECT_ID: the project ID.
  • BACKUP_ID: the backup ID. You obtain this ID from the output of running the previous call.
  • DESCRIPTION: the updated description for the final backup.

HTTP method and URL:

PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description

Request JSON body:

{        "backup": {            "description":DESCRIPTION,         },}

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID?update_mask=description" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "kind": "sql#operation",      "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",      "status": "DONE",      "user": "user@example.com",      "insertTime": "2024-02-15T00:10:22.078Z",      "operationType": "UPDATE_BACKUP",      "name": "OPERATION_ID",      "targetId": "BACKUP_ID",      "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",      "targetProject": "PROJECT_ID"}

Delete a final backup

You can delete a final backup by using the Google Cloud console,gcloud CLI, or the Cloud SQL API.

Deleting a backup might notfree up as much space as the size of the backup. This is because backups areincremental, so deleting an older backup might transfer some of its contentsto a more recent backup to preserve the integrity of the newer backup.

Console

  1. In the Google Cloud console, go to theCloud SQL Backups page.

    Go to Cloud SQL Backups

    This page lists all backups, including final backups, that are associated with a Google Cloud project.

  2. For the final backup that you want to delete, click more actionsMore actions icon., and then selectDelete.
  3. In theDelete final backup? window, enter the name of the instance that you used to create the final backup, and then clickDelete.

gcloud

  1. To get a list of all final backups that are associated with a Google Cloud project, use thegcloud sql backups list command:

    gcloudsqlbackupslist\--filter="type=FINAL"

    Note: By using this command, you can retrieve information about the backups, including their IDs. You need a backup ID to delete a final backup.

    Also, you can filter and control the results of running this command by using standard list parameters. For a complete list, see thegcloud sql backups list command reference page.

  2. To delete a final backup, use thegcloud sql backups delete command:

    gcloudsqlbackupsdelete\BACKUP_NAME

    You obtain theBACKUP_NAME from the output of running thegcloud sql backups list command. TheBACKUP_NAME has the following format:projects/PROJECT_ID/backups/BACKUP_ID.

REST v1

Get a list of final backups

Use this example to get a list of all final backups that are associated with a Google Cloud project. For a complete list of parameters for this call, see theBackups.ListBackups page.

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/backups?filter=type=FINAL

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups?filter=type=FINAL" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "status": "SUCCESSFUL",      "backupInterval": {            "startTime": "2020-01-21T11:25:33.858Z",            "endTime": "2020-01-21T11:26:18.663Z",         }      "type": "FINAL",      "instance": "INSTANCE_ID",      "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",      "location": "us"      "description": "final backup",      "backupKind": "SNAPSHOT",      "dataDiskSizeGB": "10",      "expiryTime": "2020-01-30T11:26:18.663Z",      "backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",      "satisfies_pzs": false,      "satisfies_pzi": false}

Delete a final backup

Use this example to delete a final backup. For a complete list of parameters for this call, see theBackups.DeleteBackup page.

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

  • PROJECT_ID: the project ID.
  • BACKUP_ID: the backup ID. You obtain this ID from the output of running the previous call.

HTTP method and URL:

DELETE https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{  "kind": "sql#operation",  "targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/backups/BACKUP_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "DELETE_BACKUP",  "name": "OPERATION_ID",  "targetId": "BACKUP_ID",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

REST v1beta4

Get a list of final backups

Use this example to get a list of all final backups that are associated with a Google Cloud project. For a complete list of parameters for this call, see theBackups.ListBackups page.

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/backups?filter=type=FINAL

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups?filter=type=FINAL" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "status": "SUCCESSFUL",      "backupInterval": {            "startTime": "2020-01-21T11:25:33.858Z",            "endTime": "2020-01-21T11:26:18.663Z",         }      "type": "FINAL",      "instance": "INSTANCE_ID",      "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",      "location": "us"      "description": "final backup",      "backupKind": "SNAPSHOT",      "dataDiskSizeGB": "10",      "expiryTime": "2020-01-30T11:26:18.663Z",      "backup_run": "projects/PROJECT_ID/instances/INSTANCE_ID/backupRuns/BACKUP_RUN_ID",      "satisfies_pzs": false,      "satisfies_pzi": false}

Delete a final backup

Use this example to delete a final backup. For a complete list of parameters for this call, see theBackups.DeleteBackup page.

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

  • PROJECT_ID: the project ID.
  • BACKUP_ID: the backup ID. You obtain this ID from the output of running the previous call.

HTTP method and URL:

DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{  "kind": "sql#operation",  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/backups/BACKUP_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "DELETE_BACKUP",  "name": "OPERATION_ID",  "targetId": "BACKUP_ID",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-18 UTC.