[Oracle Cloud] cloud shell -> OCI CLI でバックアップポリシをいじる

# はじめに

OCIコンソールで、ポリシーベースのバックアップを設定する場合、
設定時刻が10時,12時,13時といった、「時」単位でしか設定ができない
これを OCI CLIで設定しようとすると、
より細かく設定ができそうだったので設定手順を記載してみる
※ この記事では一旦設定手順まで。動作検証は別途。

# Cloud Shell

↓ ログイン直後のOCIコンソールトップ

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/52636a7f-4c38-b72b-7ca0-b30c9f77d75a.png)

↓ Cloud Shell

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/f9da7560-55cc-9956-b6c4-0fd064ca99a8.png)

Cloud Shellの立ち上げに少々時間がかかる
その後立ち上がった画面はこちら ↓

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/525833bd-42f5-dbce-5011-341d57c28a41.png)

↓ 基本情報を表示してみる

```
hogehoge@cloudshell:~ (ap-tokyo-1)$ id
uid=1101(hogehoge) gid=1101(oci) groups=1101(oci),994(docker)
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
hogehoge@cloudshell:~ (ap-tokyo-1)$ date 
Fri Mar 15 05:21:21 UTC 2024
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
hogehoge@cloudshell:~ (ap-tokyo-1)$ uname -n 
c5ffb0ae121a
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
hogehoge@cloudshell:~ (ap-tokyo-1)$ w
 05:21:34 up  2:37,  0 users,  load average: 0.12, 0.12, 0.09
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
hogehoge@cloudshell:~ (ap-tokyo-1)$ pwd
/home/hogehoge
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
```


# OCI CLI

↓ リファレンス
https://docs.oracle.com/en-us/iaas/tools/oci-cli/3.37.13/oci_cli_docs/

↓ 例えば oci network vcn list のページは下記の感じ

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/d5c39a8b-7d29-1878-6ed5-9d1be3c5b9b5.png)

↓ 実際に流してみる

```
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
hogehoge@cloudshell:~ (ap-tokyo-1)$ oci network vcn list -c ocid1.compartment.oc1..aaaaaaaatrohzlj2ddlvdbuefmz3l32pu2tqh6u4rxzvo3lqcsgiupj3zfha
{
  "data": [
    {
      "byoipv6-cidr-blocks": null,
      "cidr-block": "10.90.0.0/16",
      "cidr-blocks": [
        "10.90.0.0/16"
      ],
      "compartment-id": "ocid1.compartment.oc1..aaaaaaaatrohzlj2ddlvdbuefmz3l32pu2tqh6u4rxzvo3lqcsgiupj3zfha",
      "default-dhcp-options-id": "ocid1.dhcpoptions.oc1.ap-tokyo-1.aaaaaaaao3e7f3klfmzofdixba6cmxv5gsonf6hqwn4hwgwyik5irkovz2fa",
      "default-route-table-id": "ocid1.routetable.oc1.ap-tokyo-1.aaaaaaaac5i3ugeqecve3plcxbnny3romnydbx5zu5tpotjlilz5epfhysia",
      "default-security-list-id": "ocid1.securitylist.oc1.ap-tokyo-1.aaaaaaaaxpomaxicsmn5y4k3yriubno375jpeuprn2efyta3e4qd6otbnpdq",
      "defined-tags": {},
      "display-name": "vcn_tokyo_10.90.0.0/16",
      "dns-label": "vcntokyo1090001",
      "freeform-tags": {},
      "id": "ocid1.vcn.oc1.ap-tokyo-1.amaaaaaassl65iqaig47wx76lad2rbc4p3ptqeacwxe3srmhg2hnioymf5ia",
      "ipv6-cidr-blocks": null,
      "ipv6-private-cidr-blocks": null,
      "lifecycle-state": "AVAILABLE",
      "time-created": "2020-06-08T00:43:35.694000+00:00",
      "vcn-domain-name": "vcntokyo1090001.oraclevcn.com"
    },
    {
      "byoipv6-cidr-blocks": null,
      "cidr-block": "192.168.0.0/16",
      "cidr-blocks": [
        "192.168.0.0/16"
      ],
      "compartment-id": "ocid1.compartment.oc1..aaaaaaaatrohzlj2ddlvdbuefmz3l32pu2tqh6u4rxzvo3lqcsgiupj3zfha",
      "default-dhcp-options-id": "ocid1.dhcpoptions.oc1.ap-tokyo-1.aaaaaaaamejfo2slyyrs5rpd4w26h3wo2x7uyos3jjn7j752q665fplb7haa",
      "default-route-table-id": "ocid1.routetable.oc1.ap-tokyo-1.aaaaaaaabwneytbdvdwa3yhvozwknkwdbuvzq6qumbuy2zbl7whjlxx7uxoa",
      "default-security-list-id": "ocid1.securitylist.oc1.ap-tokyo-1.aaaaaaaaj5b4dudq5am367fwvkyg6dkcojwfs7ff2a4uyqnd2tbkdfb5bfkq",
      "defined-tags": {},
      "display-name": "vcn_192.168.0.0/16",
      "dns-label": "vcn1921680016",
      "freeform-tags": {},
      "id": "ocid1.vcn.oc1.ap-tokyo-1.aaaaaaaa4zlgdlbx3jcw6ga7xduqcnnjox35nb6nm7gejmcs3ivzmg3zg7dq",
      "ipv6-cidr-blocks": null,
      "ipv6-private-cidr-blocks": null,
      "lifecycle-state": "AVAILABLE",
      "time-created": "2019-09-26T04:41:11.836000+00:00",
      "vcn-domain-name": "vcn1921680016.oraclevcn.com"
    }
  ]
}
hogehoge@cloudshell:~ (ap-tokyo-1)$ 

```

# バックアップポリシのupdate

さてやりたかったのはここから
↓ oci bv volume-backup-policy get を試す
既に作成済みのバックアップポリシをいじっていく

```
hogehoge@cloudshell:~ (ap-tokyo-1)$ oci bv volume-backup-policy get --policy-id ocid1.volumebackuppolicy.oc1.ap-tokyo-1.aaaaaaaapygqxyy2lwgssl5j7rg6r6g7zhfl4mlahn2gzexnd6lfkj3puipa
{
  "data": {
    "compartment-id": "ocid1.compartment.oc1..aaaaaaaatrohzlj2ddlvdbuefmz3l32pu2tqh6u4rxzvo3lqcsgiupj3zfha",
    "defined-tags": {},
    "destination-region": "ap-osaka-1",
    "display-name": "test",
    "freeform-tags": {},
    "id": "ocid1.volumebackuppolicy.oc1.ap-tokyo-1.aaaaaaaapygqxyy2lwgssl5j7rg6r6g7zhfl4mlahn2gzexnd6lfkj3puipa",
    "schedules": [
      {
        "backup-type": "INCREMENTAL",
        "day-of-month": 1,
        "day-of-week": "MONDAY",
        "hour-of-day": 22,
        "month": "JANUARY",
        "offset-seconds": 0,
        "offset-type": "STRUCTURED",
        "period": "ONE_DAY",
        "retention-seconds": 604800,
        "time-zone": "REGIONAL_DATA_CENTER_TIME"
      }
    ],
    "time-created": "2021-09-16T12:03:44.716000+00:00"
  },
  "etag": "c2320d9a02679070c34c6b45de0760db"
}
hogehoge@cloudshell:~ (ap-tokyo-1)$
```

VolumeBackupScheduleリファレンスはこちら ↓
https://docs.oracle.com/en-us/iaas/api/#/en/iaas/20160918/datatypes/VolumeBackupSchedule

↓ 気にしていたのはこちら
オフセットを設定することで、デフォルトの時間からずらすことができる（らしい）

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/dd27c470-a81d-9abc-5f43-74cd5188a015.png)

↓ 設定用コマンド

```
hogehoge@cloudshell:~ (ap-tokyo-1)$ oci bv volume-backup-policy update --policy-id ocid1.volumebackuppolicy.oc1.ap-tokyo-1.aaaaaaaapygqxyy2lwgssl5j7rg6r6g7zhfl4mlahn2gzexnd6lfkj3puipa --schedules file://sche2.json
WARNING: Updates to schedules and defined-tags and freeform-tags will replace any existing values. Are you sure you want to continue? [y/N]: y
{
  "data": {
    "compartment-id": "ocid1.compartment.oc1..aaaaaaaatrohzlj2ddlvdbuefmz3l32pu2tqh6u4rxzvo3lqcsgiupj3zfha",
    "defined-tags": {},
    "destination-region": "ap-osaka-1",
    "display-name": "test",
    "freeform-tags": {},
    "id": "ocid1.volumebackuppolicy.oc1.ap-tokyo-1.aaaaaaaapygqxyy2lwgssl5j7rg6r6g7zhfl4mlahn2gzexnd6lfkj3puipa",
    "schedules": [
      {
        "backup-type": "INCREMENTAL",
        "day-of-month": 1,
        "day-of-week": "MONDAY",
        "hour-of-day": 22,
        "month": "JANUARY",
        "offset-seconds": 600,
        "offset-type": "STRUCTURED",
        "period": "ONE_DAY",
        "retention-seconds": 604800,
        "time-zone": "REGIONAL_DATA_CENTER_TIME"
      }
    ],
    "time-created": "2021-09-16T12:03:44.716000+00:00"
  },
  "etag": "9a3ffc31b139923ecad11b17c71018c9"
}
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
```

↓ 用意したjsonはこちら

```
hogehoge@cloudshell:~ (ap-tokyo-1)$ cat ./sche2.json
[
        {
                "backup-type": "INCREMENTAL",
                "day-of-month": 1,
                "day-of-week": "MONDAY",
                "hour-of-day": 22,
                "month": "JANUARY",
                "offset-seconds": 600,
                "offset-type": "STRUCTURED",
                "period": "ONE_DAY",
                "retention-seconds": 604800,
                "time-zone": "REGIONAL_DATA_CENTER_TIME"
        }
]
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
```

↓ 確認

```
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
hogehoge@cloudshell:~ (ap-tokyo-1)$ oci bv volume-backup-policy get --policy-id ocid1.volumebackuppolicy.oc1.ap-tokyo-1.aaaaaaaapygqxyy2lwgssl5j7rg6r6g7zhfl4mlahn2gzexnd6lfkj3puipa
{
  "data": {
    "compartment-id": "ocid1.compartment.oc1..aaaaaaaatrohzlj2ddlvdbuefmz3l32pu2tqh6u4rxzvo3lqcsgiupj3zfha",
    "defined-tags": {},
    "destination-region": "ap-osaka-1",
    "display-name": "test",
    "freeform-tags": {},
    "id": "ocid1.volumebackuppolicy.oc1.ap-tokyo-1.aaaaaaaapygqxyy2lwgssl5j7rg6r6g7zhfl4mlahn2gzexnd6lfkj3puipa",
    "schedules": [
      {
        "backup-type": "INCREMENTAL",
        "day-of-month": 1,
        "day-of-week": "MONDAY",
        "hour-of-day": 22,
        "month": "JANUARY",
        "offset-seconds": 600,
        "offset-type": "STRUCTURED",
        "period": "ONE_DAY",
        "retention-seconds": 604800,
        "time-zone": "REGIONAL_DATA_CENTER_TIME"
      }
    ],
    "time-created": "2021-09-16T12:03:44.716000+00:00"
  },
  "etag": "9a3ffc31b139923ecad11b17c71018c9"
}
hogehoge@cloudshell:~ (ap-tokyo-1)$ 
```

↓ 設定前の状態

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/567355/726cc572-02e0-7295-1113-90415f8410d1.png)

上記updateのコマンドを流しても、
コンソール表示は特に変化しなかった
本当にバックアップの開始時間がずれるのか
別途確認を行っていきたい


# 参照資料

xxx