Monitor Oracle Cloud Infrastructure Backups with Functions and Autonomous JSON

This function inserts Oracle Cloud backup events into an autonomous database. This example uses—and Oracle recommends that you use—autonomous JSON because an event on Oracle Cloud Infrastructure (OCI) is a JSON text. For instance, with OCI File Storage, a snapshot (that is, a backup) will create an event that looks like this:
```
{
  "eventType" : "com.oraclecloud.filestorage.createsnapshot",
  "cloudEventsVersion" : "0.1",
  "eventTypeVersion" : "2.0",
  "source" : "FileStorage",
  "eventTime" : "2022-11-23T21:30:20Z",
  "contentType" : "application/json",
  "data" : {
    "compartmentId" : "ocid1.compartment.oc1..********************",
    "compartmentName" : "ChristophePruvost",
    "resourceName" : "Snapshot-20221123-2130-10",
    "resourceId" : "ocid1.snapshot.oc1.********************",
    "availabilityDomain" : "AD2",
    "freeformTags" : { },
    "definedTags" : {
      "Mandatory_Tags" : {
        "Owner" : "oracleidentitycloudservice/firstname.name@company.com",
        "Schedule" : "OnDemand_UTC+1",
        "CreatedOn" : "2022-11-23T21:30:11.405Z"
      }
    },
    "additionalDetails" : {
      "X-Real-Port" : 60458
    }
  },
  "eventID" : "d520f88c-cd3d-4d1f-9a39-d935db5dcd8b",
  "extensions" : {
    "compartmentId" : "ocid1.compartment.oc1..*****************************"
  }
}
```

After inserting events in Autonomous JSON, you can easily build an APEX application that will monitor all of your OCI backups in one place. Moreover, as an OCI administrator, you can avoid a deluge of email notifications and you can use APEX to build efficient backup reports. To enable this, you need to disable the Email Delivery component shown on the following architecture diagram.

Architecture

The following diagram illustrates the reference architecture for this solution.

Description of mon-bu-funs-auto-json-arch.png follows
Description of the illustration mon-bu-funs-auto-json-arch.png

mon-bu-funs-auto-json-arch-oracle.zip

Note:

File Storage Snapshot and DBCS Backup are just two examples of this implementation. It will run similarly with all backup events on OCI, including Block Storage Backup, Boot Storage Backup, ExaCS Backup, and so on.

The architecture has the following components:

  • Region

    An Oracle Cloud Infrastructure region is a localized geographic area that contains one or more data centers, called availability domains. Regions are independent of other regions, and vast distances can separate them (across countries or even continents).

  • Virtual cloud network (VCN) and subnets

    A VCN is a customizable, software-defined network that you set up in an Oracle Cloud Infrastructure region. Like traditional data center networks, VCNs give you complete control over your network environment. A VCN can have multiple non-overlapping CIDR blocks that you can change after you create the VCN. You can segment a VCN into subnets, which can be scoped to a region or to an availability domain. Each subnet consists of a contiguous range of addresses that don't overlap with the other subnets in the VCN. You can change the size of a subnet after creation. A subnet can be public or private.

  • File Storage

    Oracle Cloud Infrastructure File Storage service provides a durable, scalable, secure, enterprise-grade network file system. You can connect to a File Storage service file system from any bare metal, virtual machine, or container instance. A File Storage Snapshot is a backup of the file system that you can use if you want to restore it doing a clone.

  • Database Cloud Service (DBCS)

    DBCS is a full managed service of Oracle Database. A DBCS Backup is a backup of the data that you can use to restore the database.

  • OCI Events Service

    Oracle Cloud Infrastructure Events Service tracks resource changes using events that comply with the Cloud Native Computing Foundation (CNCF) Cloud Events standard. Developers can respond to changes in real-time by triggering code with Functions, writing to Streaming, or sending alerts using Notifications.

  • OCI Functions

    Oracle Cloud Infrastructure OCI Functions is a serverless, event-driven service that lets developers build, run, and scale applications without provisioning or managing any infrastructure. You only pay for the resources used when the function is running. Functions integrate with other OCI services and Oracle Saar applications. Based on an open framework, OCI Functions can be ported to other clouds or on-premises environments.

  • Autonomous JSON

    Oracle Autonomous JSON Database is a feature-scoped service for storing and retrieving JSON document collections using SQL or Document APIs.

  • Email Delivery

    The Oracle Cloud Infrastructure Email Delivery service provides a fast and reliable managed solution for sending secured, high-volume marketing and transactional emails.

Recommendations

To implement the function, Oracle recommends that you complete some of the available LiveLabs to better understand the process and to prepare your environment.

  • Oracle OCI Function

    First, you need to become familiar with implementing OCI Functions. Follow the LiveLab, Configuring Oracle Functions. To expedite the process, copy and paste sample code from oracle-functions-samples on GitHub.

  • Autonomous JSON

    Next, to develop familiarity with using JSON in Oracle databases, follow the LiveLab, Developing with JSON and SODA in Oracle Database. Then, follow the LiveLab, Event Driven Oracle Functions with Autonomous Data Warehouse.

  • Monitoring with APEX

    Finally, learn how to monitor processes in APEX, follow the LiveLabs Low Code Development with Autonomous Database.

    After you finish the LiveLab, create an SQL View of the JSON Events and use the following code sample to build your own APEX Monitoring Application. Note that this view is relative to the structure of the JSON Event example shown in "Learn About Monitoring Oracle Cloud Infrastructure Backups with Functions and Autonomous JSON".
     CREATE OR REPLACE VIEW j_backup_detail_view
        AS SELECT ba.id, ba.created_on, ba.last_modified, ba.version, jt.*
        FROM backup ba,
        json_table(ba.json_document, '$'
                    COLUMNS (
                        eventtype        VARCHAR2(100)        PATH '$.eventType',
                        cloudeventsversion        VARCHAR2(10)  PATH '$.cloudEventsVersion',
                        eventtypeversion        VARCHAR2(10) PATH '$.eventTypeVersion',
                        source           VARCHAR2(50)  PATH '$.source',
                        compartmentid    VARCHAR2(200) PATH '$.data.compartmentId',
                        compartmentname    VARCHAR2(100) PATH '$.data.compartmentName',
                        resourcename    VARCHAR2(200) PATH '$.data.resourceName',
                        resourceid    VARCHAR2(200) PATH '$.data.resourceId',
                        availabilitydomain    VARCHAR2(200) PATH '$.data.availabilityDomain'
                    )) jt;
    
        create search index srchidx on backup (json_document) for json; 

    Now you are ready to start your own implementation.

Explore More

Learn more about monitoring OCI backups with Functions and autonomous JSON.

Review these additional solutions:

Acknowledgments

  • Author: Christophe Pruvost

  • Contributors: Oracle EMEA Solution Center