- Published on
How to take backup and restore backup in MongoDB
- Authors
- Name
- Milad E. Fahmy
- @miladezzat12
How to take backup and restore backup in MongoDB
How to take backup in mongoDB
- 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
- Create backup from local
mongodump --uri=mongodb://localhost:<YOUR_PORT>/<DB_NAME> --out=./ --gzip
How to restore backup in mongoDB
- 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>
- Restore to local
mongorestore --uri=mongodb://localhost:<YOUR_PORT> --db=<DB_NAME> --gzip <PATH_TO_FOLDER_THAT_CONTAINS_BACKUP>