Exporting data from Couchbase Server

First post about Couchbase Server - gotta start somewhere, so I'll briefly talk about a usecase that came up recently.

Sometimes, you want to export your data from Couchbase. It might be because you want to have a backup in another system, or you want to use the data for another process. Whatever it is, you need to have the data in a format that's accessible without having a live Couchbase cluster up, and going through the SDKs.

There's actually a very simple way to do this, which relies on the fact that Couchbase backup utilities store data in SQLite database file format. You can find all the utilities in the Couchbase bin directory.
On Windows: \<install dir>\Couchbase\Server\bin
On Linux: /opt/couchbase/bin

Step 1: Make a backup of your data with either cbbackup or cbtransfer. If you have a live cluster:

> cbbackup http://<host>:8091 <backup_folder> -u <user> -p <pass> -b <bucket>

If your Couchbase server is down, you can specify the data directory instead of the host URL, in couchstore-files protocol:

> cbbackup couchstore-files:///opt/couchbase/var/lib/couchbase/data  <backup_folder> -u <user> -p <pass> -b <bucket>

Note that the latter will only backup the data of this particular node. Also, if you haven't specified another location for the data files, you'll need admin/root permissions to access it.

Step 2: Go to the <backup_folder> directory, inside you'll find a folder named bucket-<bucket>, and inside it a subfolder per node in the cluster. In each of the node subfolders, there are *.cbb files, which hold the backup data for that bucket/node.

Despite the *.cbb extension, these are plain SQLite files, which you can open with any SQLite browser utility, or the appropriate SQLite driver for your language/platform.

You can grab a free, open-source, SQLite editor here: http://sourceforge.net/projects/sqlitebrowser/

Couchbase backup data in SQLite format

And there you go, all your data available to use ouside of Couchbase.

David Ostrovsky

I'm a level 38 Computer Geek, with experience in everything from databases to mobile apps. I'm also a Senior Solutions Architect at Couchbase, where I often keep clients happy by coding hard.

comments powered by Disqus