次の方法で共有


Azure CLI を使用して Azure Database for PostgreSQL - フレキシブル サーバーを復元する

この記事では、Azure CLI を使用して Azure Database for PostgreSQL - フレキシブル サーバーを復元する方法について説明します。

PaaS データベースでは、元の場所の回復 (OLR) オプションはサポートされていません。 代わりに、Alternate-Location Recovery (ALR) を使用して復旧ポイントから復元し、同じまたは別の Azure PostgreSQL - フレキシブル サーバーに新しいデータベースを作成し、ソースデータベースと復元されたデータベースの両方を保持します。

例のリソース グループ TestBkpVaultの下で、既存の Backup コンテナー testBkpVaultRGを使用してみましょう。

[前提条件]

Azure Database for PostgreSQL - フレキシブル サーバー バックアップから復元する前に、次の前提条件を確認してください。

  • 復元操作に必要なアクセス許可があることを確認します。
  • 復元のターゲット ストレージ アカウントで AllowCrossTenantReplication プロパティが true に設定されていることを確認します。

バックアップ データは、Microsoft テナント内の BLOB としてバックアップ コンテナーに保存されます。 復元操作の間に、バックアップ データはテナントをまたいで異なるストレージ アカウント間でコピーされます。

PostgreSQL のアクセス許可を設定する - フレキシブル サーバーの復元

バックアップ コンテナーは、マネージド ID を使用して他の Azure リソースにアクセスします。 バックアップから復元するには、Backup コンテナーのマネージド ID には、データベースを復元する Azure PostgreSQL - フレキシブル サーバーに対する一連のアクセス許可が必要です。

ターゲットの PostgreSQL - フレキシブル サーバーでボールトのシステム割り当てマネージド ID に関連する適切なアクセス許可を割り当てるには、Azure PostgreSQL - フレキシブル サーバー データベースをバックアップするために必要なアクセス許可のセットを確認してください。

復旧ポイントをファイルとしてストレージ アカウントに復元するには、バックアップ コンテナーのシステム割り当てマネージド ID がターゲット ストレージ アカウントにアクセスする必要があります。

PostgreSQL – フレキシブル サーバーの関連する復旧ポイントを取得する

コンテナー内のすべてのバックアップ インスタンスを一覧表示するには、 az dataprotection backup-instance list コマンドを使用します。 次に、 az dataprotection backup-instance show コマンドを使用して、関連するインスタンスをフェッチします。 または、大規模なシナリオでは、 az dataprotection backup-instance list-from-resourcegraph コマンドを使用して、コンテナーとサブスクリプション全体のバックアップ インスタンスを一覧表示できます。

az dataprotection backup-instance list-from-resourcegraph --datasource-type AzureDatabaseForPostgreSQLFlexibleServer -subscriptions "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e"

{
    "datasourceId": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/ossdemoRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/testpostgresql/databases/empdb11",
    "extendedLocation": null,
    "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/testBkpVaultRG/providers/Microsoft.DataProtection/backupVaults/testBkpVault/backupInstances/testpostgresql-empdb11-957d23b1-c679-4c94-ade6-c4d34635e149",
    "identity": null,
    "kind": "",
    "location": "",
    "managedBy": "",
    "name": "testpostgresql-empdb11-957d23b1-c679-4c94-ade6-c4d34635e149",
    "plan": null,
    "properties": {
      "currentProtectionState": "ProtectionConfigured",
      "dataSourceInfo": {
        "baseUri": null,
        "datasourceType": "Microsoft.DBforPostgreSQL/flexibleServers/databases",
        "objectType": "Datasource",
        "resourceID": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/ossdemoRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/testpostgresql/databases/empdb11",
        "resourceLocation": "westus",
        "resourceName": "postgres",
        "resourceProperties": null,
        "resourceType": "Microsoft.DBforPostgreSQL/flexibleServers/databases",
        "resourceUri": ""
      },
      "dataSourceProperties": null,
      "dataSourceSetInfo": {
        "baseUri": null,
        "datasourceType": "Microsoft.DBforPostgreSQL/flexibleServers/databases",
        "objectType": "DatasourceSet",
        "resourceID": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/ossdemoRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/testpostgresql",
        "resourceLocation": "westus",
        "resourceName": "testpostgresql",
        "resourceProperties": null,
        "resourceType": "Microsoft.DBforPostgreSQL/flexibleServers",
        "resourceUri": ""
      },
      "datasourceAuthCredentials": {
        "objectType": "SecretStoreBasedAuthCredentials",
        "secretStoreResource": {
          "secretStoreType": "AzureKeyVault",
          "uri": "https://vikottur-test.vault.azure.net/secrets/dbauth3",
          "value": null
        }
      },
      "friendlyName": "testpostgresql\\empdb11",
      "objectType": "BackupInstance",
      "policyInfo": {
        "policyId": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/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": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
    "tags": null,
    "tenantId": "aaaabbbb-0000-cccc-1111-dddd2222eeee",
    "type": "microsoft.dataprotection/backupvaults/backupinstances",
    "vaultName": "testBkpVault",
    "zones": null
  }
.
.

インスタンスが識別されたら、 az dataprotection recovery-point list コマンドを使用して関連する復旧ポイントをフェッチします。

az dataprotection recovery-point list --backup-instance-name testpostgresql-empdb11-957d23b1-c679-4c94-ade6-c4d34635e149 -g testBkpVaultRG --vault-name TestBkpVault

{
  "id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/testBkpVaultRG/providers/Microsoft.DataProtection/backupVaults/testBkpVault/backupInstances/testpostgresql-empdb11-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 - フレキシブル サーバーの復元要求を準備する

PostgreSQL – フレキシブル サーバー データベースの復旧ポイントは、ファイルとしてのみ復元できます。

ファイルとして復元

アクセス許可が割り当てられたストレージ アカウント内で、コンテナーの URI (Uniform Resource Identifier) を フェッチします。 たとえば、異なるサブスクリプションのストレージ アカウント testcontainerrestore の下にある、testossstorageaccount という名前のコンテナーです。

$contURI = "https://testossstorageaccount.blob.core.windows.net/testcontainerrestore"

az dataprotection 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 --target-file-name "empdb11_postgresql-westus_1628853549768" --recovery-point-id 9da55e757af94261afa009b43cd3222a > OssRestoreAsFilesReq.JSON

ターゲット ストレージ アカウントへの復元が完了したら、 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を使用することで、 マルチ仮想コア ターゲット サーバー上の大規模なデータベースの復元時間を短縮できます。 ジョブの数は、ターゲット サーバーに割り当てられた vCPUs の数以下にすることができます。

PostgreSQL - フレキシブル サーバーの復元をトリガーする

準備された要求で復元操作をトリガーするには、 az dataprotection backup-instance restore trigger コマンドを使用します。

az dataprotection backup-instance restore trigger -g testBkpVaultRG --vault-name TestBkpVault --backup-instance-name testpostgresql-empdb11-957d23b1-c679-4c94-ade6-c4d34635e149 --restore-request-object OssRestoreReq.JSON

PostgreSQL のジョブの追跡 - フレキシブル サーバーの復元

az dataprotection job list コマンドを使用して、すべてのジョブを追跡します。 すべてのジョブを一覧表示し、特定のジョブの詳細を取得できます。

Az.ResourceGraphを使用して、すべてのバックアップ コンテナーのジョブを追跡することもできます。 az dataprotection job list-from-resourcegraph コマンドを使用して、すべての Backup コンテナーに関連するジョブを取得します。

az dataprotection job list-from-resourcegraph --datasource-type AzureDatabaseForPostgreSQLFlexibleServer --operation Restore

次のステップ

Azure Database for PostgreSQL - フレキシブル サーバーのバックアップ操作と復元操作に関する一般的なエラーのトラブルシューティングを行います。