Eclipsys Blog

How to Automate Start and Stop of DBCS Node using REST API in OCI – Eclipsys

Written by Manoj Kumar | Aug 9, 2024 11:40:59 PM

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 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 the morning.

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

Please see my previous post on the 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 the clear over the internet.

You basically need to change the Tenancy OCID, USER OCID, KeyFingerprint, and private key .pem file location in that script. You can easily get these from the 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 the above changes as per your tenancy.

So what else do we need

  • API Endpoint for the 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 the 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 the Toronto region. It might be different for your region if your region is not Toronto.

POST : API Request

./empty.json : This is the empty file I used for starting and stopping dbcs node, because we have to use any config json file for POST API requests. Here we are not changing anything like OCPU etc. that’s why it’s empty.

/20160918/dbNodes/<dbnodeid>?action=stop : This is the command we have to use to 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 the 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 this stop-and-start script via crontab.