Using OCI CLI to generate report for all the Boot Volumes Backup Policy Assigned and Not Assigned

This bash script 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 NOT ASSIGNED. If you intend to have backups enabled, create a new backup policy of your choice or assign an already existing one.

You can use the Not Assigned Policy file to assign a backup policy in one go. The script for the same will be published in the next Blog. Stay tuned..

========================================================== 

ociCompartmentList=$(oci iam compartment list --compartment-id ocid1.tenancy.oc1..aaaaaaaaaaaaaa)

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 "$bvName | Backup Policy : NOT ASSIGNED" >>backup-policy-notasigned.txt

                        else

                                echo "$bvName | Backup Policy : AVAILABLE" >>backup-policy-assigned.txt

                        fi

                done

        done

done  

Comments

Popular posts from this blog

Creating Oracle Java Cloud Service Virtual Image with Oracle Database Cloud Service Virtual Image

FTMCLI setup for Oracle Storage Cloud Service