Emergency Recovery Script from Couchbase disaster

Today, I dealt with a totally broken installation of Couchbase 2.0.0 Developer Preview. I couldn't find why but, although views were returning the right results, when I tried to retrieve a single document, I was getting the error below:

{
"error": "badrpc",
"reason": "{'EXIT',{{{badmatch,{error,closed}}, [{mc_client_binary,cmd_binary_vocal_recv,5}, {mc_client_binary,get_meta,3}, {ns_memcached,do_handle_call,3}, {gen_server,handle_msg,5}, {proc_lib,init_p_do_apply,3}]}, {gen_server,call, [{'ns_memcached-$data-default','ns...@127.0.0.1'}, {get_meta,<>,37}, 30000]}}}"
}


This is taken from Network Monitor panel on Chrome. On Coucbase admin console (:8091) the only message I got was "Unknown error".

I tried to upgrade the couchbase version by downloading one of the latests builds, which is said to be more stable and have less problems that Developer Preview. But, this is what happened when I tried to install the .deb package:
# dpkg -i couchbase-server-community_x86_2.0.0-1482-rel.deb
dpkg: warning: downgrading couchbase-server from 2.0.0dp4r to 2.0.0.
(Reading database ... 35466 files and directories currently installed.)
Preparing to replace couchbase-server 2.0.0dp4r (using couchbase-server-community_x86_2.0.0-1482-rel.deb) ...
* Stopped couchbase-server
Upgrading previous couchbase ... (2.0.0dp4r)
Stopping previous couchbase ... (2.0.0dp4r)
* Failed to stop couchbase-server
Saving previous couchbase config.dat ...
Cleaning symlinks ...
Unpacking replacement couchbase-server ...
Setting up couchbase-server (2.0.0) ...
Upgrading couchbase-server ...
/opt/couchbase/bin/install/cbupgrade -c /opt/couchbase/var/lib/couchbase/config -a yes
Automatic mode: running without interactive questions or confirmations.
Upgrading your Couchbase Server to 2.0.0-1482-rel.
The upgrade process might take awhile.
Analysing...
Previous config.dat file is /opt/couchbase/var/lib/couchbase/config/config.dat.debsave
Target node: ns_1@127.0.0.1
ERROR: bucket default is configured but missing: /opt/couchbase/var/lib/couchbase/data/default
dpkg: error processing couchbase-server (--install):
subprocess installed post-installation script returned error exit status 1
Processing triggers for ureadahead ...
Errors were encountered while processing:
couchbase-server

And my documents just disappeared. Lucky me, I had in one tab of my browser the result of an "all/all" view, which looks like this:

function (doc) {
emit(doc._id, null);
}


accessed from http://myserver:8092/default/_design/dev_all/_view/all?full_set=true&include_docs=true

Notice the include_docs and the missing limits (from, skip). This makes an entire dump of your database, in JSON, which I saved into a txt file.

After that, I wrote this small piece of code, in Python, and ran it. After a few seconds, I had access to my documents again.

The problem was hard. I was lucky. But I love this kind of simplicity. I think I can write a easy couchbase backup/export and recovery/import tool after this.

Popular posts from this blog

Diseño y comités

Revisiting charts: NodeJS, Twitter and Elasticsearch

Creating an e-commerce platform with Couchbase 2.0