Skip to content

Instantly share code, notes, and snippets.

@bekce
Last active February 22, 2017 13:14
Show Gist options
  • Select an option

  • Save bekce/4070a67dc23d003653d3af1833e1bb1e to your computer and use it in GitHub Desktop.

Select an option

Save bekce/4070a67dc23d003653d3af1833e1bb1e to your computer and use it in GitHub Desktop.
Upgrade MongoDB from 2.x to 3.4.x directly
sudo -s # shell out to root
cd
mongodump --out dump
service mongodb stop
# check if stopped and kill process if not
ps faux|grep mongod # then kill softly
ps faux|grep mongod|awk '{print $2}'|head -n 1|xargs kill
rm /var/lib/mongodb/mongod.lock
# backup data folder and configurations for extra protection
tar -cvzf data.tgz /var/lib/mongodb
tar -cvzf logs.tgz /var/log/mongodb
tar -cvzf conf.tgz /etc/mongo*
# remove and purge existing old packages
apt-get purge --auto-remove mongodb*
# delete data folder
rm -rf /var/lib/mongodb
# install new packages on ubuntu trusty (14.04)
# commands taken from https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
# warning: this part depends for your distribution, please look at the above link
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
# update package lists
apt-get update
apt-get install mongodb-org
# optional: adapt your old configuration to new yaml format if you were using a non-default configuration
# note that wiredTiger storage engine became the default in v3.2
nano /etc/mongod.conf
# start service (it is mongod instead of mongodb)
service mongod start
# connect to db and print version
mongo --eval 'db.version()'
# restore from dump
mongorestore dump
# voila!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment