Restore Azure Database for PostgreSQL - Flexible servers using REST API (preview)
This article describes how to restore an Azure Database for PostgreSQL - Flexible server backed up by Azure Backup.
Prerequisites
Before you restore:
- Create a Backup vault.
- Create a PostgreSQL flexible server backup policy.
- Configure a PostgreSQL flexible server backup.
Let's use an existing Backup vault TestBkpVault
, under the resource group testBkpVaultRG
in the examples.
Restore a backed-up PostgreSQL database
Set up permissions
Backup vault uses Managed Identity to access other Azure resources. To restore from backup, Backup vault’s managed identity requires a set of permissions on the target to be restored to. To restore the recovery point as files to a storage account, Backup vault's system assigned managed identity needs access on the target storage account as mentioned here.
Fetch the relevant recovery point
To list all the available recovery points for a backup instance, use the list recovery points API.
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataProtection/backupVaults/{vaultName}/backupInstances/{backupInstanceName}/recoveryPoints?api-version=2021-07-01
For example, this API translates to:
GET https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/TestBkpVaultRG/providers/Microsoft.DataProtection/backupVaults/testBkpVault/backupInstances/pgflextestserver-857d23b1-c679-4c94-ade6-c4d34635e149/recoveryPoints?api-version=2021-07-01
Responses for the list of recovery points:
Once you submit the GET request, it returns response as 200 (OK), and the list of all discrete recovery points with all the relevant details.
Name | Type | Description |
---|---|---|
200 OK | AzureBackupRecoveryPointResourceList | OK |
Other status codes | CloudError | Error response describes the reason for the operation failure. |
Example response for list of recovery points:
HTTP/1.1 200 OK
Content-Length: 53396
Content-Type: application/json
Expires: -1
Pragma: no-cache
X-Content-Type-Options: nosniff
x-ms-request-id:
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-reads: 11999
x-ms-correlation-request-id: 41f7ef85-f31e-4db7-87ef-115e3ca65b93
x-ms-routing-request-id: SOUTHINDIA:20211022T200018Z:ba3bc1ce-c081-4895-a292-beeeb6eb22cc
Cache-Control: no-cache
Date: Fri, 22 Oct 2021 20:00:18 GMT
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
{
"value": [
{
"properties": {
"objectType": "AzureBackupDiscreteRecoveryPoint",
"recoveryPointId": "eb006fde78cb47198be5a320fbe45e9b",
"recoveryPointTime": "2021-10-21T16:31:16.8316716Z",
"recoveryPointType": "Full",
"friendlyName": "794ead7c7661410da03997d210d469e7",
"recoveryPointDataStoresDetails": [
{
"id": "9ea7eaf4-eeb8-4c8f-90a7-7f04b60bf075",
"type": "VaultStore",
"creationTime": "2021-10-21T16:31:16.8316716Z",
"expiryTime": "2022-10-21T16:31:16.8316716Z",
"metaData": null,
"visible": true,
"state": "COMMITTED",
"rehydrationExpiryTime": null,
"rehydrationStatus": null
}
],
"retentionTagName": "Default",
"retentionTagVersion": "637212748405148394",
"policyName": "osspol3",
"policyVersion": null
},
Select the relevant recovery points from the above list and proceed to prepare the restore request. We'll choose a recovery point named 794ead7c7661410da03997d210d469e7 from the above list to restore.
Prepare the restore request
Restore as files
Fetch the URI of the container, within the storage account to which permissions were assigned as detailed above. For example, a container named testcontainerrestore
under a storage account testossstorageaccount
with a different subscription.
"https://testossstorageaccount.blob.core.windows.net/testcontainerrestore"
{
"objectType": "ValidateRestoreRequestObject",
"restoreRequestObject": {
"objectType": "AzureBackupRecoveryPointBasedRestoreRequest",
"sourceDataStoreType": "VaultStore",
"restoreTargetInfo": {
"targetDetails": {
"url": "https://testossstorageaccount.blob.core.windows.net/testcontainerrestore",
"filePrefix": "testprefix",
"restoreTargetLocationType": "AzureBlobs"
},
"restoreLocation": "westus",
"recoveryOption": "FailIfExists",
"objectType": "RestoreFilesTargetInfo"
},
"recoveryPointId": "eb006fde78cb47198be5a320fbe45e9b"
}
}
Validate restore requests
Once the request body is prepared, validate it using the validate for restore API. Like validate for backup API, this is a POST operation.
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataProtection/backupVaults/{vaultName}/backupInstances/{backupInstanceName}/validateRestore?api-version=2021-07-01
For example, this API translates to:
POST "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testBkpVaultRG/providers/Microsoft.DataProtection/backupVaults/testBkpVault/backupInstances/pgflextestserver-857d23b1-c679-4c94-ade6-c4d34635e149/ValidateRestore?api-version=2021-07-01"
Learn more about the request body for this POST API.
Response to validate restore requests:
The validate restore request is an asynchronous operation. So, this operation creates another operation that you need to track separately. It returns two responses: 202 (Accepted) when another operation is created. Then 200 (OK) when that operation completes. | Name | Type | Description | | --- | --- | --- | | 200 OK | | Status of validate request | | 202 Accepted | | Accepted |
Example response to restore validate request:
Once the POST operation is submitted, it returns the initial response as 202 (Accepted) with an Azure-asyncOperation
header.
HTTP/1.1 202 Accepted
Content-Length: 0
Expires: -1
Pragma: no-cache
Retry-After: 10
Azure-AsyncOperation: https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/providers/Microsoft.DataProtection/locations/westus/operationStatus/ZmMzNDFmYWMtZWJlMS00NGJhLWE4YTgtMDNjYjI4Y2M5OTExOzVlNzMxZDBiLTQ3MDQtNDkzNS1hYmNjLWY4YWEzY2UzNTk1ZQ==?api-version=2021-07-01
X-Content-Type-Options: nosniff
x-ms-request-id:
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-correlation-request-id: bae60c92-669d-45a4-aed9-8392cca7cc8d
x-ms-routing-request-id: CENTRALUSEUAP:20210708T205935Z:f51db7a4-9826-4084-aa3b-ae640dc78af6
Cache-Control: no-cache
Date: Thu, 08 Jul 2021 20:59:35 GMT
Location: https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/providers/Microsoft.DataProtection/locations/westus/operationResults/ZmMzNDFmYWMtZWJlMS00NGJhLWE4YTgtMDNjYjI4Y2M5OTExOzVlNzMxZDBiLTQ3MDQtNDkzNS1hYmNjLWY4YWEzY2UzNTk1ZQ==?api-version=2021-07-01
X-Powered-By: ASP.NET
Track the Azure-AsyncOperation
header with a simple GET request. When the request is successful, it returns 200 (OK) with a status response.
GET https://management.azure.com/subscriptions/e3d2d341-4ddb-4c5d-9121-69b7e719485e/providers/Microsoft.DataProtection/locations/westus/operationStatus/YWJjMGRmMzQtNTY1NS00MGMyLTg4YmUtMTUyZDE3ZjdiNzMyOzY4NDNmZWZkLWU4ZTMtNDM4MC04ZTJhLWUzMTNjMmNhNjI1NA==?api-version=2021-07-01
{
"id": "/subscriptions/e3d2d341-4ddb-4c5d-9121-69b7e719485e/providers/Microsoft.DataProtection/locations/westus/operationStatus/YWJjMGRmMzQtNTY1NS00MGMyLTg4YmUtMTUyZDE3ZjdiNzMyOzY4NDNmZWZkLWU4ZTMtNDM4MC04ZTJhLWUzMTNjMmNhNjI1NA==",
"name": "YWJjMGRmMzQtNTY1NS00MGMyLTg4YmUtMTUyZDE3ZjdiNzMyOzY4NDNmZWZkLWU4ZTMtNDM4MC04ZTJhLWUzMTNjMmNhNjI1NA==",
"status": "Inprogress",
"startTime": "2021-10-22T20:22:41.0305623Z",
"endTime": "0001-01-01T00:00:00Z"
}
In case of issues, the response indicates errors that have to be solved before submitting the restore request. Once we fix the errors and revalidate the request, the 200 (OK) returns a success response.
HTTP/1.1 200 OK
Content-Length: 443
Content-Type: application/json
Expires: -1
Pragma: no-cache
X-Content-Type-Options: nosniff
x-ms-request-id:
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-reads: 11999
x-ms-correlation-request-id: 61d62dd8-8e1a-473c-bcc6-c6a7a19fb035
x-ms-routing-request-id: SOUTHINDIA:20211022T203846Z:89af04a6-4e91-4b64-8998-a369dc763408
Cache-Control: no-cache
Date: Fri, 22 Oct 2021 20:38:46 GMT
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
{
"id": "/subscriptions/e3d2d341-4ddb-4c5d-9121-69b7e719485e/providers/Microsoft.DataProtection/locations/westus/operationStatus/YWJjMGRmMzQtNTY1NS00MGMyLTg4YmUtMTUyZDE3ZjdiNzMyOzU0NDI4YzdhLTJjNWEtNDNiOC05ZjBjLTM2NmQ3ZWVjZDUxOQ==",
"name": "YWJjMGRmMzQtNTY1NS00MGMyLTg4YmUtMTUyZDE3ZjdiNzMyOzU0NDI4YzdhLTJjNWEtNDNiOC05ZjBjLTM2NmQ3ZWVjZDUxOQ==",
"status": "Succeeded",
"startTime": "2021-10-22T20:28:24.3820169Z",
"endTime": "2021-10-22T20:28:49Z"
}
Trigger restore requests
The trigger restore operation is a POST API. Learn more about the trigger restore operation.
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataProtection/backupVaults/{vaultName}/backupInstances/{backupInstanceName}/restore?api-version=2021-07-01
For example, the API translates to:
POST "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/testBkpVaultRG/providers/Microsoft.DataProtection/backupVaults/testBkpVault/backupInstances/testpostgresql-empdb11-957d23b1-c679-4c94-ade6-c4d34635e149/restore?api-version=2021-07-01"
Create a request body for restore operations
Once the requests are validated, use the same request body to trigger *restore request with minor changes.
Response to trigger restore requests:
The trigger restore request is an asynchronous operation. So, this operation creates another operation that needs to be tracked separately.
It returns two responses: 202 (Accepted) when another operation is created. Then 200 (OK) when that operation completes.
Name | Type | Description |
---|---|---|
200 OK | Status of restore request | |
202 Accepted | Accepted |
Example response to trigger restore request:
Once the POST operation is submitted, it will return the initial response as 202 (Accepted) with an Azure-asyncOperation
header.
HTTP/1.1 202 Accepted
Content-Length: 0
Expires: -1
Pragma: no-cache
Retry-After: 30
Azure-AsyncOperation: https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/providers/Microsoft.DataProtection/locations/westus/operationStatus/ZmMzNDFmYWMtZWJlMS00NGJhLWE4YTgtMDNjYjI4Y2M5OTExO2Q1NDIzY2VjLTczYjYtNDY5ZC1hYmRjLTc1N2Q0ZTJmOGM5OQ==?api-version=2021-07-01
X-Content-Type-Options: nosniff
x-ms-request-id:
Strict-Transport-Security: max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-writes: 1197
x-ms-correlation-request-id: 8661209c-5b6a-44fe-b676-4e2b9c296593
x-ms-routing-request-id: CENTRALUSEUAP:20210708T204652Z:69e3fa4b-c5d9-4601-9410-598006ada187
Cache-Control: no-cache
Date: Thu, 08 Jul 2021 20:46:52 GMT
Location: https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/providers/Microsoft.DataProtection/locations/westus/operationResults/ZmMzNDFmYWMtZWJlMS00NGJhLWE4YTgtMDNjYjI4Y2M5OTExO2Q1NDIzY2VjLTczYjYtNDY5ZC1hYmRjLTc1N2Q0ZTJmOGM5OQ==?api-version=2021-07-01
X-Powered-By: ASP.NET
Track the Azure-AsyncOperation
header with a simple GET request. When the request is successful, it will return 200 (OK) with a job ID that should be further tracked for completion of the restore request.
GET https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/providers/Microsoft.DataProtection/locations/westus/operationStatus/ZmMzNDFmYWMtZWJlMS00NGJhLWE4YTgtMDNjYjI4Y2M5OTExO2Q1NDIzY2VjLTczYjYtNDY5ZC1hYmRjLTc1N2Q0ZTJmOGM5OQ==?api-version=2021-07-01
{
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/providers/Microsoft.DataProtection/locations/westus/operationStatus/ZmMzNDFmYWMtZWJlMS00NGJhLWE4YTgtMDNjYjI4Y2M5OTExO2Q1NDIzY2VjLTczYjYtNDY5ZC1hYmRjLTc1N2Q0ZTJmOGM5OQ==",
"name": "ZmMzNDFmYWMtZWJlMS00NGJhLWE4YTgtMDNjYjI4Y2M5OTExO2Q1NDIzY2VjLTczYjYtNDY5ZC1hYmRjLTc1N2Q0ZTJmOGM5OQ==",
"status": "Succeeded",
"startTime": "2021-07-08T20:46:52.4110868Z",
"endTime": "2021-07-08T20:46:56Z",
"properties": {
"jobId": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/TestBkpVaultRG/providers/Microsoft.DataProtection/backupVaults/testBkpVault/backupJobs/c4bd49a1-0645-4eec-b207-feb818962852",
"objectType": "OperationJobExtendedInfo"
}
}
Track jobs
The trigger restore requests trigger the restore job. To track the resultant Job ID, use the GET Jobs API.
Use the GET command to track the JobId
present in the trigger restore response above.
GET /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/TestBkpVaultRG/providers/Microsoft.DataProtection/backupVaults/testBkpVault/backupJobs/c4bd49a1-0645-4eec-b207-feb818962852?api-version=2021-07-01
The job status mentioned above indicates that the restore job is complete.
Next steps
About Azure Database for PostgreSQL - Flexible server backup (preview).