Cannot update / migrate 4.x database to 5.x or 6.x

Description

Hi,

I am trying to upgrade my server, which was on 4.x (I’m not sure of which version exactly as my instance is no longer running, but I believe it was the latest stable), to 5.x or 6.x.

Initially, I accomplished upgrading to 5.4.5 by doing:
sudo snap refresh --channel=5.x rocketchat-server

And this worked successfully. I then attempted to upgrade to 6.x release with:
sudo snap refresh --channel=6.x rocketchat-server

That worked, but it left rocket-chat in a non-running state, so I attempted to downgrade back to the 5.4.5 release with the same command as above, only this time I get errors:

error: cannot perform the following tasks:                                                                                                                                                                                                                                                                                                                                  
- Run pre-refresh hook of "rocketchat-server" snap if present (run hook "pre-refresh":                                                                                                                                                                                                                                                                                      
-----                                                                                                                                                                                                                                                                                                                                                                       
:92}}}                                                                                                                                                                                                                                                                                                                                                                      
1 : syntax error: operand expected (error token is "{"t":{"$date":"2023-04-17T23:20:34.027Z"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"js","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"connect (sync) TCP fast open","option":{"level":6,"name":30,"data":"01 00 00 00"},"error":{"what":"set_option: Protocol not available","messag
e":"Protocol not available","category":"asio.system","value":92}}}                                                                                                                                                                                                                                                                                                          
1 ")
/snap/rocketchat-server/1545/helpers/mongo.sh: line 50: ((: {"t":{"$date":"2023-04-17T23:20:35.148Z"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"js","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"connect (sync) TCP fast open","option":{"level":6,"name":30,"data":"01 00 00 00"},"error":{"what":"set_option: Protocol not available"
,"message":"Protocol not available","category":"asio.system","value":92}}}                                                                                                                                                                                                                                                                                                  
1 : syntax error: operand expected (error token is "{"t":{"$date":"2023-04-17T23:20:35.148Z"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"js","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"connect (sync) TCP fast open","option":{"level":6,"name":30,"data":"01 00 00 00"},"error":{"what":"set_option: Protocol not available","messag
e":"Protocol not available","category":"asio.system","value":92}}}                                                                                                                                                                                                                                                                                                          
1 ")                                                                                                                                                                                                                                                                                                                                                                        
/snap/rocketchat-server/1545/helpers/mongo.sh: line 50: ((: {"t":{"$date":"2023-04-17T23:20:36.250Z"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"js","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"connect (sync) TCP fast open","option":{"level":6,"name":30,"data":"01 00 00 00"},"error":{"what":"set_option: Protocol not available"
,"message":"Protocol not available","category":"asio.system","value":92}}}                                                                                                                                                                                                                                                                                                  
1 : syntax error: operand expected (error token is "{"t":{"$date":"2023-04-17T23:20:36.250Z"},"s":"I",  "c":"NETWORK",  "id":5693100, "ctx":"js","msg":"Asio socket.set_option failed with std::system_error","attr":{"note":"connect (sync) TCP fast open","option":{"level":6,"name":30,"data":"01 00 00 00"},"error":{"what":"set_option: Protocol not available","messag
e":"Protocol not available","category":"asio.system","value":92}}}                                                                                                                                                                                                                                                                                                          
1 ")  

...

[ERROR] mongod server start wait timed out
[ERROR] pre refresh migration script /snap/rocketchat-server/1545/migrations/pre_refresh/feature_compatibity/00-adopt_version.sh

I completely removed rocketchat-server and re-installed with:
sudo snap remove rocketchat-server && sudo snap install --channel=5.x rocketchat-server

which gets me a running server. However, when I restore my old database and restart the server, I (understandably) get an error:

+----------------------------------------------------------------------+
|                         ERROR! SERVER STOPPED                        |
+----------------------------------------------------------------------+
|                                                                      |
|  Your database migration failed:                                     |
|  index not found with name [userId_1]                                |
|                                                                      |
|  Please make sure you are running the latest version and try again.  |
|  If the problem persists, please contact support.                    |
|                                                                      |
|  This Rocket.Chat version: 5.4.5                                     |
|  Database locked at version: 272                                     |
|  Database target version: 281                                        |
|                                                                      |
|  Commit: 45d3ca8961fc16077ea849daa28ee3f8980d7914                    |
|  Date: Thu Mar 16 15:24:56 2023 -0300                                |
|  Branch: HEAD                                                        |
|  Tag: 5.4.5                                                          |
|                                                                      |
+----------------------------------------------------------------------+

I assume this error is because I’m trying to restore a 4.x database into a 5.4.5 server and it hasn’t run any migration scripts?

I can remove rocket-server and re-install 5.4.5 successfully, but then how can I restore my old database and have it migrate successfully?

When I install 6.x from snap (either directly, or refreshing to it from the 5.x release), no migration scripts seem to be ran, and I get this error starting:

 Error creating index: livechat_priority -> { name: 1 } {
   unique: true,
   partialFilterExpression: { '$and': [ [Object], [Object] ] }
 } MongoServerError: An equivalent index already exists with the same name but different options. Requested index: { v: 2, unique: true, key: { name: 1 }, name: "name_1", partialFilterExpression: { $and: [ { name: { $exists: true } }, { name: { $gt: "" } } ] } }, existing index: { v: 2, unique: true, key: { name: 1 }, name: "name_1" }
     at Connection.onMessage (/snap/rocketchat-server/1545/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/cmap/connection.js:230:30)
     at MessageStream.<anonymous> (/snap/rocketchat-server/1545/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/cmap/connection.js:61:60)
     at MessageStream.emit (events.js:400:28)
     at MessageStream.emit (domain.js:475:12)
     at processIncomingData (/snap/rocketchat-server/1545/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/cmap/message_stream.js:125:16)
     at MessageStream._write (/snap/rocketchat-server/1545/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/cmap/message_stream.js:33:9)
     at writeOrBuffer (internal/streams/writable.js:358:12)
     at MessageStream.Writable.write (internal/streams/writable.js:303:10)
     at Socket.ondata (internal/streams/readable.js:731:22)
     at Socket.emit (events.js:400:28)
     at Socket.emit (domain.js:475:12)
     at addChunk (internal/streams/readable.js:293:12)
     at readableAddChunk (internal/streams/readable.js:267:9)
     at Socket.Readable.push (internal/streams/readable.js:206:10)
     at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
     at TCP.callbackTrampoline (internal/async_hooks.js:130:17) {
   ok: 0,
   code: 85,
   codeName: 'IndexOptionsConflict',
   '$clusterTime': {
     clusterTime: new Timestamp({ t: 1681774969, i: 1 }),
     signature: {
       hash: new Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
       keyId: 0
     }
   },
   operationTime: new Timestamp({ t: 1681774969, i: 1 }),
   [Symbol(errorLabels)]: Set(0) {}
 }
 strict mode: use allowUnionTypes to allow union type keyword at "#/properties/value" (strictTypes)
 MessageType.render is deprecated. Use MessageType.message instead. livechat_webrtc_video_call
 {"level":40,"time":"2023-04-17T23:43:03.926Z","pid":7460,"hostname":"rocketchat-host","name":"VoIPService","msg":"Voip is not enabled. Cant start the service"}
 {"level":30,"time":"2023-04-17T23:43:04.231Z","pid":7460,"hostname":"rocketchat-host","name":"Federation","section":"Setup","msg":"Federation is disabled"}
 {"level":30,"time":"2023-04-17T23:43:05.557Z","pid":7460,"hostname":"rocketchat-host","name":"Search Logger","msg":"create search provider defaultProvider"}
 {"level":30,"time":"2023-04-17T23:43:05.807Z","pid":7460,"hostname":"rocketchat-host","name":"System","msg":"Updating process.env.MAIL_URL"}
 {"level":30,"time":"2023-04-17T23:43:06.302Z","pid":7460,"hostname":"rocketchat-host","name":"CAS","msg":"Disabling CAS login service"}
 {"level":51,"time":"2023-04-17T23:43:06.324Z","pid":7460,"hostname":"rocketchat-host","name":"Migrations","msg":"Migrating from version 272 -> 292"}
 {"level":51,"time":"2023-04-17T23:43:06.325Z","pid":7460,"hostname":"rocketchat-host","name":"Migrations","msg":"Running up() on version 273"}
 +----------------------------------------------------------------------+
 |                         ERROR! SERVER STOPPED                        |
 +----------------------------------------------------------------------+
 |                                                                      |
 |  Your database migration failed:                                     |
 |  index not found with name [userId_1]                                |
 |                                                                      |
 |  Please make sure you are running the latest version and try again.  |
 |  If the problem persists, please contact support.                    |
 |                                                                      |
 |  This Rocket.Chat version: 6.0.0                                     |
 |  Database locked at version: 272                                     |
 |  Database target version: 292                                        |
 |                                                                      |
 |  Commit: aa8f0ec70b2267af55d9ce9a3e3abfe7ff6c0a37                    |
 |  Date: Thu Mar 9 16:48:12 2023 -0300                                 |
 |  Branch: HEAD                                                        |
 |  Tag: 6.0.0                                                          |
 |                                                                      |
 +----------------------------------------------------------------------+

Could anyone please offer some guidance on how to go about resolving these errors and getting rocketchat back up and running?

Server Setup Information

  • Version of Rocket.Chat Server: 5.4.5
  • Operating System: Ubuntu 16.04
  • Deployment Method: snap
  • Number of Running Instances: 1
  • DB Replicaset Oplog: n/a
  • NodeJS Version:
  • MongoDB Version: 5.0.15
  • Proxy: nginx
  • Firewalls involved: none

Any additional Information

Hi! I would recommend using docker instead of snap.

What you can do it spin up a docker server with the same version you are running (or the latest one at the same major version, 4.X on your case)

Then up dump data from this server and restore it at the new one.

While snaps is a great technology, docker will give you more controle over your deployment :slight_smile: