Tuesday, June 23, 2026

Automating Creating Long Term backups from the Autonomous Recovery Service

 When I wrote my last blog on listing the Long Term Backups created by Autonomous Recovery Service, I didn't go through the process of how to dynamically create a new backup.

Below is how you create a long term backup in the console, but most customers want to automate this process.


The oci cli command you would use to create a new backup is "oci db backup create".

In order to create an end-of-month backup with a restore point as of midnight what I recommend customers do is

  1. Ensure you have a nightly backup that runs late at night (about 22:00) and will finish by midnight on a regular basis. 
  2. Schedule the automatic long term backup creation to occur about 00:45 on the next day. This ensures that a log sweep has occurred. For BaseDB you would wait until after the next hour.  If you have enabled the zero data loss feature (real-time redo), you want to make sure that the ARCHIVE_LAG_TARGET is set to 30 minutes or less and forcing a periodic log switch.
This ensures you are creating a long term backup with minimal archive logs to defuzzy the backup.

Command inputs

The easiest way to determine the input for this command is to use the --generate-full-command-json-input option.

oci db backup create --generate-full-command-json-input

What is returned is the JSON example below showing you what parameters need to be filled in to create the backup.

{
  "databaseId": "string",
  "displayName": "string",
  "maxWaitSeconds": 0,
  "retentionDays": 0,
  "retentionYears": 0,
  "waitForState": [
    "CREATING|ACTIVE|DELETING|DELETED|FAILED|RESTORING|UPDATING|CANCELING|CANCELED"
  ],
  "waitIntervalSeconds": 0
}

Source database and backup identifying name

  • databaseID : This is the OCID for the database that you want to create the long term backup for.
  • displayName: This is the name to identify the backup from a listing and would match the name I would put in the GUI.

Wait for state of command (Optional)

  • waitForState: Since the backup can take awhile to run, you can have the command wait to return until a specified state (or any one of a list of states) occurs. When creating a new backup the valid states would be
    • ACTIVE
    • CANCELED
    • CANCELING
    • CREATING
    • FAILED
  • maxWaitSeconds: How long to wait between state checks when waiting for a state to occur.
Example of  wait

oci db backup create --waitForState CREATING --waitForState CANCELED 

Would wait for the backup to start to be created or canceled before returning.

Retention (mandatory for long term backups and must be greater than 90 days and less than 10 years)

You would enter the number of days you want to keep backups for (retentionDays), or you would enter the number of years (retentionYears) , but not both.

Below is an example JSON file that would create a new long term backup named "bsgtest" and keep the backup for 100 days.


{
  "databaseId": "ocid1.database.oc1.phx.anyhqljtbv6267ia2wse63oz7xadpv5lfi2gf233333eomezhadfbdkt2eq",
  "displayName": "bsgtest",
  "maxWaitSeconds": 0,
  "retentionDays": 100
}


That's all you need to know about creating a long term backup dynamically.


No comments:

Post a Comment