이 문서에서는 Azure Database for PostgreSQL - 유연한 서버를 Azure Database for PostgreSQL - Azure Backup에서 백업하는 유연한 서버로 복원하는 방법을 설명합니다.
여기의 예에서는 리소스 그룹 testBkpVaultRG 아래의 기존 백업 자격 증명 모음 TestBkpVault를 사용해 보겠습니다.
백업된 PostgreSQL 데이터베이스 복원
권한 설정
백업 자격 증명 모음은 관리 ID를 사용하여 다른 Azure 리소스에 액세스합니다. 백업에서 복원하려면 Backup 자격 증명 모음의 관리 ID에 서버가 복원될 스토리지 계정에 대한 권한 집합이 필요합니다. 관리 ID는 스토리지 계정에 대해 Storage Blob 데이터 기여자 역할을 할당해야 합니다.
관련 복구 지점 가져오기
자격 증명 모음 내의 모든 백업 인스턴스를 나열하려면 az data protection backup-instance list 명령을 사용합니다. 그런 다음 az data protection backup-instance show 명령을 사용하여 관련 인스턴스를 가져옵니다. 또는 대규모 시나리오의 경우 az data protection backup-instance list-from-resourcegraph 명령을 사용하여 자격 증명 모음 및 구독에서 백업 인스턴스를 나열할 수 있습니다.
az dataprotection backup-instance list-from-resourcegraph --datasource-type AzureDatabaseForPostgreSQLFlexibleServer -subscriptions 00001111-aaaa-2222-bbbb-3333cccc4444
{
"datasourceId": "/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourceGroups/ossdemoRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/testpgflex",
"extendedLocation": null,
"id": "/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourceGroups/testBkpVaultRG/providers/Microsoft.DataProtection/backupVaults/testBkpVault/backupInstances/testpostgresql-empdb11-957d23b1-c679-4c94-ade6-c4d34635e149",
"identity": null,
"kind": "",
"location": "",
"managedBy": "",
"name": "testpgflex-957d23b1-c679-4c94-ade6-c4d34635e149",
"plan": null,
"properties": {
"currentProtectionState": "ProtectionConfigured",
"dataSourceInfo": {
"baseUri": null,
"datasourceType": "Microsoft.DBforPostgreSQL/flexibleServers",
"objectType": "Datasource",
"resourceID": "/subscriptions/bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f/resourceGroups/ossdemoRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/testpgflex",
"resourceLocation": "westus",
"resourceName": "postgres",
"resourceProperties": null,
"resourceType": "Microsoft.DBforPostgreSQL/flexibleServers",
"resourceUri": ""
},
"dataSourceProperties": null,
"dataSourceSetInfo": {
"baseUri": null,
"datasourceType": "Microsoft.DBforPostgreSQL/flexibleServers",
"objectType": "DatasourceSet",
"resourceID": "/subscriptions/bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f/resourceGroups/ossdemoRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/testpgflex",
"resourceLocation": "westus",
"resourceName": "testpgflex",
"resourceProperties": null,
"resourceType": "Microsoft.DBforPostgreSQL/flexibleServers",
"resourceUri": ""
},
"friendlyName": "testpgflex",
"objectType": "BackupInstance",
"policyInfo": {
"policyId": "/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourceGroups/testBkpVaultRG/providers/Microsoft.DataProtection/backupVaults/testBkpVault/backupPolicies/osspol3",
"policyParameters": null,
"policyVersion": ""
},
"protectionErrorDetails": null,
"protectionStatus": {
"errorDetails": null,
"status": "ProtectionConfigured"
},
"provisioningState": "Succeeded",
"validationType": null
},
"protectionState": "ProtectionConfigured",
"resourceGroup": "testBkpVaultRG",
"sku": null,
"subscriptionId": bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f,
"tags": null,
"tenantId": aaaabbbb-0000-cccc-1111-dddd2222eeee,
"type": "microsoft.dataprotection/backupvaults/backupinstances",
"vaultName": "testBkpVault",
"zones": null
}
.
.
.
.
.
인스턴스가 식별되면 az data protection recovery-point list 명령을 사용하여 관련 복구 지점을 가져옵니다.
az dataprotection recovery-point list --backup-instance-name testpgflex-957d23b1-c679-4c94-ade6-c4d34635e149 -g testBkpVaultRG --vault-name TestBkpVault
{
"id": "/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourceGroups/testBkpVaultRG/providers/Microsoft.DataProtection/backupVaults/testBkpVault/backupInstances/testpgflex-957d23b1-c679-4c94-ade6-c4d34635e149/recoveryPoints/9da55e757af94261afa009b43cd3222a",
"name": "9da55e757af94261afa009b43cd3222a",
"properties": {
"friendlyName": "2031fdb43a914114b6ce644eb6fcb5ce",
"objectType": "AzureBackupDiscreteRecoveryPoint",
"policyName": "oss-clitest-policy",
"policyVersion": null,
"recoveryPointDataStoresDetails": [
{
"creationTime": "2021-09-13T15:17:41.209845+00:00",
"expiryTime": null,
"id": "beddea84-7b30-42a5-a752-7c75baf96a52",
"metaData": "{\"objectType\":\"PostgresBackupMetadata\",\"version\":\"1.0\",\"postgresVersion\":\"11\",\"dbName\":\"postgres\",\"serverName\":\"testpostgresql\",\"serverFQDN\":\"testpostgresql.postgres.database.azure.com\",\"usernameUsed\":\"backupadmin@testpostgresql\",\"backupToolPath\":\"postgresql-11.6-1\\\\bin\\\\pg_dump.exe\",\"backupType\":\"Full\",\"backupDumpFormat\":\"CUSTOM\",\"backupToolArgsFormat\":\"--no-acl --no-owner --serializable-deferrable --no-tablespaces --quote-all-identifiers -Fc -d postgres://{0}:{1}@{2}:5432/{3}?sslmode=verify-full&sslrootcert=E:\\\\approot\\\\Plugins\\\\Postgres\\\\..\\\\..\\\\postgres-root.crt\",\"storageUnits\":{\"1\":\"DbBackupDumpData\"},\"streamNamesInFirstStorageUnit\":[\"dbbkpdmpdatastream-1631546260050\"],\"pitId\":\"2031fdb43a914114b6ce644eb6fcb5ce\",\"bytesTransferred\":2063,\"dataSourceSize\":8442527,\"backupToolVersion\":\"11\"}",
"rehydrationExpiryTime": null,
"rehydrationStatus": null,
"state": "COMMITTED",
"type": "VaultStore",
"visible": true
}
],
"recoveryPointId": "9da55e757af94261afa009b43cd3222a",
"recoveryPointTime": "2021-09-13T15:17:41.209845+00:00",
"recoveryPointType": "Full",
"retentionTagName": "default",
"retentionTagVersion": "637671427933449525"
},
"resourceGroup": "testBkpVaultRG",
"systemData": null,
"type": "Microsoft.DataProtection/backupVaults/backupInstances/recoveryPoints"
}
복원 요청 준비
PostgreSQL – 유연한 서버 데이터베이스의 복구 지점을 파일로만 복원할 수 있습니다.
파일로 복원
권한이 할당된 스토리지 계정 내에서 컨테이너의 URI(Uniform Resource Identifier)를 가져옵니다. 예를 들어 다른 구독을 사용하는 스토리지 계정 testossstorageaccount에서 testcontainer라는 컨테이너를 복원합니다.
$contURI = "https://testossstorageaccount.blob.core.windows.net/testcontainerrestore"
az data protection backup-instance restore initialize-for-data-recovery-as-files 명령을 사용하여 모든 관련 세부 정보를 사용하여 복원 요청을 준비합니다.
az dataprotection backup-instance restore initialize-for-data-recovery-as-files --datasource-type AzureDatabaseForPostgreSQLFlexibleServer --restore-location {location} --source-datastore VaultStore -target-blob-container-url $contURI --recovery-point-id 9da55e757af94261afa009b43cd3222a > OssRestoreAsFilesReq.JSON
JSON 파일이 새 리소스를 만드는 데 성공했는지 확인하려면 az data protection backup-instance validate-for-restore 명령을 사용합니다.
복원 트리거
az data protection backup-instance restore trigger 명령을 사용하여 이전에 준비한 요청으로 복원 작업을 트리거합니다.
az dataprotection backup-instance restore trigger -g testBkpVaultRG --vault-name TestBkpVault --backup-instance-name testpgflex-957d23b1-c679-4c94-ade6-c4d34635e149 --restore-request-object OssRestoreReq.JSON
작업 추적
az data protection job list 명령을 사용하여 모든 작업을 추적합니다. 모든 작업을 나열하고 특정 작업 세부 정보를 가져올 수 있습니다.
Az.ResourceGraph를 사용하여 모든 백업 자격 증명 모음에서 작업을 추적할 수도 있습니다. az data protection job list-from-resourcegraph 명령을 사용하여 모든 Backup 자격 증명 모음에 있는 관련 작업을 가져옵니다.
az dataprotection job list-from-resourcegraph --datasource-type AzureDatabaseForPostgreSQLFlexibleServer --operation Restore
PostgreSQL 만들기 - 복원된 스토리지 계정에서 유연한 서버
복원 완료 후 대상 스토리지 계정에 pg_restore 유틸리티를 사용하여 대상에서 Azure Database for PostgreSQL – 유연한 서버 데이터베이스를 복원할 수 있습니다. 다음 명령을 사용하여 기존 PostgreSQL – 유연한 서버 및 기존 데이터베이스에 연결합니다.
pg_restore -h <hostname> -U <username> -d <db name> -Fd -j <NUM> -C <dump directory>
-Fd: 디렉터리 형식입니다. -j: 작업 수입니다. -C: 명령으로 출력을 시작하여 데이터베이스 자체를 만든 다음 다시 연결합니다.
다음은 이 구문이 표시되는 방법의 예입니다.
pg_restore -h <hostname> -U <username> -j <Num of parallel jobs> -Fd -C -d <databasename> sampledb_dir_format
복원할 데이터베이스가 두 개 이상 있는 경우 각 데이터베이스에 대해 이전 명령을 다시 실행합니다.
또한, 여러 동시 작업 -j를 사용하면 다중 vCore 대상 서버에서 대규모 데이터베이스를 복원하는 데 걸리는 시간을 줄일 수 있습니다. 작업 수는 대상 서버에 할당된 vCPU 수와 같거나 작을 수 있습니다.