Skip to content

Instantly share code, notes, and snippets.

@csamsel
Last active January 6, 2025 19:42
Show Gist options
  • Save csamsel/9e8780934bf1b1929b87e9901a215173 to your computer and use it in GitHub Desktop.
Save csamsel/9e8780934bf1b1929b87e9901a215173 to your computer and use it in GitHub Desktop.
update unifi mongodb from 3.6 to 7.0 on Ubuntu 22.04, incl. migration from mmapv1 to wiredtiger
# i suggest to take a VM snapshot / backup just in case.
# first we install mongodb-database-tools from mongodb 4.4 which is still compatible with mmapv1
curl -fsSL https://pgp.mongodb.com/server-4.4.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-4.4.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-4.4.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
apt update
apt install mongodb-database-tools
# make backup of unifi mongodb
mkdir /root/backup
mongodump --port=27117 --out=/root/backup
# remove unifi and old mongodb installation
systemctl stop unifi
apt remove mongodb-server-core mongodb-database-tools unifi -y
# add repo for mongodb 7.0
rm /etc/apt/sources.list.d/mongodb-org-4.4.list
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
apt update
# update to mongodb 7.0
apt install mongodb-org-server mongodb-org-tools -y
# create empty mongodb
mv /var/lib/unifi/db /var/lib/unifi/db.old
mkdir /var/lib/unifi/db
mongod --dbpath=/var/lib/unifi/db &
# restore database
mongorestore /root/backup/
killall mongod
# secure files
chown -R unifi:unifi /var/lib/unifi/db
chmod 700 /var/lib/unifi/db
# update to mongodb 7.0 and reinstall unifi
apt install mongodb-org-server unifi -y
#restart unifi (check if everything is working)
systemctl start unifi
# clean up
rm -R /root/backup /var/lib/unifi/db.old
rm /usr/share/keyrings/mongodb-server-4.4.gpg /etc/apt/sources.list.d/mongodb-org-4.4.list
apt update
apt clean
apt autoremove
# gz now you have unifi working with mongodb 7.0 (you can now also upgrade to Ubuntu 24.04)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment