This page describes how to restore your instance from a backup.
For information, best practices, and requirements for restore operations, see
Overview of restoring an instance .
Restore 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.
Restore 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 .
If you need a list of backups for the project and can't view them on the
instance overview page due to an outage, you can use the backupRuns.list
API
with a wildcard (-
). The wildcard option retrieves a list of all backups
across all instances in the project. For more information, see
Viewing backups during an outage .
Warning: The restore process overwrites all the current
data on the instance, including previous point-in-time recovery logs.
Overwritten data cannot be recovered.
Console
In the Google Cloud console, go to the Cloud SQL Instances page.
Go to Cloud SQL Instances
If the target instance has any read replicas,
use the more actions menu on the far right side
to delete them.
To open the Overview page of an instance, click the instance name.
Select Backups from the SQL navigation menu.
Find the backup you want to restore from, and select Restore .
In the Restore an instance from a backup page, confirm that you selected the correct backup in Review backup details .
In Choose restore destination , select Overwrite an
existing instance .
From the Instance drop-down menu, select the instance you want
to use for the restore. The instance that you select and all of its data are overwritten.
To confirm your selection, enter the name of the instance to be overwritten in the Destination instance ID field.
To start the restore process, click Restore .
Check the status of the restore operation by going to the
Operations tab of the target instance.
After the restore operation completes, recreate any replicas you deleted
previously.
gcloud
Describe the target instance to see whether it has any replicas:
gcloud sql instances describe TARGET_INSTANCE_NAME
Note any instances listed in replicaNames
.
Delete all replicas:
gcloud sql instances delete REPLICA_NAME
Repeat for each replica.
List the backups for the source instance:
gcloud sql backups list \
--instance SOURCE_INSTANCE_NAME
Find the backup you want to use and record its ID
value.
Note: Select a backup that is marked
SUCCESSFUL
.
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
After the restore completes, recreate any replicas you deleted previously.
REST v1
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/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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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 "
]
}
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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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.
List the backups for the source instance to get the ID of the
backup you want to use.
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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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 is having an outage, list all 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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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 you need to restore.
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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud auth list
.
Save the request body in a file named request.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)
Save the request body in a file named request.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 "
}
After the restore operation completes, recreate any replicas you deleted
previously.
REST v1beta4
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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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 "
]
}
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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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.
List the backups for the source instance to get the ID of the
backup you want to use.
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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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 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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud auth list
.
Save the request body in a file named request.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)
Save the request body in a file named request.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 "
}
After the restore operation completes, recreate any replicas you deleted
previously.
Restore to the same instance
When you restore from a backup to the same instance, you return the data on that
instance to the state of when you took the backup. For information about
restoring an instance, see
General tips about performing a restore .
Warning: The restore process overwrites all the current data on the
instance, including previous point-in-time recovery logs. Overwritten data
cannot be recovered. This restore process is not recommended for production.
Console
In the Google Cloud console, go to the Cloud SQL Instances page.
Go to Cloud SQL Instances
If the target instance has any read replicas,
use the more actions menu at the far right side
to delete them.
To open the Overview page of an instance, click the instance name.
Select Backups from the SQL navigation menu.
Find the backup you want to use, and select Restore .
In the Restore an instance from a backup page, confirm that you selected the correct backup in Review backup details .
In Choose restore destination , select Overwrite the
source instance .
Check that the name of the source instance
is specified in
parentheses.
To confirm your selection, enter the instance name in the Destination instance ID field.
To start the restore process, click Restore .
Check the status of the restore operation by going to the
Operations page of the instance.
After the restore operation completes, recreate any replicas you deleted in the first step.
gcloud
Describe the instance to see whether it has any replicas:
gcloud sql instances describe INSTANCE_NAME
Note any instances listed in replicaNames
.
Delete all replicas:
gcloud sql instances delete REPLICA_NAME
Repeat for all replicas.
List the backups for the instance:
gcloud sql backups list --instance INSTANCE_NAME
Find the backup you want to use and record its ID
value.
Note: Select a backup that is marked
SUCCESSFUL
.
Restore the instance from the specified backup:
gcloud sql backups restore BACKUP_ID \
--restore-instance= INSTANCE_NAME
After the restore operation completes, recreate any replicas you deleted in
the first step.
REST v1
List the backups for the instance to get the id of the backup you
want to use.
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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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 instance from the backup.
Before using any of the request data,
make the following replacements:
project-id : The project ID
instance-id : The instance ID
backup-id The backup ID
HTTP method and URL:
POST https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /restoreBackup
Request JSON body:
{
"restoreBackupContext":
{
"backupRunId": "backup-id ",
}
}
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Note:
The following command assumes that you have logged in to
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud auth list
.
Save the request body in a file named request.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)
Save the request body in a file named request.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 "
}
After the restore operation completes, recreate any replicas you deleted
previously.
REST v1beta4
List the backups for the instance to get the id of the backup you
want to use.
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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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 instance from the backup.
Before using any of the request data,
make the following replacements:
project-id : The project ID
instance-id : The instance ID
backup-id The backup ID
HTTP method and URL:
POST https://sqladmin.googleapis.com/sql/v1beta4/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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud auth list
.
Save the request body in a file named request.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)
Save the request body in a file named request.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/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 "
}
After the restore operation completes, recreate any replicas you deleted
previously.
Restore to an instance in another project
You can use the project
parameter to restore data to an instance in a
different project than the one where the backup was taken. When using the
project
parameter, call restoreBackup
in the project and on the instance you
want 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 instance
when you took the backup.
Permissions
The user restoring to a different project must have the
cloudsql.instances.restoreBackup
permission for the target project
and the cloudsql.backupRuns.get
permission for the source instance.
These permissions are included in the Cloud SQL Admin
role.
Warning: The restore process overwrites all the current
data on the instance, including previous point-in-time recovery logs.
Overwritten data cannot be recovered.
To restore data to an instance in a different project:
REST v1
To obtain the backupId
, run the following.
Before using any of the request data,
make the following replacements:
project-id : The project ID
instance-id : The instance ID
HTTP method and URL:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /backupRuns
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Note:
The following command assumes that you have logged in to
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud auth list
.
Save the request body in a file named request.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)
Save the request body in a file named request.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 the project
property, see
restoreBackup
REST v1beta4
To obtain the backupId
, 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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud 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)
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
the gcloud
CLI with your user account by running
gcloud init
or
gcloud auth login
, or by using Cloud Shell ,
which automatically logs you into the gcloud
CLI
.
You can check the currently active account by running
gcloud auth list
.
Save the request body in a file named request.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)
Save the request body in a file named request.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 the project
property, see
restoreBackup
Perform a point-in-time recovery
To perform a point-in-time recovery, see Point-in-time recovery .
What's next