Good morning.
We have been running couchdb for quite some time on our Ubuntu (18.04) server with no problem. Unfortunately, the IT department recently performed a number of updates that messed with a lot of things on the server. We've managed to get most of it back up and running, but we are still struggling with couchdb.
Our Python flask website did not load and the error log showed that it was unable to access couchdb. After investigating, we realised that couchdb was completely removed from the server.
We reinstalled couchdb but the version that was installed is version 3, and according to the prompt we got during installation our files in /var/lib/couchdb are for version 1, for which they recommend to use the replicator tool to upgrade them to version 3.
We've been trying to do this without success by following this guide and this one. I could be wrong because I'm not a couchdb expert, but it looks like the problem is that these tutorials tell us how to replicate a database from an already running couchdb, which we do not have a the moment (only the newly installed version with no database in it).
Currently, Python flask is able to connect to couchdb (the newly installed one) but does not find any database, and when trying to access the databases manually using couchdb commands, we are just prompted with:
{"error":"not_found","reason":"Database does not exist."}
We have a backup of the couchdb files, they look like a bunch of files with .couch extension. They also still are in /var/lib/couchdb.
The question is, how can we make these .couch files work with our newly installed version of couchdb?
Thanks in advance to anyone who can help with that.
I finally managed to do it, and this is how:
I installed an older version of Ubuntu server on a virtual machine (I used VirtualBox) and installed couchdb 1.6. I manually added my .couch files into /var/lib/couchdb using FileZilla. I tested that everything worked fine and it did.
After that I upgraded couchdb 1.6 to couchdb 2.3 and used the couchup tool that comes with couchdb 2 (note that couchdb 2 and 3 require you to set an admin password). This page shows how to use it. The couchup script is located in /opt/couchdb/bin.
I navigated to this folder and I ran the following:
$ python couchup list # Shows your unmigrated 1.x databases
$ python couchup replicate -a --login admin --password password # Replicates your 1.x DBs to 2.x
$ python couchup rebuild -a --login admin --password password # Optional; starts rebuilding your views
$ python couchup delete -a --login admin --password password # Deletes your 1.x DBs (careful!)
$ python couchup list # Should show no remaining databases!
It turns out that couchdb 2.x databases work just fine with couchdb 3 so there wasn't anything else needed. I uploaded the replicated databases to my deployed server and it worked right away.
INFO: note that with couchdb 1, each database you create appears as one single file. (e.g. db1.couch, db2.couch, etc.), but with couchdb 2 and 3 they are all located in the file _dbs.couch (you may want to transfer shards, _users.couch and the other files in /var/lib/couchdb to ensure everything works well).
INFO 2: the couchup utility is only installed by default with couchdb 2, you won't have it if you jump straight to couchdb 3. However, couchup is just a python script and I believe it is possible to download it from this github page, so you may not even need to install couchdb 2 (I have not tried it this way, so no guarantees).