Published on

How to take backup and restore backup in MongoDB

Authors

How to take backup and restore backup in MongoDB

How to take backup in mongoDB

  1. Create Backups from Non-Local mongodb Instances
  mongodump --uri=mongodb+srv://<PROJECT_NAME_ON_MONGO_ATLAS>.ppmkd.gcp.mongodb.net/<YOUR_DATABASE_NAME>  --username=<YOUR_USER_NAME>  --password=<YOUR_PASSWORD> --out=<PATH_TO_SET_BACK_UP> --gzip
  1. Create backup from local
mongodump --uri=mongodb://localhost:<YOUR_PORT>/<DB_NAME>     --out=./ --gzip

How to restore backup in mongoDB

  1. Restore to remote
mongorestore --uri=mongodb+srv://<PROJECT_NAME_ON_MONGO_ATLAS>.ppmkd.gcp.mongodb.net/<YOUR_DATABASE_NAME> --db=<YOUR_DATABASE>  --username=<YOUR_USER_NAME>  --password=<YOUR_PASSWORD> --gzip <PATH_TO_FOLDER_THAT_CONTAINS_BACKUP>
  1. Restore to local
mongorestore --uri=mongodb://localhost:<YOUR_PORT> --db=<DB_NAME>  --gzip <PATH_TO_FOLDER_THAT_CONTAINS_BACKUP>