Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Upgrade to Mongo 3.0.7
#!/bin/bash
echo "Requesting initial permissions (necessary to start and stop services)"
sudo echo "OK"
if [[ "$(uname)" == 'Darwin' ]]; then
platform='osx'
DB_PATH='/usr/local/var/mongodb'
LOG_PATH='/usr/local/var/log/mongodb/mongo.log'
CONFIG_PATH='/usr/local/etc/mongod.conf'
BACKUP_PATH="$HOME/mongobackups"
brew update
brew tap homebrew/services
else
platform='linux'
DB_PATH='/usr/local/var/mongodb'
LOG_PATH='/usr/local/var/log/mongodb/mongo.log'
CONFIG_PATH='/etc/mongod.conf'
BACKUP_PATH='$HOME/mongobackups'
fi
echo "=> Dumping database"
mkdir -p "$BACKUP_PATH/dump"
mongodump -d banff_development --out "$BACKUP_PATH/dump"
echo "=> Stopping mongod service"
if [[ "$platform" == 'osx' ]]; then
brew services stop mongo
else
sudo service mongod stop
fi
echo "=> Moving old database"
mkdir -p "$BACKUP_PATH/db"
sudo mv "$DB_PATH" "$BACKUP_PATH/db"
mkdir -p "$DB_PATH"
echo "=> Installing Mongo 3.0"
if [[ "$platform" == 'osx' ]]; then
brew install mongo
brew upgrade mongo
brew unlink mongodb26
brew link --overwrite mongodb
else
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools
fi
echo "=> Updating mongod.conf"
sudo mv $CONFIG_PATH $BACKUP_PATH/mongod.conf
cat > "$CONFIG_PATH" << EOF
storage:
dbPath: $DB_PATH
engine: wiredTiger
systemLog:
destination: file
path: $LOG_PATH
logAppend: true
net:
bindIp: 127.0.0.1
port: 27017
# Enable the HTTP interface (Defaults to port 28017).
http:
enabled: false
EOF
echo "=> Starting mongod service"
if [[ "$platform" == 'osx' ]]; then
brew services start mongo
else
sudo service mongod start
fi
echo "=> Importing database from dump"
mongorestore -d banff_development "$BACKUP_PATH/dump/banff_development"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.