Updating a MySQL HeatWave Backup - Using the Oracle Cloud TypeScript SDK Part 6

This post is the sixth in a series that will demonstrate how to view and manage MySQL HeatWave instances in Oracle Cloud Infrastructure (OCI). Oracle offers several SDKs that can be used to view and manage resources in OCI. In this post, we will discuss how to leverage the TypeScript/JavaScript SDK to programmatically update data of a backup of a MySQL HeatWave instance.
Prerequisites
To use the OCI SDKs, you need credentials for an OCI account with the proper permissions. While it is not necessary to install the OCI CLI, following the instructions at this post will create the same files we will need to use the SDK…with the added advantage of installing the CLI.
To follow along with this demo, you should also have Node.js installed. I am using version 21.5.0.
Creating the Node App
Before we can access the SDK, we need to take care of some setup and config.
Initialize the Node App
Create a directory to hold your code, open a terminal/command window, and cd
into that new folder. To initialize a Node app, run the following command:
You will be prompted for information about the project. For this demo, feel free to accept all the default values.
When the init
script is complete, you should see a file named package.json
in your directory. Here is what mine looks like.
Install the Necessary Modules
Next, we will install the node modules we will need. You can install these modules using the command:
This command will install the oci-mysql
, dotenv
, and express
modules.
The oci-mysql
module contains the parts of the SDK specific to MySQL HeatWave instances. It also includes dependencies on other modules, such as oci-common
.
The bunyan
module is a JSON logging library for Node.js. I had to add this because I was getting errors while trying to run the code for this demo. I guess that there is a missing dependency somewhere. Installing bunyan
separately addressed my issues.
The dotenv
module allows us to use environment variables for information we will use in our demo.
Set up .env
In this example, we only need one environment variable, the OCID of the compartment we will use. Create a file named .env
and then add a variable named COMPARTMENT_ID
and give it the value of the compartment you want to use. It should look like the text below.
Using the SDK
Rather than break down each bit of code a little at a time, here is all the code you will need for this demo. I will break down the new pieces below.
The Code
Create a file named index.mjs
and paste in the following code.
The Breakdown
At the top of the file, we import the necessary modules, oci-common
, oci-mysl
, and dotenv
. We then call dotenv.config()
to grab the environment variables.
Next, we create a function named main()
, and inside that function, we create an instance of ConfigFileAuthenticationDetailsProvider()
called provider
. This provider reads the OCI config file created when we installed the OCI CLI. By default, the provider uses the config file located at ~/.oci/config
and the DEFAULT
config block if more than one block is specified.
Once we have an authentication provider, we need to create an instance of mysql.DbBackupsClient()
, named backupClient
, and pass this provider as part of a config block.
Now that we have our backupClient
, we must build the config block to specify options about our backup.
In the JSON object named updateBackupDetails
, we set new values for displayName
, description
, and retentionDays
. We then use this object in the request details config block named updateBackupRequest
. We must also pass the backupId
for the backup we wish to update.
We update our backup by calling updateBackup()
on our backupClient
and pass in the config values we just discussed. We then log the result of this call to the console.
Running the Code
Before
Before we run the code, let’s look at the backup details page in OCI for the backup we want to update. We can see that the backup name is ‘TEST API Backup’ (1), and the ‘Retention Days’ value is set to 42 (2).
To run the code, open a terminal/command window in the project folder and run the command:
In the console, you will almost immediately see the output of our call to creeateBackup()
. Mine resembles the output below.
After
If we go back and look at the backup Details page in OCI, we will see that the backup name (1) and retention days (2) have been updated.
The Wrap-Up
As we can see, the TypeScript/JavaScript OCI SDK allows us to update information about a backup of a MySQL HeatWave instance. In my last post in this series, I will discuss how to retrieve lists of reference data used when managing MySQL HeatWave instances using the OCI SDK.
Photo by Markus Winkler on Unsplash
Related Entries
- Listing MySQL HeatWave Instances - Using the Oracle Cloud TypeScript SDK Part 1
- Managing MySQL HeatWave Instances - Using the Oracle Cloud TypeScript SDK Part 2
- Waiters - Using the Oracle Cloud TypeScript SDK Part 3
- Listing MySQL HeatWave Backups - Using the Oracle Cloud TypeScript SDK Part 4
- Creating a MySQL HeatWave Backup - Using the Oracle Cloud TypeScript SDK Part 5
- Retrieving Reference Lists - Using the Oracle Cloud TypeScript SDK Part 7