Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- export hosts="localhost"
- export new_db="ratul"
- export new_user="ratul"
- export new_pass="ratul"
- export backup_path="/var/backups/mongobackups"
- export old_db="ooop" # existing database name which'll be migrated
- sudo mkdir $backup_path
- sudo sed -i 's/\(authorization:\)\(.*\)/\1 disabled/' /etc/mongod.conf
- sudo systemctl restart mongodb
- ### create backup of database
- sudo mongodump -d $old_db --out $backup_path/
- ### restore the backed up database to new db
- sudo mongorestore -d $new_db --drop $backup_path/$old_db
- mongo $new_db --eval "db.createUser({ user: '$new_user', pwd: '$new_pass', roles: [ { role: 'root', db: '$new_db' } ] });"
- sudo sed -i 's/\(authorization:\)\(.*\)/\1 enabled/' /etc/mongod.conf
- sudo systemctl restart mongodb
Add Comment
Please, Sign In to add comment