X

The latest cloud infrastructure announcements, technical solutions, and enterprise cloud insights.

How to use bash script to refresh an autonomous database

As of now, you need to manually refresh a refreshable clone of an autonomous database every seven days to keep it up to date by logging into Oracle Cloud Infrastructure (OCI) Console. In this post, I call a REST API to refresh an autonomous database clone. By scheduling the bash script in crontab, you can eliminate the need to log into the Console and perform the refresh task every seven days. You can download the bash script from the documentation.

Before submitting the REST call

Before you can make a REST calls to Autonomous Database service in OCI, you need to obtain the following information:

  • OCID of a user in OCI tenancy allowed to make API calls

  • An RSA key pair in PEM format. The public key must be uploaded to the OCI user.

  • The fingerprint from the uploaded public key

  • OCID of your tenancy

For details of these items, see the documentation.

The bash script

The script needs a few modifications.

  local authUserId="ocid1.user.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxx";

  local keyFingerprint="xx:xx:xx:xx:xx:xx:xx:9a:9a:d7:aa:b5:8b:df:7b:c3";

  local privateKeyPath="/home/opc/.oci/oci_api_key.pem";

Change the four variables to reflect your environment. You can find details on how to set up and acquire these variables in Required Keys and OCIDs.

The whole bash script consists of two functions, which it can’t run unless you call it. So, let’s add the following line at the end of the script:

oci-curl database.us-ashburn-1.oraclecloud.com post /home/opc/request.json "/20160918/autonomousDatabases/ocid1.autonomousdatabase.oc1.iad. abuwcljtcv2od2huzpnwjiopamevognifl4wrjh6jdooohkzthoz2fx2foqq/actions/refresh"

This line is made up of the following components:

  • oci-curl: The function name

  • database.us-ashburn-1.oraclecloud.com: The host name. Choose your region.

  • post: Method of the API, which you can determine from API Reference and Endpoints.

  • /home/opc/request.json: The request body. Because the API we’re using is a POST API, you need a request body.

  • "/20160918/autonomousDatabases/ocid1.autonomousdatabase.oc1.iad. abuwcljtcv2od2huzpnwjiopamevognifl4wrjh6jdooohkzthoz2fx2foqq/actions/refresh": The API path. Enter the refreshable Autonomous Database OCID, not the source OCID.

For the request.json, we use the following parameter, which is explained in the documentation.

{
 "timeRefreshCutoff": "2021-01-27T13:00:00.000Z"
 }

If you use a different date format and it works, let me know in the comments.

Submitting the REST call to refresh a clone

When you’ve added the line in the bash script, run it. If it’s correct, you get an output similar to the following screenshot. I manually mask out my various OCIDs. Note the yellow highlighted text.

A screenshot of the resulting output from the edited bash script.

With this alteration, you can schedule the script in crontab to refresh the clone automatically.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha