How to automate start and stop of DBCS node using REST API in OCI

 


Recently we migrated databases from ODA (Oracle database appliance) to OCI DBCS for a client. And client asking to stop the dev DBCS node from 5 PM to 6 AM in the morning to save cost.

NOTE: For Virtual machine DB systems - Stopping a node stops billing for all OCPUs associated with that node, and billing resumes when you restart the node.

So this task is possible by console -> go to console and stop the DBCS node and again start in morning.

But we can not automate this from console. I found REST API is the best and easiest way to automate this task.

Please see my previous post on deployment of DBCS using REST API.

In my above post I specify the oci-curl script that you can copy. 

Here is the link again to copy script oci-curl

OCI-CURL will sign and encrypt your APIs so they are not sent in clear over the internet.

You basically need to change Tenancy OCID, USER OCID, KeyFingerprint and private key .pem file location in that script. You can easily get these from OCI console.

Pre-requisite:

1. I am assuming you already have VCN, subnet, security rules and compartment.

2. Running DBCS

3. OCI-CURL script with above changes as per your tenancy.

So what else we need

API endpoint for database: I used  database.ca-toronto-1.oraclecloud.com , if your cloud database is located somewhere else you can use that. full list here .. API Endpoints

DB Node Action command: POST /20160918/dbNodes/{dbNodeId}

How it works:

I created a very small shell script to stop DBCS node.

$ cat stop_dbsystem.sh

#!/bin/bash

. ./oci-curl.sh

oci-curl database.ca-toronto-1.oraclecloud.com POST ./empty.json /20160918/dbNodes/<dbnodeid>?action=stop

where 

oci-curl.sh : will load and source the function with our tenant data.

database.ca-toronto-1.oraclecloud.com : API endpoint that listens for DB service from Toronto region. It might be different for your region is your region is not Toronto.

POST : API Request

./empty.json : This is the empty file I used for start and stop dbcs node, because we have to use any config json file for POST API request. Here we are not changing anything like OCPU etc. that's why its empty.

/20160918/dbNodes/<dbnodeid>?action=stop : This is basically the command we have to use for start/stop dbcs node. The first number in this command is the API version. and dbnodeid is OCID of dbcs node we have to copy from console to use here.

After that just make this file executable.

chmod +x stop_dbsystem.sh

After running the above script I saw my DBCS node start stopping. here is the output response.


Once DBCS node stopped.

I created another small script to start the DBCS node.

$ cat start_dbsystem.sh

#!/bin/bash

. ./oci-curl.sh

oci-curl database.ca-toronto-1.oraclecloud.com POST ./empty.json /20160918/dbNodes/<dbnodeid>?action=start

and then run this script to start dbcs node, here is the output response.


We can see dbnode starting via oci console.

Now as per client requirement, we can schedule these stop and start script via crontab.

I hope you like the blog!

Analyze Invoices with Oracle Analytics and AI Document Understanding

OCI Document Understanding is an AI service that enables developers to extract text, tables, and other key data from document files through...