unofficial-unifi / unifi-pfsense

A script that installs the UniFi Controller software on pfSense and other FreeBSD systems
BSD 2-Clause "Simplified" License
755 stars 245 forks source link

Upgrading controller version 6.0.45 to 6.2.26 results in incompatible DB #241

Closed ice124 closed 2 years ago

ice124 commented 3 years ago

The 6.2.26 merge on 6/18/2021 jumps the Mongodb from 3.6 to 4.2. By skipping the 4.0 version of Mongodb, an upgraded installation will fail to start up, as Mongodb is incapable of upgrading across more than one major release version.

Suggest modifying the install script to check the existing Mongodb version, and if it is more than one major release apart, either abort install or install the intermediate Mongodb releases and upgrade the DB until the target DB version is reached.

Here's the relevant log entry:

** IMPORTANT: UPGRADE PROBLEM: Found an invalid featureCompatibilityVersion document (ERROR: BadValue: Invalid value for version, found 3.6, expected '4.2' or '4.0'. Contents of featureCompatibilityVersion document in admin.system.version: { _id: "featureCompatibilityVersion", version: "3.6" }. See https://docs.mongodb.com/manual/release-notes/4.2-compatibility/#feature-compatibility.). If the current featureCompatibilityVersion is below 4.0, see the documentation on upgrading at https://docs.mongodb.com/manual/release-notes/4.2/#upgrade-procedures.
somebody-somewhere-over-the-rainbow commented 3 years ago

Can confirm the issue - had to uninstall and restore from backup

tong2x commented 3 years ago

there is new code in the commit that unlocks and removes older version of mongodb. not sure if possible to add code to install 4.0 if older is found.

thompatry commented 3 years ago

Not sure if this helps, but I was able to rollback to the May 30th version.

https://github.com/unofficial-unifi/unifi-pfsense/blob/e51c3a6f9b55080d1e9b6100a8d42daa30641ba9/install-unifi/install-unifi.sh

ccottam commented 3 years ago

removing mongodb 4.2 version and installing the 4.0 version did allow me to get the unifi controller to start.

I couldn't then upgrade to 4.2, so there's still some upgrade step that's required

thompatry commented 3 years ago

So I was digging around the internet and found someone that had same issue. They manage to get it working but it takes some time.

https://forums.gentoo.org/viewtopic-p-8535757.html?sid=b30b27b56d542e94801fad6041933a2e#8535757

ccottam commented 3 years ago

having installed mongodb 4.0, I could run the mongo client and update the compatibility version - then rerunning the install script updated to mongodb4.2 and started without any issue

mongo localhost:27117

> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "3.6" }, "ok" : 1 }
>  db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } )
{ "ok" : 1 }
> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "4.0" }, "ok" : 1 }
shortbloke commented 3 years ago

Could anyone explain the steps of how do you install mongodb40 on PfSense 2.4.5-RELEASE-p1? So that I can go through the intermediate database upgrade process to go from 6.2.25 to 6.4.54, which goes from mongodb 3.6 to 4.2.

johnkeates commented 3 years ago

This is one way to do it:

  1. Install the May 30 version first (https://github.com/unofficial-unifi/unifi-pfsense/blob/e51c3a6f9b55080d1e9b6100a8d42daa30641ba9/install-unifi/install-unifi.sh) to get a working mongo 3.6 database and make sure everything still works.

  2. Install a mongo 4.0 version: (Jun 1) https://raw.githubusercontent.com/unofficial-unifi/unifi-pfsense/4167b09685d1bdf881d9076ba01d8ff2ab173a81/install-unifi/install-unifi.sh

  3. Set the feature version to 4.0:

having installed mongodb 4.0, I could run the mongo client and update the compatibility version - then rerunning the install script updated to mongodb4.2 and started without any issue

mongo localhost:27117

> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "3.6" }, "ok" : 1 }
>  db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } )
{ "ok" : 1 }
> db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
{ "featureCompatibilityVersion" : { "version" : "4.0" }, "ok" : 1 }
  1. Install the newer Jun 1 version next (upgrades to 4.2) (https://raw.githubusercontent.com/unofficial-unifi/unifi-pfsense/c04a44f34f7c9c7c4e358d43dd7d74b1e676ef6a/install-unifi/install-unifi.sh)

At this point you have a mongodb that was upgraded from 3.6 to 4.0, then the database files were upgraded to 4.0 compatible, then upgrading to mongodb 4.2. allows you to see that it indeed works with the new format (repairs might be needed but the script does that for you)

So now you can install newer versions because the database file formats are now up-to-date.

  1. Install the latest version as per readme
tong2x commented 2 years ago

I am having this issue with one of my machine, my other machines upgrade ok with latest mongodb42. the follow is the log error when installing scripts with mongodb42. weird thing is I have already tried a clean install (using the clean uninstall script, even tried to make my own uninstall command for mongodb) what I have not yet tried is clean uninstall+uninstall mongodb+check files in(usr/lib/bin/mongodb) using mongodb40 works fine for unifi

how do I fully uninstall mongodb?

Fetching mongodb42-4.2.17.txz: .......... done Installing mongodb42-4.2.17... pkg: mongodb42-4.2.17 conflicts with mongodb40-4.0.27 (installs files into the same place). Problematic file: /usr/local/bin/install_compass ignored by forced mode pkg: mongodb42-4.2.17 conflicts with mongodb40-4.0.27 (installs files into the same place). Problematic file: /usr/local/bin/mongo ignored by forced mode pkg: mongodb42-4.2.17 conflicts with mongodb40-4.0.27 (installs files into the same place). Problematic file: /usr/local/bin/mongod ignored by forced mode pkg: mongodb42-4.2.17 conflicts with mongodb40-4.0.27 (installs files into the same place). Problematic file: /usr/local/bin/mongos ignored by forced mode pkg: mongodb42-4.2.17 conflicts with mongodb40-4.0.27 (installs files into the same place). Problematic file: /usr/local/etc/mongodb.conf.sample ignored by forced mode pkg: mongodb42-4.2.17 conflicts with mongodb40-4.0.27 (installs files into the same place). Problematic file: /usr/local/etc/rc.d/mongod ignored by forced mode

running the commands above before upgrading seems to fail also...