Guest User

Untitled

a guest
Nov 5th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. export hosts="localhost"
  4. export new_db="ratul"
  5. export new_user="ratul"
  6. export new_pass="ratul"
  7. export backup_path="/var/backups/mongobackups"
  8.  
  9. export old_db="ooop" # existing database name which'll be migrated
  10. sudo mkdir $backup_path
  11.  
  12. sudo sed -i 's/\(authorization:\)\(.*\)/\1 disabled/' /etc/mongod.conf
  13.  
  14. sudo systemctl restart mongodb
  15.  
  16. ### create backup of database
  17. sudo mongodump -d $old_db --out $backup_path/
  18.  
  19. ### restore the backed up database to new db
  20. sudo mongorestore -d $new_db --drop $backup_path/$old_db
  21.  
  22. mongo $new_db --eval "db.createUser({ user: '$new_user', pwd: '$new_pass', roles: [ { role: 'root', db: '$new_db' } ] });"
  23.  
  24.  
  25. sudo sed -i 's/\(authorization:\)\(.*\)/\1 enabled/' /etc/mongod.conf
  26.  
  27. sudo systemctl restart mongodb
Add Comment
Please, Sign In to add comment