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
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: -
["account","cartoon","foobar","snafu"]
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
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:
Post a Comment