Periodic backup of IBM Cloud Database with IBM Cloud Function

Ong Khai Wei
3 min readDec 24, 2019

Backup is always an important element in Day2 operation. Traditional way of performing backup is done via Cron Job, Windows Scheduler and Task Automation software with backup solution. Compute resources that used to automate and backup are constantly up and running, but idle most of time and this leads to wastage. With more and more cloud service provider offers Database-as-a-Service, it make the backup easy by leveraging Function-as-a-Service to automate the backup. The following example will be based on IBM Cloud Database and IBM Cloud Function.

IBM Cloud Database provides API to allow On-Demand backup to be trigged (https://cloud.ibm.com/apidocs/cloud-databases-api). It will be similar steps that I did in previous post. In this example I have the source code for the nodejs app to call cloud database api published in github.

Step 1: Generate IBM Cloud API key

Cloud Database API security leverages on IAM token. Each token will expire based on certain time period, therefore it will be important to have IBM Cloud API to generate an IAM token for the execution. Follow this page https://cloud.ibm.com/docs/iam?topic=iam-userapikey#create_user_key to create an API key.

Step 2: Download the source code and package to zip file

Use git clonecommand to download the source code. Execute npm install to install node dependencies locally. Subsequently zip the file and dependency folder to become a package zip -r action.zip *

Step 3: Login to IBM Cloud via command line interface and push the package to IBM Cloud Function.

ibmcloud fn action update packageICDBackup action.zip --kind nodejs:10

Step 4: Create Trigger

The step to create trigger is straight forward here. What I want to showcase is the parameter. Once the trigger is created, click on the package

Click on Parameters at left hand menu and create 2 parameters — IAMToken and DeploymentId. IAMToken is the API key generated from Step 1, DeploymentId will be CRN of IBM Cloud Database service. When using a CRN, remember to URL encode the CRN value as it might include the forward-slash (/) %2F character.

Happy coding!

Github repo: https://github.com/ongkhaiwei/icdbackup

--

--