Tuesday, February 9, 2021

OCI CLI to List all the Boot Volumes Backup Policy Assignment

OCI CLI to List all the Boot Volumes Backup Policy Assignment

This bash scripts needs the tenancy ID to be updated. It loops through all the compartments and then it all availability-domain ,  then fetches the boot volume details. From the boot volume it fetches the asset-id and then validates block volume policy assignment. If there is no policy assigned then the policy status is marked as FAILURE. If you intend to have backups enabled , create a new backup policy of your choice or assign already existing one.


ociCompartmentList=$(oci iam compartment list --compartment-id ocid1.tenancy.oc1..aaaa1111222334)
for c in $(echo "$ociCompartmentList" | jq '.data | keys | .[]')
do
        compartment_ocid=$(echo "$ociCompartmentList" | jq -r ".data[$c].\"id\"")
        ociadList=$(oci iam availability-domain list)
        for a in $(echo "$ociadList" | jq '.data | keys | .[]')
        do
                ociAD=$(echo "$ociadList" | jq -r ".data[$a].\"name\"")
                ocibootvList=$(oci bv boot-volume list -c $compartment_ocid --availability-domain $ociAD)
                for i in $(echo "$ocibootvList" | jq '.data | keys | .[]')
                do
                        bvID=$(echo "$ocibootvList" | jq -r ".data[$i].\"id\"")
                        bvName=$(echo "$ocibootvList" | jq -r ".data[$i].\"display-name\"")
                        lifecycle=$(echo "$ocibootvList" | jq -r ".data[$i].\"lifecycle-state\"")
                        bvPolicyAList=$(oci bv volume-backup-policy-assignment get-volume-backup-policy-asset-assignment --asset-id $bvID)
                        ociAssignedPolicyID=$(echo "$bvPolicyAList" | jq -r ".data[].\"id\"")
                        if [ -z "$ociAssignedPolicyID" ]
                        then
                                echo "BootVolume : $bvName | Backup Policy : FAILURE"
                        else
                                echo "BootVolume : $bvName | Backup Policy : AVAILABLE"
                        fi
                done
        done
done 

Boot Volume: ebstestserver-001(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-002(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-003(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-001(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-004(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-005(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-001(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-006(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-006(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-007(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-008(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-009(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-010(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-011(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-012(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-013(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-014(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-015(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-016(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-017(Boot Volume)| Backup Policy: AVAILABLE
Boot Volume: ebstestserver-018(Boot Volume)| Backup Policy: FAILURE
Boot Volume: ebstestserver-019(Boot Volume)| Backup Policy: FAILURE
Boot Volume: ebstestserver-020(Boot Volume)| Backup Policy: FAILURE
 

Monday, February 8, 2021

OCI CLI to List all the Boot Volumes and its LifeCycle State in the Tenancy

OCI CLI to List all the Boot Volumes and its LifeCycle State in the Tenancy

This bash scripts needs the tenancy ID to be updated. It loops through all the compartments and then it all availability-domain ,  then fetches the boot volume details.


ociCompartmentList=$(oci iam compartment list --compartment-id ocid1.tenancy.oc1..aaaa1111222334)
for c in $(echo "$ociCompartmentList" | jq '.data | keys | .[]')
do
 compartment_ocid=$(echo "$ociCompartmentList" | jq -r ".data[$c].\"id\"")
 ociadList=$(oci iam availability-domain list)
 for a in $(echo "$ociadList" | jq '.data | keys | .[]')
 do
  ociAD=$(echo "$ociadList" | jq -r ".data[$a].\"name\"")
  ocibootvList=$(oci bv boot-volume list -c $compartment_ocid --availability-domain $ociAD)
  for i in $(echo "$ocibootvList" | jq '.data | keys | .[]')
  do
  bvName=$(echo "$ocibootvList" | jq -r ".data[$i].\"display-name\"")
  lifecycle=$(echo "$ocibootvList" | jq -r ".data[$i].\"lifecycle-state\"")
  echo "BootVolume : $bvName | LifeCycle: $lifecycle"
  done
 done
done

Boot Volume: ebstestserver-001(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-002(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-003(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-004(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-005(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-006(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-007(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-008(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-009(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-010(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-011(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-012(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-013(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-014(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-015(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-016(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-017(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-018(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-019(Boot Volume)| LifeCycle: RUNNING
Boot Volume: ebstestserver-020(Boot Volume)| LifeCycle: RUNNING
 

Popular Posts