LoginSignup
1
0

More than 1 year has passed since last update.

[OCI]OCI CLIからAutonomous Databaseの自動起動/停止スケジュールを設定してみた

Last updated at Posted at 2022-01-19

はじめに

Autonomous Databaseの自動起動/停止のスケジューリングができるようになり、とても便利になりました。

今回はOCI CLIから自動起動/停止のスケジューリングの設定を行う方法を確認しました。

oci db autonomous-database updateコマンドの"--scheduled-operation"オプションで設定できることがわかったのですが、スケジュールを指定するフォーマットがわからなかったので、"--generate-param-json-input"オプションで確認してみました。

1.自動起動/停止スケジュールを指定するJSONの書式確認

[opc@work ~]$ oci db autonomous-database update --generate-param-json-input scheduled-operations
[
  {
    "dayOfWeek": {
      "name": "string"
    },
    "scheduledStartTime": "string",
    "scheduledStopTime": "string"
  },
  {
    "dayOfWeek": {
      "name": "string"
    },
    "scheduledStartTime": "string",
    "scheduledStopTime": "string"
  }
]
[opc@work ~]$

こちらによると、"dayOfWeek"の"name"に曜日、"scheduledStartTime"に起動時間、"scheduledStopTime"に停止時間を指定するようです。起動/停止時間はUTCで指定します。

2.JSONファイルの作成

ということで、設定内容を記述した以下のようなJSONファイルを作成します。

scheduled-operations.json
[
    {
        "day-of-week": {
          "name": "MONDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
    },
    {
        "day-of-week": {
          "name": "TUESDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
    },
    {
        "day-of-week": {
          "name": "WEDNESDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
    },
    {
        "day-of-week": {
          "name": "THURSDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
    },
    {
        "day-of-week": {
          "name": "FRIDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
    },
    {
        "day-of-week": {
          "name": "SATURDAY"
        },
        "scheduled-start-time": "10:00",
        "scheduled-stop-time": "18:00"
    },
    {
        "day-of-week": {
          "name": "SUNDAY"
        },
        "scheduled-start-time": "10:00",
        "scheduled-stop-time": "18:00"
    }
]

3.OCI CLIで自動起動/停止スケジュールを設定

こちらのファイルを指定して、"oci db autonomous-database update --scheduled-operations"コマンドを実行します。

[opc@work ~]$ oci db autonomous-database update --autonomous-database-id ocid1.autonomousdatabase.oc1.ap-tokyo-1.xxxxxxxxxxxxxxxxxxxx --scheduled-operations file://scheduled-operations.json
WARNING: Updates to freeform-tags and defined-tags and whitelisted-ips and standby-whitelisted-ips and nsg-ids and customer-contacts and scheduled-operations will replace any existing values. Are you sure you want to continue? [y/N]: y
{
  "data": {
    "apex-details": {
      "apex-version": "21.1.6",
      "ords-version": "21.3.2.327.1419"
    },
<省略>
    "scheduled-operations": [
      {
        "day-of-week": {
          "name": "MONDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
      },
      {
        "day-of-week": {
          "name": "TUESDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
      },
      {
        "day-of-week": {
          "name": "WEDNESDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
      },
      {
        "day-of-week": {
          "name": "THURSDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
      },
      {
        "day-of-week": {
          "name": "FRIDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
      },
      {
        "day-of-week": {
          "name": "SATURDAY"
        },
        "scheduled-start-time": "10:00",
        "scheduled-stop-time": "18:00"
      },
      {
        "day-of-week": {
          "name": "SUNDAY"
        },
        "scheduled-start-time": "10:00",
        "scheduled-stop-time": "18:00"
      }
    ],
<省略>

4.設定内容の確認

設定が完了したので、"oci db autonomous-database get"コマンドで設定内容を確認してみます。

[opc@work ~]$ oci db autonomous-database get --autonomous-database-id ocid1.autonomousdatabase.oc1.ap-tokyo-1.xxxxxxxxxxxxxxxxxxxx
{
  "data": {
    "apex-details": {
      "apex-version": "21.1.6",
      "ords-version": "21.3.2.327.1419"
    },
<略>
    "scheduled-operations": [
      {
        "day-of-week": {
          "name": "MONDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
      },
      {
        "day-of-week": {
          "name": "TUESDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
      },
      {
        "day-of-week": {
          "name": "WEDNESDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
      },
      {
        "day-of-week": {
          "name": "THURSDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
      },
      {
        "day-of-week": {
          "name": "FRIDAY"
        },
        "scheduled-start-time": "08:00",
        "scheduled-stop-time": "20:00"
      },
      {
        "day-of-week": {
          "name": "SATURDAY"
        },
        "scheduled-start-time": "10:00",
        "scheduled-stop-time": "18:00"
      },
      {
        "day-of-week": {
          "name": "SUNDAY"
        },
        "scheduled-start-time": "10:00",
        "scheduled-stop-time": "18:00"
      }
    ],
<略>

JSONファイルで記述した自動起動/停止スケジュールが設定されていることが確認できました。

コンソールで設定内容が反映されているか確認してみます。
Autonomous Databaseの詳細画面の「自動開始/停止スケジュール:」の編集をクリックします。
スクリーンショット 2022-01-19 16.11.38.png

OCI CLIで設定した自動起動/停止スケジュールが反映されていることが確認できました。
スクリーンショット 2022-01-19 16.09.15.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0