Ravi Sharma
Ravi Sharma

Reputation: 873

CouchDb data migration from 1.4 to 2.0

I am updating CouchDB from 1.4 to 2.0 on my windows 8 system. I have taken backup of my data and view files from /var/lib/couchdb and uninstalled 1.4.

Installed 2.0 successfully and its running. Now I copied all data to /var/lib/couchdb and /data folder but futon is not showing any database.

I created a new database "test" and its accessible in futon but I could not find it in /data dir.

Configuration:

default.ini:
[couchdb]
uuid = 
database_dir = ./data
view_index_dir = ./data

Also I want to understand that: will upgrade require re-indexing?

Upvotes: 2

Views: 1727

Answers (2)

Christian Meichsner
Christian Meichsner

Reputation: 171

Use this to migrate all databases residing in CouchDB's database_dir, e.g. /var/lib/couchdb

# cd to database dir, where all .couchdb files reside
cd /var/lib/couchdb

# create new databases in the target instance
for i in ./*.couch; do curl -X PUT http://machine2:5986$( echo $i | grep -oP '[^.]+(?=.couch)'); done

# one-time replication of each database from source to target instance
for i in ./*.couch; do curl -X POST http://machine1:5984/_replicate -H "Content-type: application/json" -d '{"source": "'"$( echo $i | grep -oP '[^./]+(?=.couch)')"'", "target": "http://machine2:5986'$( echo $i | grep -oP '[^.]+(?=.couch)')'"}'; done

If you are running both the source and the target CouchDB within a docker container on the same docker host, you might first check the docker host IP that is mapped into the source container in order to allow the source container to access the target container

/sbin/ip route|awk '/default/ { print $3 }'

Upvotes: 0

Sebastian Rothbucher
Sebastian Rothbucher

Reputation: 1483

you might want to look at the local port of the node you copied the data into: when you just copy data files, it will likely work, but they appear at another Port (5986 instead of 5984).

What this means is: when you copy the database file (those residing in the directory specified in /_config/couchdb/database_dir and ending with .couch; quoting https://blog.couchdb.org/2016/08/17/migrating-to-couchdb-2-0/ here) into the data directory of one of the nodes of the CouchDB 2.0 cluster (e.g., lib/node1/data), the database will appear in http://localhost:5986/_all_dbs (note 5986 instead of 5984: this is the so-called local port never intended for production use but helpful here).

As the local port is not a permanent solution, you can now start a replication from the local port to a clustered port (still quoting https://blog.couchdb.org/2016/08/17/migrating-to-couchdb-2-0/ - assuming you're dealing with a database named mydb resulting in a filename mydb.couch):

# create a clustered new mydb on CouchDB 2.0
curl -X PUT 'http://machine2:5984/mydb'

# replicate data (local 2 cluster)
curl -X POST 'http://machine2:5984/_replicate' -H 'Content-type: application/json' -d '{"source": "http://machine2:5986/mydb", "target": "http://machine2:5984/mydb"}' 

# trigger re-build index(es) of somedoc with someview; 
# do for all to speed up first use of application
curl -X GET 'http://machine2:5984/mydb/_design/_view/?stale=update_after'

As an alternative, you could also replicate from the old CouchDB (running) to the new one as you can replicate between 1.x and 2.0 just as you could replicate between 1.x and 1.x

Upvotes: 2

Related Questions