Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CouchDB dump to file and load from file

I cannot replicate between two couchdb servers, so I would like to dump to file from one server and load from file into the other server.

I used this statement to dump and it worked fine:

curl -X GET http://localhost:5984/<DATABASE_NAME>/_all_docs?include_docs=true > FILE.txt

But when I used this statement to load:

curl -d @FILE.txt -H “Content-Type: application/json” -X POST http://localhost:5984/<DATABASE_NAME>/_bulk_docs

it failed like this:

curl: (6) Could not resolve host: application; Host not found {"error":"bad_content_type","reason":"Content-Type must be application/json"}

Any ideas?

like image 565
eriq Avatar asked Jul 24 '12 21:07

eriq


People also ask

How do I back up CouchDB?

To back up CouchDB data, use CouchDB replication to back up the data to another CouchDB installation. You can choose between a normal replication in one-shot mode or continuous replications. Back up all CouchDB databases. Use CouchDB replication to recover the backup databases from the backup CouchDB instance.

Where is CouchDB data stored?

Configuration Backups. CouchDB's configuration system stores data in . ini files under the configuration directory (by default, etc/ ). If changes are made to the configuration at runtime, the very last file in the configuration chain will be updated with the changes.

How does CouchDB replication work?

During replication, CouchDB will compare the source and the destination database to determine which documents differ between the source and the destination database. It does so by following the Changes Feeds on the source and comparing the documents to the destination.

Is CouchDB slow?

Quite the opposite: CouchDB is slower than many people expect. To some degree it has room to improve and optimize; but primarily CouchDB has decided that those costs are worthwhile for the broader good it brings. CouchDB fails the benchmarks, and aces the college of hard knocks.


2 Answers

As said, you should use the " and not the as argument of the -H option

If you are a Linux or MacOSX user you can use the couchdb-dump tool, which basically works on bash shell.

It dumps the database on a local file (ASCII text file), formatted as requested by http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API

Then you can restore it with the bulk document upload or with the couchdb-dump restore tool included in the package.

This is the link to the tool: https://github.com/animamea/couchdb-dump

But you can find other tools also:

https://github.com/stockr-labs/couchdbdump

https://github.com/zebooka/couchdb-dump

like image 188
Daniele B Avatar answered Oct 13 '22 22:10

Daniele B


You can use the following command line to convert the output of the curl command to the “docs” structure that the _bulk_docs requires:

curl -X GET 'http://localhost:5984/mydatabase/_all_docs?include_docs=true' | jq '{"docs": [.rows[].doc]}' | jq 'del(.docs[]._rev)' > db.json

jq is the name of an excellent command line processor very useful (i.e. in this situation).

Hope it helps.

like image 22
Roberto Avatar answered Oct 14 '22 00:10

Roberto