Restore an instance using a backup

MySQL  |  PostgreSQL  |  SQL Server

You can restore your instance from a backup and recover it to aspecific period of time to a new or an existing instance. You can restore a liveor a deleted instance. To learn more about how restoring works, seeRestore overview.

To restore an instance using a backup, you must do the following:

  1. Find the backup you want to restore
  2. Use the backup to restore your instance

The location of your backup depends on your instance'sbackup option.

Restore a live instance

You can restore a backup in the following ways:

Restore to the same instance

When you restore data from a backup to the same instance, you return the dataon that instance to the state of when you took the backup.

Warning: The restore process overwrites all of the current data on the instance, includingprevious point-in-time recovery (PITR) logs. Previous on-demand and automatic backups on theinstance are retained.

To restore your instance using a backup to the same instance, do the following:

Console

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

    Go to Cloud SQL Backups

  2. On theBackups page, clickStandard tier orEnhanced tier, depending on your instance'sbackup option.

  3. If your instance is using standard backups, then select the instance you want to view backups for.

    If your instance is using enhanced backups, then selectEnhanced tier, then select theBackup vaultthat contains the backup you want to use. All backups available in thebackup vault for your selected instance are displayed.

  4. Find the name of the backup you want to restore and then clickRestore.

    Note: All replicas for your target instance must be deleted priorto restoring.
  5. InChoose restore destination, selectOverwrite the source instance.

  6. In theDestination instance ID field, enter the name of the instance to be overwritten to confirm your selection.

  7. ClickRestore.

    Cloud SQL restores the backup to same instance. To check thestatus of the restore operation, go to theOperations page for theinstance.

    You can create any replicas once the restore operation completes.

gcloud

  1. All replicas must be deleted from your instance prior to restoring.

    Determine if your instance has any read replicas using thegcloud sql instances describecommand:

    gcloud sql instances describeINSTANCE_NAME

    Replace the following:

    • INSTANCE_NAME: the name of the instance.

    If your instance contains replicas, then delete the replicasusing thegcloud sql instances deletecommand:

    gcloud sql instances deleteREPLICA_NAME

    Replace the following:

    • REPLCICA_NAME: the name of the replica.
  2. Find the backup you want to use.

    If your instance is using standard backups, use thegcloud sql backups listcommand to find a backup and record itsID value:

    gcloud sql backups listINSTANCE_NAME

    Replace the following:

    • INSTANCE_NAME: the name of the instance.

    If your instance is using enhanced backups, seeList all backups in a backup vault.

  3. To restore the instance from the specified backup, use thegcloud sql backups restorecommand:

    gcloud sql backups restoreBACKUP_ID \--restore-instance=BACKUP_ID

    Replace the following:

    • BACKUP_ID: the backup you want to restore's ID.
    • INSTANCE_NAME: the name of the instance.
  4. After the restore operation completes, recreate any replicas that you deletedin this procedure.

REST v1

  1. To determine if the instance has any read replicas and to get their IDs, listall the replicas for the instance:

    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?fields=replicaNames

    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/instances/INSTANCE_ID?fields=replicaNames"

    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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content

    You should receive a JSON response similar to the following:

    Response

    {  "replicaNames": [    "REPLICA_NAME"  ]}

  2. Delete all replicas for the instance:

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

    • PROJECT_ID: the project ID
    • REPLICA_ID: the replica ID

    HTTP method and URL:

    DELETE https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "DELETE_BACKUP",  "name": "OPERATION_ID",  "targetId": "REPLICA_ID",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

  3. Get the ID of the backup you want to use.

    • If your instance is using standard backups, run the following:

      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:

      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/instances/instance-id/backupRuns"

      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/instances/instance-id/backupRuns" | Select-Object -Expand Content

      You should receive a JSON response similar to the following:

      Response

      {      "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"    }

  4. Restore the instance from 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:

    POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/restoreBackup

    Request JSON body:

    {  "restoreBackupContext":  {    "backupRunId": "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.

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

    curl -X POST \
    -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/instances/INSTANCE_ID/restoreBackup"

    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 POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/restoreBackup" | 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/instances/INSTANCE_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_BACKUP",  "name": "OPERATION_ID",  "targetId": "INSTANCE_ID",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

  5. After the restore operation completes, recreate any replicas that youdeleted in this procedure.

REST v1beta4

  1. To determine if the instance has any read replicas and to get their IDs, listall the replicas for the instance:

    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?fields=replicaNames

    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/instances/INSTANCE_ID?fields=replicaNames"

    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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content

    You should receive a JSON response similar to the following:

    Response

    {  "replicaNames": [    "REPLICA_NAME"  ]}
  2. Delete all replicas for the instance:

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

    • PROJECT_ID: the project ID
    • REPLICA_ID: the replica ID

    HTTP method and URL:

    DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "DELETE_BACKUP",  "name": "OPERATION_ID",  "targetId": "REPLICA_ID",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

  3. Get the ID of the backup you want to use.

    • If your instance is using standard backups, run the following:

      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:

      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/instances/instance-id/backupRuns"

      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/instances/instance-id/backupRuns" | Select-Object -Expand Content

      You should receive a JSON response similar to the following:

      Response

      {      "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/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns/backup-id",      "location": "us"    }

  4. Restore the instance from the backup:

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

    • PROJECT_ID: the project ID
    • INSTANCE_ID: the instance ID
    • BACKUP_RUN_ID: a date-and-time stamp of when Cloud SQL restores the instance from the backup

    HTTP method and URL:

    POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID/restoreBackup

    Request JSON body:

    {  "restoreBackupContext":  {    "backupRunId": "BACKUP_RUN_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.

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

    curl -X POST \
    -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/instances/INSTANCE_ID/restoreBackup"

    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 POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/INSTANCE_ID/restoreBackup" | 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/instances/TARGET_INSTANCE_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_BACKUP",  "name": "OPERATION_ID",  "targetId": "TARGET_INSTANCE_ID",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

  5. After the restore operation completes, recreate any replicas that youdeleted in this procedure.

Restore to a new or existing instance

When you restore data from a backup to a different instance, you update the data onthe target instance to the state of the source instance when you took the backup.

If you need a list of backups for the project and can't view them on the instance overviewpage due to an outage, you can use thebackupRuns.listAPI with a wildcard (-). The wildcard option retrieves a list of all backups across allinstances in the project. For more information, seeViewing backups during an outage.

To restore your instance to a new or existing instance, do the following:

Console

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

    Go to Cloud SQL Backups

  2. On theBackups page, clickStandard tier orEnhanced tier, dependingon your instance'sbackup option.

  3. If your instance is using standard backups, then select the instanceyou want to view backups for.

    If your instance is using enhanced backups, then selectEnhanced tier, then select theBackup vaultthat contains the backup you want to use. All backups available in thebackup vault for your selected instance are displayed.

  4. Find the name of the backup you want to restore and then clickRestore.

  5. InChoose restore destination:

  6. ClickRestore.

    Cloud SQL restores the backup to the new or existing instance,depending on your selection. To check the status of the restore operation,go to theOperations page for the instance.

    You can create any replicas once the restore operation completes.

gcloud

  1. If you're restoring to an existing instance, then all replicas must be deletedfrom your target instance prior to restoring.

    Determine if your instance has any read replicas using thegcloud sql instances describecommand:

    gcloud sql instances describeTARGET_INSTANCE_NAME

    Replace the following:

    • TARGET_INSTANCE_NAME: the name of the instance.

    If your instance contains replicas, then delete the replicasusing thegcloud sql instances deletecommand:

    gcloud sql instances deleteREPLCICA_NAME

    Replace the following:

    • REPLCICA_NAME: the name of the replica.
  2. Find the backup you want to use.

    If your instance is using standard backups, use thegcloud sql backups listcommand to find a backup and record itsID value:

    gcloud sql backups listINSTANCE_NAME

    Replace the following:

    • INSTANCE_NAME: the name of the instance.

    If your instance is using enhanced backups, seeList all backups in a backup vault.

  3. To restore the instance from the specified backup, use thegcloud sql backups restorecommand:

    gcloud sql backups restoreBACKUP_ID \--restore-instance=TARGET_INSTANCE_NAME \--backup-instance=SOURCE_INSTANCE_NAME

    Replace the following:

    • BACKUP_ID: the backup you want to restore's ID.
    • TARGET_INSTANCE_NAME: the name of the target new or existinginstance.
    • SOURCE_INSTANCE_NAME: the name of the source instance.
  4. If you're restoring to an existing instance, then after the restore operation completes,recreate any replicas that you deleted in this procedure.

REST v1

  1. If you're using an existing instance, all replicas must be deleted prior to restoring. Determine if the instance has any read replicas and to get their IDs, list all the replicas for the instance:

    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?fields=replicaNames

    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/instances/INSTANCE_ID?fields=replicaNames"

    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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content

    You should receive a JSON response similar to the following:

    Response

    {  "replicaNames": [    "REPLICA_NAME"  ]}

  2. Delete all replicas for the instance:

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

    • PROJECT_ID: the project ID
    • REPLICA_ID: the replica ID

    HTTP method and URL:

    DELETE https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "DELETE_BACKUP",  "name": "OPERATION_ID",  "targetId": "REPLICA_ID",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

  3. Get the ID of the backup you want to use.

    • If your instance is using standard backups, run the following:

      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:

      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/instances/instance-id/backupRuns"

      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/instances/instance-id/backupRuns" | Select-Object -Expand Content

      You should receive a JSON response similar to the following:

      Response

      {      "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"    }

  4. Restore the instance from the backup:

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

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

    HTTP method and URL:

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

    Request JSON body:

    {  "restoreBackupContext":  {    "backupRunId":backup-id,    "instanceId": "source-instance-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.

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

    curl -X POST \
    -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/instances/target-instance-id/restoreBackup"

    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 POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/target-instance-id/restoreBackup" | 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/instances/instance-id",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_BACKUP",  "name": "operation-id",  "targetId": "instance-id",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id",  "targetProject": "project-id"}

  5. After the restore operation completes, recreate any replicas that youdeleted in this procedure.

REST v1beta4

  1. To determine if the instance has any read replicas and to get their IDs, listall the replicas for the instance:

    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?fields=replicaNames

    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/instances/INSTANCE_ID?fields=replicaNames"

    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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content

    You should receive a JSON response similar to the following:

    Response

    {  "replicaNames": [    "REPLICA_NAME"  ]}

  2. Delete all replicas for the instance:

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

    • PROJECT_ID: the project ID
    • REPLICA_ID: the replica ID

    HTTP method and URL:

    DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "DELETE_BACKUP",  "name": "OPERATION_ID",  "targetId": "REPLICA_ID",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

  3. Get the ID of the backup you want to use.

    • If your instance is using standard backups, run the following:

      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:

      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/instances/instance-id/backupRuns"

      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/instances/instance-id/backupRuns" | Select-Object -Expand Content

      You should receive a JSON response similar to the following:

      Response

      {      "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/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns/backup-id",      "location": "us"    }

  4. Restore the instance from the backup:

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

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

    HTTP method and URL:

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

    Request JSON body:

    {  "restoreBackupContext":  {    "backupRunId":backup-id,    "instanceId": "source-instance-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.

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

    curl -X POST \
    -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/instances/target-instance-id/restoreBackup"

    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 POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/target-instance-id/restoreBackup" | 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/instances/instance-id",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_BACKUP",  "name": "operation-id",  "targetId": "instance-id",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",  "targetProject": "project-id"}

  5. After the restore operation completes, recreate any replicas that youdeleted in this procedure.

Restore to an instance in another project

You can use theproject parameter to restore data to an instance in a differentproject. When you restore from a backup to an instance in a different project, youupdate the data on the target instance to the state of the source instance when youtook the backup.

The user restoring to a different project must have the following permissionsto restore the instance:*cloudsql.instances.restoreBackup permission for the target project*cloudsql.backupRuns.get permission for the source project.

These permissions are included theCloud SQL Admin role.

Warning: The restore process overwrites all of the current data on the instance, includingprevious point-in-time recovery (PITR) logs. Previous on-demand and automatic backups on theinstance are retained.

To restore your instance using a backup to an instance in a different project or region,do the following:

gcloud

To restore a backup from a backup vault to an existing instance, do thefollowing:

  1. If restoring to an existing instance, determine if the target instancehas any read replicas using thegcloud sql instances describecommand:

    gcloud sql instance describeTARGET_INSTANCE_NAME

    Replace the following:

    • TARGET_INSTANCE_NAME: the name of thetarget instance you want to restore your backup to.

    Delete all replicas for your target instance using thegcloud sql instances deletecommand:

    gcloud sql instance deleteREPLICA_NAME

    Replace the following:

    • REPLICA_NAME: the name of the replica of thetarget instance.

    All replicas must be deleted before you can restore to an existinginstance.

  2. Find the backup you want to use.

    If your instance is using standard backups, use thegcloud sql backups listcommand to find a backup and record itsID value:

    gcloud sql backups listINSTANCE_NAME

    Replace the following:

    • INSTANCE_NAME: the name of the instance.

    If your instance is using enhanced backups, seeList all backups in a backup vault.

  3. To restore to a new or existing instance in a new project, use thegcloud sql backups restorecommand:

    gcloud sql backups restoreBACKUP_ID--restore-instance=TARGET_INSTANCE_NAME--backup-instance=SOURCE_INSTANCE_NAME--backup-project=SOURCE_INSTANCE_PROJECT

    Replace the following:

    • BACKUP_ID: the ID of the backup from thebackup vault. You'll need to include thefull path of the backup in this field.

    • TARGET_INSTANCE_NAME: the instance in thedestination project which you're restoring data.

    • SOURCE_INSTANCE_NAME: the instance name in thesource project where the data is.

    • SOURCE_INSTANCE_PROJECT: the project thatcontains the source instance.

REST v1

  1. To obtain thebackupId, run the following:

    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:

    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/instances/instance-id/backupRuns"

    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/instances/instance-id/backupRuns" | Select-Object -Expand Content

    You should receive a JSON response similar to the following:

    Response

    {      "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"    }

  2. Restore the backup to an instance in a different project:

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

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

    HTTP method and URL:

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

    Request JSON body:

    {  "restoreBackupContext":  {    "backupRunId":backup-id,    "project": "source-project-id",    "instanceId": "source-instance-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.

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

    curl -X POST \
    -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/target-project-id/instances/target-instance-id/restoreBackup"

    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 POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/target-project-id/instances/target-instance-id/restoreBackup" | 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/target-project-id/instances/target-instance-id",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_VOLUME",  "name": "operation-id",  "targetId": "target-instance-id",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/target-project-id/operations/operation-id",  "targetProject": "target-project-id"}

REST v1beta4

  1. To obtain thebackupId, run the following:

    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:

    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/instances/instance-id/backupRuns"

    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/instances/instance-id/backupRuns" | Select-Object -Expand Content

    You should receive a JSON response similar to the following:

    Response

    {      "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/sql/v1beta4/projects/project-id/instances/instance-id/backupRuns/backup-id",      "location": "us"    }

  2. Restore the backup to an instance in a different project:

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

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

    HTTP method and URL:

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

    Request JSON body:

    {  "restoreBackupContext":  {    "backupRunId":backup-id,    "project": "source-project-id",    "instanceId": "source-instance-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.

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

    curl -X POST \
    -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/target-project-id/instances/target-instance-id/restoreBackup"

    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 POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/target-project-id/instances/target-instance-id/restoreBackup" | 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/target-project-id/instances/target-instance-id",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_VOLUME",  "name": "operation-id",  "targetId": "target-instance-id",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/target-project-id/operations/operation-id",  "targetProject": "target-project-id"}

Restore a deleted instance

You can use afinal backupor aretained backupto restore a deleted instance for the following scenarios:

Restore to an existing instance

When you restore data from a final or retained backup to an existing instance,you update the data on the target instance to the state of the source instancewhen you took the backup. For more information about restoring an instance, seeGeneral tips about performing a restore.

Warning: The restore process overwrites all of the current data on the instance, includingprevious point-in-time recovery (PITR) logs. Previous on-demand and automatic backups onthe instance are retained.

To restore a deleted instance using a backup to an existing instance, do the following:

Console

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

    Go to Cloud SQL Instances

  2. If the target instance has any read replicas, then use the more actions menuMore actions icon. to delete them. All replicas must be deleted before youcan restore a retained or final backup to the existing instance.

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

    Go to Cloud SQL Backups

  4. On theBackups page, clickStandard tier orEnhanced tier, dependingon your instance'sbackup option.

  5. If your instance is using standard backups, then click the name of thedeleted instance that contains the backup you want to restore.

    If your instance is using enhanced backups, selectEnhanced tier, then select theBackup vaultthat contains the backup you want to use. All backups available in thebackup vault for your selected instance are displayed.

  6. Find the name of the backup you want to restore and then clickRestore.

  7. On theRestore an instance from a backup page, confirm thatyou selected the correct backup inReview backup details.

  8. In theChoose restore destination section, selectOverwrite an existing instance.

  9. From theInstance to be overwritten menu, select theinstance that you want to restore the backup to. The instance youselect and all its data will be overwritten.

  10. To confirm your selection, in theDestination instance ID field,enter the name of the instance to be overwritten.

  11. ClickRestore.

    Cloud SQL will restore the backup to the existing instance.To check the status of the restore operation, go to theOperations page for the instance.

    You can create any replicas once the restore operation completes.

gcloud

1.Whenrestoringtoanexistinginstance,allreplicasmustbedeletedfromyourtargetinstancepriortorestoring.Determineifyourinstancehasanyreadreplicasusingthe[`gcloudsqlinstancesdescribe`](/sdk/gcloud/reference/sql/instances/describe)command:```gcloudgcloudsqlinstancesdescribeTARGET_INSTANCE_NAME```Replacethefollowing:*`TARGET_INSTANCE_NAME`:thenameoftheinstance.Ifyourinstancecontainsreplicas,thendeletethereplicasusingthe[`gcloudsqlinstancesdelete`](/sdk/gcloud/reference/sql/instances/delete)command:```gcloudgcloudsqlinstancesdeleteREPLCICA_NAME```Replacethefollowing:*`REPLCICA_NAME`:thenameofthereplica.
  1. Find the backup you want to use.

    If your instance is using standard backups, use thegcloud sql backups listcommand to find a backup and record itsID value:

    gcloud sql backups listINSTANCE_NAME

    Replace the following:

    • INSTANCE_NAME: the name of the instance.

    If your instance is using enhanced backups, seeList all backups in a backup vault.

  2. To restore the instance from the specified backup, use thegcloud sql backups restorecommand:

    gcloud sql backups restoreBACKUP_ID \--restore-instance=TARGET_INSTANCE_NAME

    Replace the following:

    • BACKUP_ID: the ID of the backup you want to restore.
    • TARGET_INSTANCE_NAME: the name of the new or existing target instance.
  3. After the restore operation completes, recreate any replicas that youdeleted in this procedure.

REST v1

  1. When restoring to an existing instance, all replicas must be deletedfrom your target instance prior to restoring. To determine if theinstance has any read replicas, run the following:

    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?fields=replicaNames

    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/instances/INSTANCE_ID?fields=replicaNames"

    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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content

    You should receive a JSON response similar to the following:

    Response

    {  "replicaNames": [    "REPLICA_NAME"  ]}

  2. Delete all the read replicas of the instance:

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

    • PROJECT_ID: the project ID
    • REPLICA_ID: the replica ID

    HTTP method and URL:

    DELETE https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "DELETE_BACKUP",  "name": "OPERATION_ID",  "targetId": "REPLICA_ID",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

  3. Get the ID of the final or retained backup you want to use:

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

    • PROJECT_ID: the project ID

    HTTP method and URL:

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

    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"

    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" | 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",      "state": "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": "This is a 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}

  4. Restore the target instance from the retained or final backup.

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

    • PROJECT_ID: the project ID
    • TARGET_INSTANCE_ID: the target instance ID
    • BACKUP_ID: the backup ID

    HTTP method and URL:

    POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup

    Request JSON body:

    {  backup: 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.

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

    curl -X POST \
    -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/instances/TARGET_INSTANCE_ID/restoreBackup"

    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 POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | 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/instances/TARGET_INSTANCE_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_BACKUP",  "name": "OPERATION_ID",  "targetId": "TARGET_INSTANCE_ID",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

REST v1beta4

  1. When restoring to an existing instance, all replicas must be deletedfrom your target instance prior to restoring. To determine if theinstance has any read replicas, run the following:

    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?fields=replicaNames

    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/instances/INSTANCE_ID?fields=replicaNames"

    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/instances/INSTANCE_ID?fields=replicaNames" | Select-Object -Expand Content

    You should receive a JSON response similar to the following:

    Response

    {  "replicaNames": [    "REPLICA_NAME"  ]}

  2. Delete all the read replicas of the instance:

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

    • PROJECT_ID: the project ID
    • REPLICA_ID: the replica ID

    HTTP method and URL:

    DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_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/instances/REPLICA_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "DELETE_BACKUP",  "name": "OPERATION_ID",  "targetId": "REPLICA_ID",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

  3. Get the ID of the final or retained backup you want to use:

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

    • PROJECT_ID: the project ID

    HTTP method and URL:

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

    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"

    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" | 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",      "state": "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": "This is a 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}

  4. Restore the target instance from the retained or final backup.

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

    • PROJECT_ID: the project ID
    • TARGET_INSTANCE_ID: the target instance ID
    • BACKUP_ID: the backup ID

    HTTP method and URL:

    POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup

    Request JSON body:

    {  backup: 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.

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

    curl -X POST \
    -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/instances/TARGET_INSTANCE_ID/restoreBackup"

    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 POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | 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/instances/TARGET_INSTANCE_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_BACKUP",  "name": "OPERATION_ID",  "targetId": "TARGET_INSTANCE_ID",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

Restore to a new instance

When you create an instance from a final or retained backup, Cloud SQLuses the configuration settings of the instance from where the backup is taken.After the instance is created, Cloud SQL restores the data to the stateof when the backup is taken.

To restore data from a final or retained backup to a new instance, you must have thefollowing permissions:

  • cloudsql.instances.create permission for the target project
  • cloudsql.instances.restoreBackup permission for the target project
  • cloudsql.backupRuns.get permission for the source backup.

These permissions are included in the Cloud SQL Admin role.

Note: The instance that you create from the final backup has a differentIP address from the instance where the final backup is taken. For moreinformation about restoring an instance, seeGeneral tips about performing a restore.

To restore a deleted instance using a backup to a new instance, do the following:

Console

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

    Go to Cloud SQL Backups

  2. On theBackups page, clickStandard tier orEnhanced tier, dependingon your instance'sbackup option.

  3. If your instance is using standard backups, then click the name of thedeleted instance that contains the backup you want to restore.

    If your instance is using enhanced backups, then selectEnhanced tier, then select theBackup vaultthat contains the backup you want to use. All backups available in thebackup vault for your selected instance are displayed.

  4. Find the name of the backup you want to restore and clickRestore.

  5. On theRestore an instance from a backup page, confirm thatyou selected the correct backup inReview backup details.

  6. In theChoose restore destination section, selectRestore to a new instance.

  7. From theRegion menu, select the region for the new instance.

  8. In theInstance ID field, enter an ID for the new instance.This ID cannot be changed once created.

  9. ClickRestore.

    Cloud SQL will restore the backup to the existing instance.To check the status of the restore operation, go to theOperations page for the instance.

gcloud

  1. Find the backup you want to use.

    If your instance is using standard backups, use thegcloud sql backups listcommand to find a backup and record itsID value:

    gcloud sql backups listINSTANCE_NAME

    Replace the following:

    • INSTANCE_NAME: the name of the instance.

    If your instance is using enhanced backups, seeList all backups in a backup vault.

  2. To restore the instance from the specified backup, use thegcloud sql backups restorecommand:

    gcloud sql backups restoreBACKUP_ID \--restore-instance=TARGET_INSTANCE_NAME

    Replace the following:

    • BACKUP_ID: The ID of th backup you want to restore.
  3. TARGET_INSTANCE_NAME: the name of the new or existing target instance.

REST v1

Restore a new instance from the specified retained or final backup

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

  • PROJECT_ID: the project ID
  • TARGET_INSTANCE_ID: the target instance ID
  • BACKUP_ID: the backup ID
Note:Therestore_instance_settings: {} line of code lets Cloud SQL restore data from the backup to the new instance.

HTTP method and URL:

POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup

Request JSON body:

{  backup: projects/PROJECT_ID/backups/BACKUP_ID  restore_instance_settings: {}}

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 POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"

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 POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | 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/instances/TARGET_INSTANCE_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_BACKUP",  "name": "OPERATION_ID",  "targetId": "TARGET_INSTANCE_ID",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

REST v1beta4

Restore a new instance from the specified retained or final backup

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

  • PROJECT_ID: the project ID
  • TARGET_INSTANCE_ID: the target instance ID
  • BACKUP_ID: the backup ID
Note:Therestore_instance_settings: {} line of code lets Cloud SQL restore data from the backup to the new instance.

HTTP method and URL:

POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup

Request JSON body:

{  backup: projects/PROJECT_ID/backups/BACKUP_ID  restore_instance_settings: {}}

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 POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"

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 POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | 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/instances/TARGET_INSTANCE_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_BACKUP",  "name": "OPERATION_ID",  "targetId": "TARGET_INSTANCE_ID",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

Restore to a new or existing instance in a different project

You can use theproject parameter to restore data to an instance in adifferent project. When you restore a deleted instance from a backup to aninstance in a different project, the target instance is updated tothe state of the source instance when you took the backup.

The user restoring to a different project must have the following permissionsto restore the instance:*cloudsql.instances.create permission for the target project*cloudsql.instances.restoreBackup permission for the target project*cloudsql.backupRuns.get permission for the source backup.

These permissions are included theCloud SQL Admin role.

Warning: The restore process overwrites all of the current data on the instance, includingprevious point-in-time recovery (PITR) logs. Previous on-demand and automatic backups on theinstance are retained.

To restore your instance using a backup to an instance in a different project or region,do the following:

gcloud

  1. If restoring to an existing instance, determine if the target instancehas any read replicas using thegcloud sql instances describecommand:

    gcloud sql instance describeTARGET_INSTANCE_NAME

    Replace the following:

    • TARGET_INSTANCE_NAME: the name of thetarget instance you want to restore your backup to.

    Delete all replicas for your target instance using thegcloud sql instances deletecommand:

    gcloud sql instance deleteREPLICA_NAME

    Replace the following:

    • REPLICA_NAME: the name of the replica of thetarget instance.

    All replicas must be deleted before you can restore to an existinginstance.

    1. Find the backup you want to use.

    If your instance is using standard backups, use thegcloud sql backups listcommand to find a backup and record itsID value:

    gcloud sql backups listINSTANCE_NAME

    Replace the following:

    • INSTANCE_NAME: the name of the instance.

    If your instance is using enhanced backups, seeList all backups in a backup vault.

  2. To restore to a new or existing instance in a new project, use thegcloud sql backups restorecommand:

    gcloud sql backups restoreBACKUP_ID--restore-instance=TARGET_INSTANCE_NAME--backup-instance=SOURCE_INSTANCE_NAME--backup-project=SOURCE_INSTANCE_PROJECT

    Replace the following:

    • BACKUP_ID: the ID of the backup from thebackup vault. You'll need to include thefull path of the backup in this field.

    • TARGET_INSTANCE_NAME: the instance in thedestination project which you're restoring data.

    • SOURCE_INSTANCE_NAME: the instance name in thesource project where the data is.

    • SOURCE_INSTANCE_PROJECT: the project thatcontains the source instance.

REST v1

To get thebackupID for the retained or final backup, run the following:

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

  • PROJECT_ID: the project ID

HTTP method and URL:

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

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"

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" | 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",      "state": "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": "This is a 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}

Restore to a different project

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

  • PROJECT_ID: the project ID
  • TARGET_INSTANCE_ID: the target instance ID
  • BACKUP_ID: the backup ID

HTTP method and URL:

POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup

Request JSON body:

{  backup: 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.

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

curl -X POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"

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 POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | 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/instances/TARGET_INSTANCE_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_BACKUP",  "name": "OPERATION_ID",  "targetId": "TARGET_INSTANCE_ID",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

REST v1beta4

To get thebackupID for the retained or final backup, run the following:

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

  • PROJECT_ID: the project ID

HTTP method and URL:

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

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"

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" | 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",      "state": "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": "This is a 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}

Restore to a different project

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

  • PROJECT_ID: the project ID
  • TARGET_INSTANCE_ID: the target instance ID
  • BACKUP_ID: the backup ID

HTTP method and URL:

POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup

Request JSON body:

{  backup: 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.

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

curl -X POST \
-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/instances/TARGET_INSTANCE_ID/restoreBackup"

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 POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/instances/TARGET_INSTANCE_ID/restoreBackup" | 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/instances/TARGET_INSTANCE_ID",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "RESTORE_BACKUP",  "name": "OPERATION_ID",  "targetId": "TARGET_INSTANCE_ID",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID/operations/OPERATION_ID",  "targetProject": "PROJECT_ID"}

What's next

*Learn more about backing up your data.*See how to backup your data.

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-11-24 UTC.