[Oracle Cloud] Autonomous Database ) バックアップベースのディザスタ・リカバリのスイッチオーバーをcli/APIで実施してみた。 (2024/03/24)

# はじめに

Autonomous Database ディザスタ・リカバリのオプションとして、これまでのAutonomous Data Guardに加えて、バックアップベースのディザスタ・リカバリが可能です。
以前の記事 では、環境作成とWebコンソールでのスイッチオーバー実施したので、今回は、oci cli と API（Python）を使ってスイッチオーバーを実施してみました。

# 前提条件

- クロスリージョン・バックアップベースのディザスタ・リカバリ・ピアを作成
- oci cli のセットアップ ( oci setup config )/ 両リージョンのプロファイルを準備

# oci cli でのスイッチオーバー
コマンドは、oci db autonomous-database switchover を使用します。
オプションに、

- --autonomous-database-id ：スタンバイ側のAutonomous DatabaseのOCID
- --peer-db-id ： プライマリ側のAutonomous DatabaseのOCID
- --profile ： スタンバイ側リージョンの profile を指定

### 実行例
プライマリリージョン：東京
スタンバイリージョン：大阪

```
$ oci db autonomous-database switchover --autonomous-database-id ocid1.autonomousdatabase.oc1.ap-osaka-1.XXXXXX --peer-db-id ocid1.autonomousdatabase.oc1.ap-tokyo-1.XXXXXX --profile osaka
```

```
{
  "data": {
    "actual-used-data-storage-size-in-tbs": 0.0,
    "allocated-storage-size-in-tbs": 0.001953125,
    "apex-details": {
      "apex-version": null,
      "ords-version": "23.4.1.038.1857"
    },
    "are-primary-whitelisted-ips-used": null,
    "autonomous-container-database-id": null,
    "autonomous-maintenance-schedule-type": "REGULAR",
    "available-upgrade-versions": [],
    "backup-config": {
      "manual-backup-bucket-name": null,
      "manual-backup-type": "NONE"
    },
    "backup-retention-period-in-days": 60,
    "character-set": "AL32UTF8",
    "compartment-id": "ocid1.compartment.oc1..aaaaaaaa",
    "compute-count": 2.0,
    "compute-model": "ECPU",
    "connection-strings": {
      "all-connection-strings": {
        "HIGH": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_high.adb.oraclecloud.com",
        "LOW": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_low.adb.oraclecloud.com",
        "MEDIUM": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_medium.adb.oraclecloud.com",
        "TP": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_tp.adb.oraclecloud.com",
        "TPURGENT": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_tpurgent.adb.oraclecloud.com"
      },
      "dedicated": null,
      "high": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_high.adb.oraclecloud.com",
      "low": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_low.adb.oraclecloud.com",
      "medium": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_medium.adb.oraclecloud.com",
      "profiles": [
        {
          "consumer-group": "HIGH",
          "display-name": "a16kecvr5gbqpvsh_high",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "SERVER",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "LOW",
          "display-name": "a16kecvr5gbqpvsh_low",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "SERVER",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_low.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "MEDIUM",
          "display-name": "a16kecvr5gbqpvsh_medium",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "SERVER",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_medium.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "TP",
          "display-name": "a16kecvr5gbqpvsh_tp",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "SERVER",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_tp.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "TPURGENT",
          "display-name": "a16kecvr5gbqpvsh_tpurgent",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "SERVER",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_tpurgent.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "HIGH",
          "display-name": "a16kecvr5gbqpvsh_high",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "MUTUAL",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "LOW",
          "display-name": "a16kecvr5gbqpvsh_low",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "MUTUAL",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_low.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "MEDIUM",
          "display-name": "a16kecvr5gbqpvsh_medium",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "MUTUAL",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_medium.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "TP",
          "display-name": "a16kecvr5gbqpvsh_tp",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "MUTUAL",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_tp.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "TPURGENT",
          "display-name": "a16kecvr5gbqpvsh_tpurgent",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "MUTUAL",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_tpurgent.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        }
      ]
    },
    "connection-urls": {
      "apex-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/ords/apex",
      "database-transforms-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/odi/",
      "graph-studio-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/graphstudio/",
      "machine-learning-notebook-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/oml/",
      "machine-learning-user-management-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/omlusers/",
      "mongo-db-url": null,
      "ords-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/ords/",
      "sql-dev-web-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/ords/sql-developer"
    },
    "cpu-core-count": 0,
    "customer-contacts": null,
    "data-safe-status": "NOT_REGISTERED",
    "data-storage-size-in-gbs": 20,
    "data-storage-size-in-tbs": null,
    "database-edition": "STANDARD_EDITION",
    "database-management-status": null,
    "dataguard-region-type": "REMOTE_STANDBY_DG_REGION",
    "db-name": "A16KECVR5GBQPVSH",
    "db-tools-details": [
      {
        "compute-count": null,
        "is-enabled": true,
        "max-idle-time-in-minutes": null,
        "name": "APEX"
      },
      {
        "compute-count": 2.0,
        "is-enabled": true,
        "max-idle-time-in-minutes": 10,
        "name": "DATA_TRANSFORMS"
      },
      {
        "compute-count": null,
        "is-enabled": true,
        "max-idle-time-in-minutes": null,
        "name": "DATABASE_ACTIONS"
      },
      {
        "compute-count": 2.0,
        "is-enabled": true,
        "max-idle-time-in-minutes": 240,
        "name": "GRAPH_STUDIO"
      },
      {
        "compute-count": null,
        "is-enabled": false,
        "max-idle-time-in-minutes": null,
        "name": "MONGODB_API"
      },
      {
        "compute-count": 2.0,
        "is-enabled": true,
        "max-idle-time-in-minutes": 60,
        "name": "OML"
      },
      {
        "compute-count": null,
        "is-enabled": true,
        "max-idle-time-in-minutes": null,
        "name": "ORDS"
      }
    ],
    "db-version": "19c",
    "db-workload": "OLTP",
    "defined-tags": {},
    "disaster-recovery-region-type": "REMOTE",
    "display-name": "ATP_Remote",
    "failed-data-recovery-in-seconds": null,
    "freeform-tags": {},
    "id": "ocid1.autonomousdatabase.oc1.ap-osaka-1.XXXXXX",
    "in-memory-area-in-gbs": null,
    "in-memory-percentage": null,
    "infrastructure-type": null,
    "is-access-control-enabled": null,
    "is-auto-scaling-enabled": true,
    "is-auto-scaling-for-storage-enabled": false,
    "is-data-guard-enabled": false,
    "is-dedicated": false,
    "is-dev-tier": null,
    "is-free-tier": false,
    "is-local-data-guard-enabled": false,
    "is-mtls-connection-required": false,
    "is-preview": false,
    "is-reconnect-clone-enabled": null,
    "is-refreshable-clone": null,
    "is-remote-data-guard-enabled": false,
    "key-history-entry": [
      {
        "id": "ORACLE_MANAGED_KEY",
        "kms-key-version-id": null,
        "time-activated": "2024-03-24T00:03:02.233000+00:00",
        "vault-id": null
      }
    ],
    "key-store-id": null,
    "key-store-wallet-name": null,
    "kms-key-id": "ORACLE_MANAGED_KEY",
    "kms-key-lifecycle-details": null,
    "kms-key-version-id": null,
    "license-model": "BRING_YOUR_OWN_LICENSE",
    "lifecycle-details": null,
    "lifecycle-state": "ROLE_CHANGE_IN_PROGRESS",
    "local-adg-auto-failover-max-data-loss-limit": null,
    "local-disaster-recovery-type": "BACKUP_BASED",
    "local-standby-db": null,
    "long-term-backup-schedule": null,
    "memory-per-oracle-compute-unit-in-gbs": null,
    "ncharacter-set": "AL16UTF16",
    "net-services-architecture": null,
    "next-long-term-backup-time-stamp": null,
    "nsg-ids": null,
    "ocpu-count": null,
    "open-mode": "READ_WRITE",
    "operations-insights-status": "NOT_ENABLED",
    "peer-db-ids": [
      "ocid1.autonomousdatabase.oc1.ap-tokyo-1.XXXXXX"
    ],
    "permission-level": "UNRESTRICTED",
    "private-endpoint": "ozq5op1c.adb.ap-osaka-1.oraclecloud.com",
    "private-endpoint-ip": "10.0.0.188",
    "private-endpoint-label": "ozq5op1c",
    "provisionable-cpus": null,
    "refreshable-mode": null,
    "refreshable-status": null,
    "remote-disaster-recovery-configuration": {
      "disaster-recovery-type": "BACKUP_BASED",
      "is-replicate-automatic-backups": null,
      "is-snapshot-standby": null,
      "time-snapshot-standby-enabled-till": null
    },
    "resource-pool-leader-id": null,
    "resource-pool-summary": {
      "is-disabled": true,
      "pool-size": null
    },
    "role": "BACKUP_COPY",
    "scheduled-operations": null,
    "service-console-url": null,
    "source-id": "ocid1.autonomousdatabase.oc1.ap-tokyo-1.XXXXXX",
    "standby-db": null,
    "standby-whitelisted-ips": null,
    "subnet-id": "ocid1.subnet.oc1.ap-osaka-1.aaaaaaaasoopiguu5kxcuhjxjafory65cijv5mchfxajnevf3jgvtzgnvtha",
    "supported-regions-to-clone-to": [
      "KIX",
      "NRT"
    ],
    "system-tags": {},
    "time-created": "2024-03-24T00:03:39.447000+00:00",
    "time-data-guard-role-changed": "2024-03-24T00:12:49.004000+00:00",
    "time-deletion-of-free-autonomous-database": null,
    "time-disaster-recovery-role-changed": "2024-03-24T00:12:49.004000+00:00",
    "time-local-data-guard-enabled": null,
    "time-maintenance-begin": "2024-03-30T19:00:00+00:00",
    "time-maintenance-end": "2024-03-30T21:00:00+00:00",
    "time-of-joining-resource-pool": null,
    "time-of-last-failover": null,
    "time-of-last-refresh": null,
    "time-of-last-refresh-point": null,
    "time-of-last-switchover": null,
    "time-of-next-refresh": null,
    "time-reclamation-of-free-autonomous-database": null,
    "time-until-reconnect-clone-enabled": null,
    "total-backup-storage-size-in-gbs": 14.0,
    "used-data-storage-size-in-gbs": null,
    "used-data-storage-size-in-tbs": 1,
    "vault-id": null,
    "whitelisted-ips": null
  },
  "etag": "5aa868ee",
  "opc-work-request-id": "ocid1.coreservicesworkrequest.oc1.ap-osaka-1.abyhqljs3iaho2af6y7uulwxk6llqgvv2zujszgfradq7gjty4oqgvp7yf5a"
}
```

#### スイッチバック
コマンドは、oci db autonomous-database switchover を使用します。
オプションに、

- --autonomous-database-id ：スタンバイ側のAutonomous DatabaseのOCID(東京)
- --peer-db-id ： プライマリ側のAutonomous DatabaseのOCID(大阪)
- --profile ： スタンバイ側リージョンの profile を指定(東京)

```
$ oci db autonomous-database switchover --autonomous-database-id ocid1.autonomousdatabase.oc1.ap-tokyo-1.XXXXXX --peer-db-id ocid1.autonomousdatabase.oc1.ap-osaka-1.XXXXXX --profile tokyo
```


# API でのスイッチオーバー
APIは、database_client.switchover_autonomous_database を使用します。
オプションに、
autonomous_database_id ：スタンバイ側のAutonomous DatabaseのOCID
peer_db_id ： プライマリ側のAutonomous DatabaseのOCID
スタンバイ側のリージョンに対して実行します。

```tokyo2osaka.py
import oci
config = oci.config.from_file()

database_client = oci.database.DatabaseClient(config)

switchover_autonomous_database_response = database_client.switchover_autonomous_database(
autonomous_database_id="ocid1.autonomousdatabase.oc1.ap-osaka-1.XXXXXX",
     peer_db_id="ocid1.autonomousdatabase.oc1.ap-tokyo-1.XXXXXX")

print(switchover_autonomous_database_response.data) 
```


### 実行例
プライマリリージョン：東京
スタンバイリージョン：大阪

```
$ python tokyo2osaka.py

{
  "data": {
    "actual-used-data-storage-size-in-tbs": 0.0,
    "allocated-storage-size-in-tbs": 0.001953125,
    "apex-details": {
      "apex-version": null,
      "ords-version": "23.4.1.038.1857"
    },
    "are-primary-whitelisted-ips-used": null,
    "autonomous-container-database-id": null,
    "autonomous-maintenance-schedule-type": "REGULAR",
    "available-upgrade-versions": [],
    "backup-config": {
      "manual-backup-bucket-name": null,
      "manual-backup-type": "NONE"
    },
    "backup-retention-period-in-days": 60,
    "character-set": "AL32UTF8",
    "compartment-id": "ocid1.compartment.oc1..aaaaaaaanf3vpw3dxudtgpcdzgcwsne4rytolxifp26ggybnfxngd6agejka",
    "compute-count": 2.0,
    "compute-model": "ECPU",
    "connection-strings": {
      "all-connection-strings": {
        "HIGH": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_high.adb.oraclecloud.com",
        "LOW": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_low.adb.oraclecloud.com",
        "MEDIUM": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_medium.adb.oraclecloud.com",
        "TP": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_tp.adb.oraclecloud.com",
        "TPURGENT": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_tpurgent.adb.oraclecloud.com"
      },
      "dedicated": null,
      "high": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_high.adb.oraclecloud.com",
      "low": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_low.adb.oraclecloud.com",
      "medium": "adb.ap-osaka-1.oraclecloud.com:1522/g2b790413f0a7c4_a16kecvr5gbqpvsh_medium.adb.oraclecloud.com",
      "profiles": [
        {
          "consumer-group": "HIGH",
          "display-name": "a16kecvr5gbqpvsh_high",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "SERVER",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "LOW",
          "display-name": "a16kecvr5gbqpvsh_low",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "SERVER",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_low.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "MEDIUM",
          "display-name": "a16kecvr5gbqpvsh_medium",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "SERVER",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_medium.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "TP",
          "display-name": "a16kecvr5gbqpvsh_tp",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "SERVER",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_tp.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "TPURGENT",
          "display-name": "a16kecvr5gbqpvsh_tpurgent",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "SERVER",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1521)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_tpurgent.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "HIGH",
          "display-name": "a16kecvr5gbqpvsh_high",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "MUTUAL",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "LOW",
          "display-name": "a16kecvr5gbqpvsh_low",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "MUTUAL",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_low.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "MEDIUM",
          "display-name": "a16kecvr5gbqpvsh_medium",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "MUTUAL",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_medium.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "TP",
          "display-name": "a16kecvr5gbqpvsh_tp",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "MUTUAL",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_tp.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        },
        {
          "consumer-group": "TPURGENT",
          "display-name": "a16kecvr5gbqpvsh_tpurgent",
          "host-format": "FQDN",
          "is-regional": null,
          "protocol": "TCPS",
          "session-mode": "DIRECT",
          "syntax-format": "LONG",
          "tls-authentication": "MUTUAL",
          "value": "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=ozq5op1c.adb.ap-osaka-1.oraclecloud.com))(connect_data=(service_name=g2b790413f0a7c4_a16kecvr5gbqpvsh_tpurgent.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
        }
      ]
    },
    "connection-urls": {
      "apex-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/ords/apex",
      "database-transforms-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/odi/",
      "graph-studio-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/graphstudio/",
      "machine-learning-notebook-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/oml/",
      "machine-learning-user-management-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/omlusers/",
      "mongo-db-url": null,
      "ords-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/ords/",
      "sql-dev-web-url": "https://ozq5op1c.adb.ap-osaka-1.oraclecloudapps.com/ords/sql-developer"
    },
    "cpu-core-count": 0,
    "customer-contacts": null,
    "data-safe-status": "NOT_REGISTERED",
    "data-storage-size-in-gbs": 20,
    "data-storage-size-in-tbs": null,
    "database-edition": "STANDARD_EDITION",
    "database-management-status": null,
    "dataguard-region-type": "REMOTE_STANDBY_DG_REGION",
    "db-name": "A16KECVR5GBQPVSH",
    "db-tools-details": [
      {
        "compute-count": null,
        "is-enabled": true,
        "max-idle-time-in-minutes": null,
        "name": "APEX"
      },
      {
        "compute-count": 2.0,
        "is-enabled": true,
        "max-idle-time-in-minutes": 10,
        "name": "DATA_TRANSFORMS"
      },
      {
        "compute-count": null,
        "is-enabled": true,
        "max-idle-time-in-minutes": null,
        "name": "DATABASE_ACTIONS"
      },
      {
        "compute-count": 2.0,
        "is-enabled": true,
        "max-idle-time-in-minutes": 240,
        "name": "GRAPH_STUDIO"
      },
      {
        "compute-count": null,
        "is-enabled": false,
        "max-idle-time-in-minutes": null,
        "name": "MONGODB_API"
      },
      {
        "compute-count": 2.0,
        "is-enabled": true,
        "max-idle-time-in-minutes": 60,
        "name": "OML"
      },
      {
        "compute-count": null,
        "is-enabled": true,
        "max-idle-time-in-minutes": null,
        "name": "ORDS"
      }
    ],
    "db-version": "19c",
    "db-workload": "OLTP",
    "defined-tags": {},
    "disaster-recovery-region-type": "REMOTE",
    "display-name": "ATP_Remote",
    "failed-data-recovery-in-seconds": null,
    "freeform-tags": {},
    "id": "ocid1.autonomousdatabase.oc1.ap-osaka-1.XXXXXX",
    "in-memory-area-in-gbs": null,
    "in-memory-percentage": null,
    "infrastructure-type": null,
    "is-access-control-enabled": null,
    "is-auto-scaling-enabled": true,
    "is-auto-scaling-for-storage-enabled": false,
    "is-data-guard-enabled": false,
    "is-dedicated": false,
    "is-dev-tier": null,
    "is-free-tier": false,
    "is-local-data-guard-enabled": false,
    "is-mtls-connection-required": false,
    "is-preview": false,
    "is-reconnect-clone-enabled": null,
    "is-refreshable-clone": null,
    "is-remote-data-guard-enabled": false,
    "key-history-entry": [
      {
        "id": "ORACLE_MANAGED_KEY",
        "kms-key-version-id": null,
        "time-activated": "2024-03-24T00:03:02.233000+00:00",
        "vault-id": null
      }
    ],
    "key-store-id": null,
    "key-store-wallet-name": null,
    "kms-key-id": "ORACLE_MANAGED_KEY",
    "kms-key-lifecycle-details": null,
    "kms-key-version-id": null,
    "license-model": "BRING_YOUR_OWN_LICENSE",
    "lifecycle-details": null,
    "lifecycle-state": "ROLE_CHANGE_IN_PROGRESS",
    "local-adg-auto-failover-max-data-loss-limit": null,
    "local-disaster-recovery-type": "BACKUP_BASED",
    "local-standby-db": null,
    "long-term-backup-schedule": null,
    "memory-per-oracle-compute-unit-in-gbs": null,
    "ncharacter-set": "AL16UTF16",
    "net-services-architecture": null,
    "next-long-term-backup-time-stamp": null,
    "nsg-ids": null,
    "ocpu-count": null,
    "open-mode": "READ_WRITE",
    "operations-insights-status": "NOT_ENABLED",
    "peer-db-ids": [
      "ocid1.autonomousdatabase.oc1.ap-tokyo-1.XXXXXX"
    ],
    "permission-level": "UNRESTRICTED",
    "private-endpoint": "ozq5op1c.adb.ap-osaka-1.oraclecloud.com",
    "private-endpoint-ip": "10.0.0.188",
    "private-endpoint-label": "ozq5op1c",
    "provisionable-cpus": null,
    "refreshable-mode": null,
    "refreshable-status": null,
    "remote-disaster-recovery-configuration": {
      "disaster-recovery-type": "BACKUP_BASED",
      "is-replicate-automatic-backups": null,
      "is-snapshot-standby": null,
      "time-snapshot-standby-enabled-till": null
    },
    "resource-pool-leader-id": null,
    "resource-pool-summary": {
      "is-disabled": true,
      "pool-size": null
    },
    "role": "BACKUP_COPY",
    "scheduled-operations": null,
    "service-console-url": null,
    "source-id": "ocid1.autonomousdatabase.oc1.ap-tokyo-1.XXXXXX",
    "standby-db": null,
    "standby-whitelisted-ips": null,
    "subnet-id": "ocid1.subnet.oc1.ap-osaka-1.aaaaaaaasoopiguu5kxcuhjxjafory65cijv5mchfxajnevf3jgvtzgnvtha",
    "supported-regions-to-clone-to": [
      "KIX",
      "NRT"
    ],
    "system-tags": {},
    "time-created": "2024-03-24T00:03:39.447000+00:00",
    "time-data-guard-role-changed": "2024-03-24T00:12:49.004000+00:00",
    "time-deletion-of-free-autonomous-database": null,
    "time-disaster-recovery-role-changed": "2024-03-24T00:12:49.004000+00:00",
    "time-local-data-guard-enabled": null,
    "time-maintenance-begin": "2024-03-30T19:00:00+00:00",
    "time-maintenance-end": "2024-03-30T21:00:00+00:00",
    "time-of-joining-resource-pool": null,
    "time-of-last-failover": null,
    "time-of-last-refresh": null,
    "time-of-last-refresh-point": null,
    "time-of-last-switchover": null,
    "time-of-next-refresh": null,
    "time-reclamation-of-free-autonomous-database": null,
    "time-until-reconnect-clone-enabled": null,
    "total-backup-storage-size-in-gbs": 14.0,
    "used-data-storage-size-in-gbs": null,
    "used-data-storage-size-in-tbs": 1,
    "vault-id": null,
    "whitelisted-ips": null
  },
  "etag": "5aa868ee",
  "opc-work-request-id": "ocid1.coreservicesworkrequest.oc1.ap-osaka-1.abyhqljs3iaho2af6y7uulwxk6llqgvv2zujszgfradq7gjty4oqgvp7yf5a"
}
```

#### スイッチバック
APIは、database_client.switchover_autonomous_database を使用します。
オプションに、
autonomous_database_id ：スタンバイ側のAutonomous DatabaseのOCID (東京)
peer_db_id ： プライマリ側のAutonomous DatabaseのOCID (大阪)
スタンバイ側のリージョンに対して実行します。(東京)

```osaka2tokyo.py
import oci
config = oci.config.from_file()

database_client = oci.database.DatabaseClient(config)

switchover_autonomous_database_response = database_client.switchover_autonomous_database(
autonomous_database_id="ocid1.autonomousdatabase.oc1.ap-tokyo-1.XXXXXX",
     peer_db_id="ocid1.autonomousdatabase.oc1.ap-osaka-1.XXXXXX")

print(switchover_autonomous_database_response.data) 
```

# おわりに
Autonomous Databaseでバックアップベースのディザスタ・リカバリを cli / API でスイッチオーバーすることができました。

# 参考情報

### cli 実行/プライマリリージョン
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/108635/c5ce7877-35fe-af69-eb4b-1c0297a160d3.png)


### API 実行/プライマリリージョン
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/108635/3dcd87c2-e0cb-45d9-c9aa-79f0dd4e60d4.png)