Restore an instance

MySQL  |  PostgreSQL  |  SQL Server

This page describes how to restore your instance from a backup.

For information, best practices, and requirements for restore operations, seeOverview of restoring an instance.

Note: This procedure restarts the instance. SeeHow long are instances shut down during restart?

Restore from an on-demand or automated backup

You can use an on-demand or automated backup for the following scenarios:

  • Restore to a different instance in the same project
  • Restore to the same instance from where the backup is taken
  • Restore to a different instance in a different project or region

If you havepoint-in-time recovery (PITR) enabled, then you can recover your instance to a specific point in time, based on the log retention settings for your instance.

Note: Point-in-time recovery is supported only for a new instance within the same project and region.

Restore to a different 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 youtook the backup. For more information, seeGeneral tips about performing a restore andTips and requirements for restoring to a different instance.

If you need a list of backups for the project and can't view them on theinstance overview page due to an outage, you can use thebackupRuns.list APIwith a wildcard (-). The wildcard option retrieves a list of all backupsacross all instances in the project. For more information, seeViewing backups during an outage.

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

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.
  3. To open theOverview page of an instance, click the instance name.
  4. From the SQL navigation menu, selectBackups.
  5. Find the backup that you want to restore from, and then clickRestore.
  6. In theRestore an instance from a backup page, confirm that you selected the correct backup inReview backup details.
  7. InChoose restore destination, selectOverwrite an existing instance.
  8. From theInstance to be overwritten menu, select the instance you want to use for the restore. The instance that you select and all of its data are overwritten.
  9. To confirm your selection, enter the name of the instance to be overwritten in theDestination instance ID field.
  10. To start the restore process, clickRestore.
  11. To check the status of the restore operation, go to theOperations page for the instance.
  12. After the restore operation completes, recreate any replicas that you deleted in this procedure.

gcloud

  1. To determine if thetarget instance has any read replicas, use thegcloud sql instances describe command:
    gcloudsqlinstancesdescribeTARGET_INSTANCE_NAME

    Note any instances that are listed in thereplicaNames column.

  2. To delete all replicas, use thegcloud sql instances delete command:
    gcloudsqlinstancesdeleteREPLICA_NAME

    Repeat for each replica.

  3. To list the backups for the source instance, use thegcloud sql backups list command:
    gcloudsqlbackupslist\--instanceSOURCE_INSTANCE_NAME
  4. Find the backup that you want to use and record itsID value.Note: Select a backup that has a status ofSUCCESSFUL.
  5. To restore the target instance from the backup, use thegcloud sql backups restore command:
    gcloudsqlbackupsrestoreBACKUP_ID\--restore-instance=TARGET_INSTANCE_NAME\--backup-instance=SOURCE_INSTANCE_NAME
  6. After the restore operation completes, recreate any replicas that you deleted in this procedure.

REST v1

  1. To determine if the instance has any read replicas and to get the IDs of these replicas, list all replicas for thetarget 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.

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

    Repeat for each replica.

  3. To get the ID of the backup that you want to use, list the backups for thesource 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/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"    }

    -OR-

    If your instance is in a region that's having an outage, then list all of the backups in a project

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

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

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID/instances/-/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/-/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/-/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"      "backupKind": "SNAPSHOT"    }
    Find the backup for the instance that you need to restore.
  4. Restore the target 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 you deleted in this procedure.

REST v1beta4

  1. To determine if the instance has any read replicas and to get the IDs of these replicas, list all replicas for thetarget 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.

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

    Repeat for each replica.

  3. To get the ID of the backup that you want to use, list the backups for thesource 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/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 target 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 you deleted in this procedure.

Restore to the same instance

When you restore data from a backup to the same instance, you return the data on thatinstance to the state of when you took the backup. For information aboutrestoring an instance, seeGeneral tips about performing a restore.

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

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.
  3. To open theOverview page of an instance, click the instance name.
  4. From the SQL navigation menu, selectBackups.
  5. Find the backup that you want to use, and then clickRestore.
  6. In theRestore an instance from a backup page, confirm that you selected the correct backup inReview backup details.
  7. InChoose restore destination, selectOverwrite the source instance.

    Check that the name of the source instance is specified in parentheses.

  8. To confirm your selection, enter the instance name in theDestination instance ID field.
  9. To start the restore process, clickRestore.
  10. To check the status of the restore operation, go to theOperations page for the instance.
  11. After the restore operation completes, recreate any replicas that you deleted in this procedure.

gcloud

  1. To determine if the instance has any read replicas, use thegcloud sql instances describe command:
    gcloudsqlinstancesdescribeINSTANCE_NAME

    Note any instances that are listed in thereplicaNames column.

  2. To delete all replicas, use thegcloud sql instances delete command:
    gcloudsqlinstancesdeleteREPLICA_NAME

    Repeat for each replica.

  3. To list the backups for the instance, use thegcloud sql backups list command:
    gcloudsqlbackupslist--instanceINSTANCE_NAME
  4. Find the backup that you want to use and record itsID value.Note: Select a backup that has a status ofSUCCESSFUL.
  5. To restore the instance from the specified backup, use thegcloud sql backups restore command:
    gcloudsqlbackupsrestoreBACKUP_ID\--restore-instance=INSTANCE_NAME
  6. After the restore operation completes, recreate any replicas that you deleted in this procedure.

REST v1

  1. To get the ID of the backup that you want to use, list the backups 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/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 instance from the specified 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"}
  3. After the restore operation completes, recreate any replicas that you deleted in this procedure.

REST v1beta4

  1. To get the ID of the backup that you want to use, list the backups 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/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 instance from the specified 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"}
  3. After the restore operation completes, recreate any replicas that you deleted in this procedure.

Restore to an instance in another project

You can use theproject parameter to restore data to an instance in adifferent project than the one where the backup was taken. When using theproject parameter, callrestoreBackup in the project and on the instance youwant to restore data to. When you restore from a backup to a different instance,you update the data on the target instance to the state of the source instancewhen you took the backup.

Permissions

The user restoring to a different project must have thecloudsql.instances.restoreBackup permission for the target projectand thecloudsql.backupRuns.get permission for the source instance.These permissions are included in theCloud SQL Admin role.

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

To restore data to an instance in a different project:

gcloud

  1. List the backups for the instance.

    gcloudsqlbackupslist--instanceINSTANCE_NAME

    ReplaceINSTANCE_NAME with the name of the instance.

  2. Find the backup you want to use and record itsID value.Note: Select a backup that's markedSUCCESSFUL.
  3. Restore data to an instance in a different project.

    gcloudsqlbackupsrestoreBACKUP_ID\--restore-instance=TARGET_INSTANCE_NAME\--backup-instance=SOURCE_INSTANCE_NAME\--backup-project=SOURCE_INSTANCE_PROJECT

    Make the following replacements:

    • BACKUP_ID: the ID of the backup. You obtained this ID earlier inthis procedure.
    • TARGET_INSTANCE_NAME: the instance in the destination project towhich you're restoring data.
    • SOURCE_INSTANCE_NAME: the instance in the source project thatcontains the data that you want to restore to the instance in the destinationproject.
    • SOURCE_INSTANCE_PROJECT: the project that contains the sourceinstance.

REST v1

To obtain thebackupId, run the following.

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

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

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"}
For more information about theproject property, seerestoreBackup

REST v1beta4

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

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"}
For more information about theproject property, seerestoreBackup

Restore from a final backup

You can use a final backup for the following scenarios:

  • Restore the final backup to a new instance
  • Restore to a new instance in a different project or region

Because you're using a final backup of a deleted instance to restore your instance, you can also use the backup to create an instance with the configuration of the deleted instance and recover your data.

Restore to a new instance

When you create an instance from a final backup, Cloud SQL uses the configuration settings of the instance from where the final backup is taken. After the instance is created, Cloud SQL restores the data to the state of when the finalbackup is taken.

Note: The instance that you create from the finalbackup has a different IP address from the instance where the final backup istaken. For information about restoring an instance, seeGeneraltips about performing a restore.

To restore data from a final backup to a newinstance, you must have thecloudsql.instances.create permission for the target project,cloudsql.instances.restoreBackup permission for the targetproject, and thecloudsql.backupRuns.get permission for the source backup.These permissions are included in theCloud SQL Adminrole.

Console

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

    Go to Cloud SQL Backups

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

  2. Click the final backup which contains data that you want to restore to a new instance.
  3. In theFinal backup dialog, clickRestore.
  4. In theRestore an instance from a backup page, confirm that you selected the correct backup inReview backup details.
  5. InChoose restore destination, selectRestore to a new instance.
  6. From theRegion menu, select the region for the new instance.
  7. In theInstance ID field, enter an ID for the new instance.
  8. To start the restore process, clickRestore.
  9. To check the status of the restore operation, go to theOperations page for the instance.

gcloud

  1. To list the final backups for thesource instance, use thegcloud sql backups list command:
    gcloudsqlbackupslist\--filter='type:FINAL instance:SOURCE_INSTANCE_NAME'
  2. Find the backup that you want to use and record itsNAME value.
  3. To restore a new instance from the specified final backup, use thegcloud sql backups restore command:
    gcloudsqlbackupsrestoreBACKUP_NAME\--restore-instance=TARGET_INSTANCE_NAME

REST v1

  1. To get the ID of the backup that you want to use, list the final backups for thesource 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/backups?filter='type:FINAL AND instance: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.

    Execute the following command:

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

    PowerShell (Windows)

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

    Execute the following command:

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

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

    You should receive a JSON response similar to the following:

    Response

    {      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "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}
  2. Restore a new instance from the specified 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

  1. To get the ID of the backup that you want to use, list the final backups for thesource 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/backups?filter='type:FINAL AND instance: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.

    Execute the following command:

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

    PowerShell (Windows)

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

    Execute the following command:

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

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

    You should receive a JSON response similar to the following:

    Response

    {      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "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}
  2. Restore a new instance from the specified 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 an existing instance

When you restore data from a final backup to an existing instance, you update the data onthe target instance to the state of the source instance when youtook the backup. For more information, seeGeneral tips about performing a restore andTips and requirements for restoring to a different instance.

If you need a list of backups for the project and can't view them on theinstance overview page because of an outage, you can use thebackupRuns.list API.

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

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.
  3. In the Google Cloud console, go to theCloud SQL Backups page.

    Go to Cloud SQL Backups

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

  4. Click the final backup which contains data that you want to restore to a different instance.
  5. In theFinal backup dialog, clickRestore.
  6. In theRestore an instance from a backup page, confirm that you selected the correct backup inReview backup details.
  7. InChoose restore destination, selectOverwrite an existing instance.
  8. From theInstance to be overwritten menu, select the instance that you want to use for the restore. The instance that you select and all of its data are overwritten.

    Note: You can select only those instances that have the same database type as the instance that you used tocreate the final backup (source instance). In addition, the selected instance must have the same or higher version than the source instance.
  9. To confirm your selection, in theDestination instance ID field, enter the name of the instance to be overwritten.
  10. To start the restore process, clickRestore.
  11. To check the status of the restore operation, go to theOperations page for the instance.
  12. After the restore operation completes, recreate any replicas that you deleted in this procedure.

gcloud

  1. To determine if thetarget instance has any read replicas, use thegcloud sql instances describe command:
    gcloudsqlinstancesdescribeTARGET_INSTANCE_NAME

    Note any instances that are listed in thereplicaNames column.

  2. To delete all replicas, use thegcloud sql instances delete command:
    gcloudsqlinstancesdeleteREPLICA_NAME

    Repeat for each replica.

  3. To list the final backups for the source instance, use thegcloud sql backups list command:
    gcloudsqlbackupslist\--filter='type:FINAL instance:SOURCE_INSTANCE_NAME'
  4. Find the backup that you want to use and record itsNAME value.Note: Select a backup that has a status ofSUCCESSFUL.
  5. To restore the target instance from the backup, use thegcloud sql backups restore command:
    gcloudsqlbackupsrestoreBACKUP_NAME\--restore-instance=TARGET_INSTANCE_NAME
  6. After the restore operation completes, recreate any replicas that you deleted in this procedure.

REST v1

  1. To determine if the instance has any read replicas and to get the IDs of these replicas, list all replicas for thetarget 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.

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

    Repeat for each replica.

  3. To get the ID of the final backup that you want to use, list the backups for thesource 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/backups?filter='type:FINAL AND instance: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.

    Execute the following command:

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

    PowerShell (Windows)

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

    Execute the following command:

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

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

    You should receive a JSON response similar to the following:

    Response

    {      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "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}
    Find the backup for the instance that you need to restore.
  4. Restore the target 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
    • 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"}
  5. After the restore operation completes, recreate any replicas that you deleted in this procedure.

REST v1beta4

  1. To determine if the instance has any read replicas and to get the IDs of these replicas, list all replicas for thetarget 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.

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

    Repeat for each replica.

  3. To get the ID of the final backup that you want to use, list the backups for thesource 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/backups?filter='type:FINAL AND instance: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.

    Execute the following command:

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

    PowerShell (Windows)

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

    Execute the following command:

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

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

    You should receive a JSON response similar to the following:

    Response

    {      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "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}
    Find the backup for the instance that you need to restore.
  4. Restore the target 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
    • 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"}
  5. After the restore operation completes, recreate any replicas that you deleted in this procedure.

Restore to an instance in another project

The user restoring data to an instance in a different project must have thecloudsql.instances.restoreBackuppermission, thecloudsql.instances.createpermission for the target project,and thecloudsql.backupRuns.getpermission for the source instance. These permissions are included in theCloud SQL Admin role.

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

To restore data to an instance in a different project:

REST v1

To obtain thebackupId for the final backup, 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/backups?filter='type:FINAL AND instance: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.

Execute the following command:

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

PowerShell (Windows)

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

Execute the following command:

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

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

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "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 the backup to an instance in 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"}
For more information about theproject property, seerestoreBackup

REST v1beta4

To obtain thebackupId for the final backup, 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/backups?filter='type:FINAL AND instance: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.

Execute the following command:

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

PowerShell (Windows)

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

Execute the following command:

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

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

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "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 the backup to an instance in 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"}
For more information about theproject property, seerestoreBackup

Restore to a new instance in another region

The user restoring data to a new instance in a different region must have thecloudsql.instances.restoreBackup permission for the target projectand thecloudsql.backupRuns.get permission for the source instance.These permissions are included in theCloud SQL Admin role.

Also, to create an instance in a different region, you must meet the criteria of theorganization policies for that region.

To restore data to a new instance in a different region:

gcloud

  1. To list the final backups for thesource instance, use thegcloud sql backups list command:
    gcloudsqlbackupslist\--filter='type:FINAL instance:SOURCE_INSTANCE_NAME'
  2. Find the backup that you want to use and record itsNAME value.
  3. To use the final backup to restore data to a new instance in a different region, use thegcloud sql backups restore command:
    gcloudsqlbackupsrestoreBACKUP_NAME\--restore-instance=TARGET_INSTANCE_NAME\--region=TARGET_REGION

REST v1

To obtain thebackupId for the final backup, 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/backups?filter='type:FINAL AND instance: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.

Execute the following command:

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

PowerShell (Windows)

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

Execute the following command:

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

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

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "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 the backup to a new instance in a different region:

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
  • REGION: the region for the target instance (for example,us-central1)

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: {    region:REGION  }}

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"}
For more information about theproject property, seerestoreBackup

REST v1beta4

To obtain thebackupId for the final backup, 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/backups?filter='type:FINAL AND instance: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.

Execute the following command:

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

PowerShell (Windows)

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

Execute the following command:

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

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

You should receive a JSON response similar to the following:

Response

{      "name": "projects/PROJECT_ID/backups/BACKUP_ID",      "kind": "sql#backup",      "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 the backup to a new instance in a different region:

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
  • REGION: the region for the target instance (for example,us-central1)

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: {    region:REGION  }}

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"}
For more information about theproject property, seerestoreBackup

Restore from a retained backup

You can use aretained backupfor the following scenarios:

  • Restore the retained backup to a new instance
  • Restore the retained backup to an existing instance
  • Restore to a new or existing instance in a different project or region

Because you're using a retained backup of a deleted instance torestore your instance, you can also use the backup to create an instance withthe configuration of the deleted instance and recover your data.

Note: The instance that you create from the retained backup has a different IPaddress from the instance where the retained backup is taken. For informationabout restoring an instance, seeGeneral tips about performing a restore.

Restore a retained backup to a new instance

When you create a new instance from a retained backup, Cloud SQL uses theconfiguration settings of the instance from where the retained backup was taken.

To restore data from a retained backup to a newinstance, you must have thecloudsql.instances.createpermission.

Console

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

    Go to Cloud SQL Backups

  2. Click on the name of the deleted instance that contains the backupyou want to restore.

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

  4. On theRestore an instance from a backup page, confirm that youselected the correct backup inReview backup details.

  5. InChoose restore destination, selectRestore to a new instance.

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

  7. In theInstance ID field, enter an ID for the new instance.

  8. ClickRestore.

    Cloud SQL will restore the backup to a new instance. To checkthe status of the restore operation, go to theOperations pagefor the instance.

gcloud

  1. Usegcloud sql backups listto find the backup you want to store to a new instance.

    gcloud sql backups list--project=PROJECT_ID

    Replace the following:

    • PROJECT_ID: the ID of your Google Cloud project.
  2. Find the backup you want to use and record itsBACKUP_NAME value.

  3. To restore to a new instance, use thegcloud sql backups restorecommand:

    gcloud sql backups restoreBACKUP_NAME--restore-instance=TARGET_INSTANCE_NAME

    Replace the following:

    • BACKUP_NAME: the name of the retained backupyou want to restore.

    • TARGET_INSTANCE_NAME: the name of the newinstance you want to restore the backup to.

REST v1

Restore a new instance from the specified retained 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 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 a retained backup to an existing instance

When you restore data from a retained backup to an existing instance, you updatethe data on the target instance to the state of the source instance when youtook the backup.

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

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 moreactions menuMore actions icon. to delete them. All replicas mustbe deleted before you can restore the retained backup to the existinginstance.

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

    Go to Cloud SQL Backups

  4. Click on the name of the deleted instance that contains the backupyou want to restore.

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

  6. On theRestore an instance from a backup page, confirm that youselected the correct backup inReview backup details.

  7. InChoose restore destination, selectOverwrite an existing instance.

  8. From theInstance to be overwritten menu, select the instance thatyou want to use for the restore. The instance you select and all itsdata will be overwritten.

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

  10. ClickRestore.

    Cloud SQL will restore the backup to a new instance. To checkthe status of the restore operation, go to theOperations pagefor the instance.

    You can create any replicas once the restore operation completes.

gcloud

  1. Determine if the target instance has 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.
  2. 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 that you want to delete.

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

  3. Usegcloud sql backups listto find the backup you want to store to a new instance.

    gcloud sql backups list--project=PROJECT_ID

    Replace the following:

    • PROJECT_ID: the ID of your Google Cloud project.
  4. Find the backup you want to use and record itsBACKUP_NAME value.

  5. To restore to a new instance, use thegcloud sql backups restorecommand:

    gcloud sql backups restoreBACKUP_NAME--restore-instance=TARGET_INSTANCE_NAME

    Replace the following:

    • BACKUP_NAME: the name of the retained backupyou want to restore.

    • TARGET_INSTANCE_NAME: the name of the newinstance you want to restore the backup to.

    Once the restore operation is complete, recreate any replicas thatwere deleted.

REST v1

  1. To determine if the instance has any read replicas and to get the IDs ofthese replicas, list all replicas for the target 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 of the target 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 retained backup that you want to restore.

    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 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. To determine if the instance has any read replicas, and to get the IDs ofthese replicas, list all replicas for the target 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 of the target 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 retained backup that you want to restore.

    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 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 an instance in another project

To restore an instance using a retained backup in a different project,you must have the following permissions:

You can restore to another project usinggcloud CLI orthe Cloud SQL API only.

gcloud

  1. Usegcloud sql backups listto find the backup you want to store to a new instance.

    gcloud sql backups list--project=PROJECT_ID

    Replace the following:

    • PROJECT_ID: the ID of your Google Cloud project.
  2. Find the backup you want to use and record itsBACKUP_NAME value.

  3. To restore to a new instance, use thegcloud sql backups restorecommand:

    gcloud sql backups restoreBACKUP_ID--restore-instance=TARGET_INSTANCE_NAME

    Replace the following:

    • BACKUP_ID: the name of the retained backupyou want to restore.

    • TARGET_INSTANCE_NAME: the name of the newinstance located in the target project you want to restore thebackup to.

REST v1

To get thebackupID for the retained 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 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"}

Restore to an instance in another region

To restore an instance using a retained backup in a different region,you must have the following permissions:

You can restore to another region usinggcloud CLI orthe Cloud SQL API only. Your target region must meet theorganization policies forthe region.

gcloud

  1. Usegcloud sql backups listto find the backup you want to store to a new instance.

    gcloud sql backups list--project=PROJECT_ID

    Replace the following:

    • PROJECT_ID: the ID of your Google Cloud project.
  2. Find the backup you want to use and record itsNAME value.

  3. To restore to a new instance, use thegcloud sql backups restorecommand:

    gcloudsqlbackupsrestoreBACKUP_ID--restore-instance=TARGET_INSTANCE_NAME--region=TARGET_REGION

    Replace the following:

    • BACKUP_ID: the name of the retained backupyou want to restore.

    • TARGET_INSTANCE_NAME: the name of the newinstance located in the target project you want to restore thebackup to.

    • TARGET_REGION: the new region you want torestore the backup to.

REST v1

To get thebackupID for the retained 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
  • REGION: the region for the target instance (for example,us-central1)

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: {    region:REGION  }}

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 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
  • REGION: the region for the target instance (for example,us-central1)

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: {    region:REGION  }}

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

Perform a point-in-time recovery

To perform a point-in-time recovery, seePoint-in-time recovery.

What's next

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

Last updated 2025-07-14 UTC.