Skip to main content

Upgrade MongoDB 3.4 to 4.4

Prompt

The upgrade duration is directly related to the number of collections in the MongoDB database
You can view the number of collections through find /data/mingdao/script/volume/data/mongodb/ -name '*collection*' | wc -l
For example, it takes 1 minute for a collection of less than 10000, about 10 minutes for 100000, and about 30 minutes for 300000

Stop service

Execute commands in the root directory of the manager:

bash ./service.sh stopall 

Backup data

If the mongodb directory has been backed up, you can skip this step

Before backup, it is necessary to confirm whether the remaining space on the server disk is sufficient

du -sh /data/mingdao/script/volume/data/mongodb

Create a backup, such as (adjusting the actual backup directory):

mkdir -p /backup && tar -zcvf /backup/mongodb3.4_$(date +%Y%m%d%H%M%S).tar.gz /data/mingdao/script/volume/data/mongodb

Upgrade

MongoDB upgrade requires version by version upgrade. Upgrading from 3.4 to 4.4 requires sequentially upgrading to 3.6, 4.0, 4.2, and 4.4, with a total of 4 upgrade commands to be executed.
If there is a version mismatch prompt during the upgrade process, the previous upgrade command needs to be executed repeatedly(For example, if the upgrade from 3.4 to 3.6 is successful and the upgrade from 3.6 to 4.0 prompts failure, the command from 3.4 to 3.6 needs to be executed again until the output of exit upgrade). If the error persists after multiple attempts, the specific reason can be checked through /data/mingdao/script/volume/data/mongodb/upgrade xxxx. log.

Pull upgrade secondary mirror ([Offline Package] (../../../../offline.md)):

docker pull registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-sc-upgrade:1.0.0

Execute upgrade command:

3.4 to 3.6

docker run -i --rm -v /data/mingdao/script/volume/data/mongodb:/data/mongodb registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-sc-upgrade:1.0.0 <<< 'upgradeMongodb.sh 3.4 3.6'

3.6 to 4.0

docker run -i --rm -v /data/mingdao/script/volume/data/mongodb:/data/mongodb registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-sc-upgrade:1.0.0 <<< 'upgradeMongodb.sh 3.6 4.0'

4.0 to 4.2

docker run -i --rm -v /data/mingdao/script/volume/data/mongodb:/data/mongodb registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-sc-upgrade:1.0.0 <<< 'upgradeMongodb.sh 4.0 4.2'

4.2 to 4.4

docker run -i --rm -v /data/mingdao/script/volume/data/mongodb:/data/mongodb registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-sc-upgrade:1.0.0 <<< 'upgradeMongodb.sh 4.2 4.4'

The final output of newRunVersion: 4.4 indicates that the upgrade is complete. 👏 👏

Several common output explanations

Successfully upgraded to the target version

oldRunVersion: 4.0
Upgrade 4.0 to 4.2...
{ "ok" : 1 }
newRunVersion: 4.2

Successfully executed target version upgrade script

oldRunVersion: 4.2
exit upgrade 4.0 to 4.2

Version mismatch, need to execute the previous successful upgrade command again

ERROR: child process failed, exited with error number 100
To see additional information in this output, start without the "--fork" option.
Failed