Ubuntu
- If a replica set is used — please contact Passwork technical support for proper updating and data preservation.
- If Passwork is installed on a virtual server, it is recommended to create a virtual OS snapshot before updating.
The instructions use switchable code blocks to separate commands according to operating system versions.
Preparation and removal of the outdated version
Creating a backup
Create a directory:
- shell
mkdir /backup
Create a backup:
- shell
mongodump --out /backup/mongo-$(date +\%Y-\%m-\%d_\%H-\%M-\%S)
Removal
Stop the service:
- shell
systemctl stop mongod.service
Move the configuration file:
- shell
mv /etc/mongod.conf ./
Remove the database with configuration files:
- shell
apt purge mongodb-org* -y
Remove the directory with log files:
- shell
rm -r /var/log/mongodb
Remove MongoDB data files:
- shell
rm -r /var/lib/mongodb
Remove the outdated repository for MongoDB 4.x:
- shell
rm -f /etc/apt/sources.list.d/mongodb-org-4.x.list
Update the list of available packages:
- shell
apt-get update
Installation and backup restoration
Installation
Download and convert the MongoDB GPG key to a file:
- Ubuntu 24.04
- Ubuntu 22.04 20.04
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
--dearmor
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
--dearmor
Add the repository line to the file:
- Ubuntu 24.04
- Ubuntu 22.04
- Ubuntu 20.04
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
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
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
Update the list of available packages:
- shell
apt-get update
Install MongoDB using the apt package manager:
- shell
apt-get install -y mongodb-org
Start the mongod.service:
- shell
systemctl start mongod.service
Enable service autostart:
- shell
systemctl enable mongod.service
Perform a connection check to the shell:
- shell
mongosh mongodb://localhost:27017
Backup restoration
If the connection to the shell is successful, restore the databases from the backup:
- shell
mongorestore --drop /backup/mongo-xxxx-xx-xx_xx-xx-xx
If you made changes to the MongoDB configuration file (mongod.conf), you need to replace the new file with the old one:
- shell
cp ./mongod.conf /etc/
Restart the mongod.service:
- shell
systemctl restart mongod.service
Open Passwork to verify correct operation.