This is an old revision of the document!
Overview
In this method, we simply export the database from the old release and import it in the new release. During this, the old database can be removed but it is best practice advise to keep the old release working on the old server just in case.
The steps for this method are simple:
- Make a backup of the database or server (using mongodump)
- Install the new software (preferably the latest)
- Import the backup into the release (using mongorestore)
So let's get going:
Backup
As mentioned before, mongo has two types of backup:
- Physical
- Logical
In that method, we are using the LOGICAL one, as the physical will NOT be compatible with the new release.
[root@localhost backup]# mongodump --out /root/backup/`date +"%m-%d-%y"` 2019-09-16T06:31:47.226-0400 writing admin.system.version to 2019-09-16T06:31:47.227-0400 done dumping admin.system.version (1 document) 2019-09-16T06:31:47.227-0400 writing admin.artists to 2019-09-16T06:31:47.227-0400 done dumping admin.artists (2 documents) [root@localhost backup]#
This command will export all not system databases and relations in the system.
Install new release
After that install the new software, either on the same server: By deleting the old one and installing the new one OR on a new server.
[root@localhost ~]# yum install mongodb-org-server.x86_64 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.it4i.cz * extras: mirror.it4i.cz * updates: mirror.it4i.cz | 2.5 kB 00:00:00 mongodb-org-4.2 | 2.5 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package mongodb-org-server.x86_64 0:4.2.14-1.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================================================================================================================= Updating: mongodb-org-server x86_64 4.2.14-1.el7 mongodb-org-4.2 20 M Transaction Summary ============================================================================================================================================================================================================================================= Upgrade 1 Package Total download size: 20 M Is this ok [y/d/N]: y Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. mongodb-org-server-4.2.14-1.el7.x86_64.rpm | 20 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : mongodb-org-server-4.2.14-1.el7.x86_64 1/2 2/2 Verifying : mongodb-org-server-4.2.14-1.el7.x86_64 1/2 2/2 Updated: mongodb-org-server.x86_64 0:4.2.14-1.el7 Complete! [root@localhost ~]#
Import the backup into the new release
After that, we can simply import the exported data into the new release as follows:
[root@localhost]# mongorestore --host 172.27.1.245 -u adminDBA -p 'password' --port 27017 /root/backup/10-25-19/ connected to:172.27.1.245:27017 2018-03-20T17:43:50.660+0100 /root/backup/admin/artists.bson 2018-03-20T17:43:50.660+0100 going into namespace [admin.artists] 2018-03-20T17:43:50.682+0100 Creating index: { key: { _id: 1 }, name: "_id_", ns: "admin.artists" } [root@lpara sales]