Restoring an Instance

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

For information about restore operations, see Overview of restoring an instance.

Restoring an instance from a backup

You can use a backup to restore the same instance the backup was taken from, or you can use a backup to restore a different instance in the same project.

Restoring to the same instance

When you restore from a backup to the same instance, you return the data on that instance to its state when you took the backup. For information about restoring an instance, see General tips about performing a restore.

Console

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

    Go to the Cloud SQL Instances page

  2. If the target instance has any read replicas, use the more actions menu More actions icon. to delete them.
  3. Click the instance you want to restore to open its Instance details page.
  4. In the Recent backups list, find the backup from which to restore and select Restore from the more actions menu More actions icon..
  5. In the Restore instance from backup dialog box, click OK to start the restore process.

    The default target instance is the same instance from which you started the restore process.

    The restore backup dialog box.

  6. You can check the status of the restore operation by going to the Operations page of the instance.
  7. After the restore operation completes, recreate any replicas you deleted in the first step.

    You cannot reuse instance names for up to a week after an instance is deleted.

gcloud

  1. Describe the instance to see whether it has any replicas:
    gcloud sql instances describe [INSTANCE_NAME]
    

    Note any instances listed under replicaNames.

  2. Delete all replicas:
    gcloud sql instances delete [REPLICA_NAME]
    

    Repeat for all replicas.

  3. List the backups for the instance:
    gcloud sql backups list --instance [INSTANCE_NAME]
    
  4. Find the backup you want to use and record its ID value.
    Be sure to select a backup that is marked as `SUCCESSFUL`.
  5. Restore the instance from the specified backup:
    gcloud sql backups restore [BACKUP_ID] --restore-instance=[INSTANCE_NAME]
  6. After the restore operation completes, recreate any replicas you deleted in the first step.

    You cannot reuse instance names for up to a week after an instance is deleted.

cURL

  1. List the backups for the instance to get the id of the backup you want to use:
    ACCESS_TOKEN="$(gcloud auth print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         -X GET \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/backupRuns
    
  2. Restore the instance from the backup:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{ "restoreBackupContext": {"backupRunId": "[BACKUP_ID]"}}' \
         -X POST \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/restoreBackup
    
  3. After the restore operation completes, recreate any replicas you deleted previously.

    You cannot reuse instance names for up to a week after an instance is deleted.

Restoring to a different instance

When you restore from a backup to a different instance, you update the data on the target instance to the state of the source instance when you took the backup. For more information, see General tips about performing a restore and Tips and requirements for restoring to a different instance.

Console

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

    Go to the Cloud SQL Instances page

  2. If the target instance has any read replicas, use the more actions menu More actions icon. to delete them.
  3. Click the source instance to open its Instance details page and select the Backups tab.
  4. Find the backup you want to restore from and select Restore from the more actions menu More actions icon..
  5. In the Restore instance from backup dialog, select the Target instance and click OK.
  6. You can check the status of the restore operation by going to the Operations tab of the target instance.
  7. After the restore operation completes, recreate any replicas you deleted previously.

    You cannot reuse instance names for up to a week after an instance is deleted.

gcloud

  1. Describe the target instance to see whether it has any replicas:
    gcloud sql instances describe [TARGET_INSTANCE_NAME]
    

    Note any instances listed under replicaNames.

  2. Delete all replicas:
    gcloud sql instances delete [REPLICA_NAME]
    

    Repeat for each replica.

  3. List the backups for the source instance:
    gcloud sql backups list --instance [SOURCE_INSTANCE_NAME]
    
  4. Find the backup you want to use and record its ID value.
    Be sure to select a backup that is marked as `SUCCESSFUL`.
  5. Restore from the specified backup to the target instance:
    gcloud sql backups restore [BACKUP_ID] --restore-instance=[TARGET_INSTANCE_NAME] \
                                              --backup-instance=[SOURCE_INSTANCE_NAME]
        
  6. After the restore completes, recreate any replicas you deleted previously.

    You cannot reuse instance names for up to a week after an instance is deleted.

cURL

  1. List all replicas for the target instance:
    ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         -X GET \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[TARGET_INSTANCE_NAME]?fields=replicaNames
    
  2. Delete all replicas:
    ACCESS_TOKEN="$(gcloud auth print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         -X DELETE \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[REPLICA_NAME]
    

    Repeat for each replica.

  3. List the backups for the source instance to get the id of the backup you want to use:
    ACCESS_TOKEN="$(gcloud auth print-access-token)"
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         -X GET \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[SOURCE_INSTANCE_NAME]/backupRuns
    
  4. Restore the target instance from the backup:
    curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
         --header 'Content-Type: application/json' \
         --data '{ "restoreBackupContext": {"backupRunId": "[BACKUP_ID]", "instanceId": "[SOURCE_INSTANCE_NAME]"}}' \
         -X POST \
         https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[TARGET_INSTANCE_NAME]/restoreBackup
    
  5. After the restore operation completes, recreate any replicas you deleted previously.

    You cannot reuse instance names for up to a week after an instance is deleted.

What's next

Send feedback about...

Cloud SQL for PostgreSQL