Skip to content
Script to perform a Cloudant backup to Cloud Object Storage
JavaScript Shell Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This is a proof-of-concept backup solution of Cloudant databases. It consists of Node.js app which when invoked backs up a single Cloudant database to IBM Cloud Object storage. It can be run on your machine, as a Docker container or scheduled to run periodically in a Kubernetes service.


The script knows which Cloudant database, Object Storage bucket and credentials to use from environment variables:

Running locally

Clone the repo:

git clone
cd scheduledcloudantbackup

Install the dependencies:

npm install


npm run start

Running as a Docker container

Build the Docker image:

docker build -t scheduledcloudantbackup .

Run (assuming you have environment variables set):

docker run \
  --env COUCH_URL="$COUCH_URL" \

Running in Kubernetes

  1. Sign up for a IBM Kubernetes service.
  2. Follow the instruction on how to install the ibmcloud command-line tools.
  3. Authenticate. e.g. ibmcloud login
  4. Set the Kubernetes target. e.g. ibmcloud ks region-set eu-gb
  5. Download the cluster config e.g. ibmcloud ks cluster-config scheduledcloudantbackup
  6. Log into the container registory service e.g. ibmcloud cr login
  7. Create a namespace e.g. ibmcloud cr namespace-add scheduledbackup
  8. Build an image e.g. ibmcloud cr build -t .

So we now have an image called in the IBM image registry - we next need to trigger it to run periodically with a Kubernetes cron job.

Kubernetes cron job

A "cron job" is a term taken from the Unix world - it means running a task periodically, say every hour. It has a syntax specifying the interval at which your code is to be run, in our case we want 0 * * * * which means "at the top of every hour".

Our cron job definition resides in a "cronjob.yml" file which tells the Kubernetes cluster which image to spin up, at what time and the environment variables it runs with. Edit the cronjob.yml to configure your Cloudant service and Object Storage details before running:

kubectl create -f cronjob.yml

Now wait until the top of the hour.

You can’t perform that action at this time.