Monday, 2 July 2018

Cloudant - Backups

Having invested a fair bit of time populating databases into Cloudant: -

I wanted to backup my databases, for safety's sake.

My IBM colleague, Glynn Bird, came to the rescue again: -

with his couchbackup tool.

It was a simple matter of installing the package: -

sudo npm install -g couchbackup

and then running it: -

export COUCH_DB=acctdb
couchbackup --db $COUCH_DB > $COUCH_DB.txt

I then got really clever, and used some script to extract the names of ALL my databases: -

curl -X GET -g $COUCH_URL/_all_dbs

which returned a JSON object comprising the names of my DBs: -


so I "merely" needed to remove the square brackets, the double-quotes and the commas.

Long story short, this is with what I ended up: -

declare -a arr=(`curl -s -X GET -g $COUCH_URL/_all_dbs | sed 's/[][]//g' | sed 's/,/ /g' | sed 's/"//g'`)
for i in "${arr[@]}"; do export COUCH_DB=$i; couchbackup --db $COUCH_DB > $COUCH_DB.txt; done

This pulls back the list of databases from Cloudant, removes the unwanted characters, and then runs the couchbackup command to extract each of them to a text file ….

Nice :-) 

No comments: