DEV Community

ruchikaatwal
ruchikaatwal

Posted on • Updated on

Mongo Database dump & restore command - For ubuntu

Introduction for NoSQL database MongoDB :

1. MongoDB is a popular NoSQL document-oriented database that was first released in 2009.
2. MongoDB is an open-source database that is designed to be flexible and scalable, making it a popular choice for many modern web applications.
3. Unlike traditional relational databases, MongoDB stores data in flexible JSON-like documents, which allows for easy and fast querying of data.
4. MongoDB is known for its fast performance and scalability, making it an ideal choice for handling large amounts of data.

Enter fullscreen mode Exit fullscreen mode

Importance of why we need to backup data in MongoDB :

Problem :
- Data loss can be a serious problem for organisations that rely on MongoDB for their applications.
- Without proper backups, organisations may be at risk of losing critical data in the event of a hardware failure, software bug, or other issue.
- The process of backing up data can be time-consuming and complex, especially for organisations with large amounts of data.
Enter fullscreen mode Exit fullscreen mode
Highlights :
- Losing important data can be a major setback for any organisation, leading to lost revenue, decreased productivity, and damaged reputation.
- Without proper backups, organisations are putting their critical data at risk, which can lead to costly downtime and lost business opportunities.
- The process of backing up data can be a challenge for organisations, especially those that lack the resources or expertise to do it effectively.
Enter fullscreen mode Exit fullscreen mode
Solve :
- Schedule regular backups: Establish a regular backup schedule that meets your organisation's needs and make sure it is followed consistently.
- Use a reliable backup solution: Choose a backup solution that is reliable, secure, and easy to use. Consider options like MongoDB Cloud Backup or third-party backup tools.
- Test your backups: Regularly test your backups to make sure they are working as expected and can be used to restore data in the event of a failure.
- Consider a managed backup service: If you lack the expertise or resources to manage backups in-house, consider using a managed backup service that can handle backups for you.
- By implementing these solutions, organizations can protect their critical data and avoid the risk of data loss. With a reliable backup strategy in place, organizations can focus on their core business objectives and rest assured that their data is safe and secure.


Enter fullscreen mode Exit fullscreen mode

Mongo dump command

mongodump --host your_db_ip --port your_db_port --username db_username --password db_password -d database_name -c collection_name --out /folder_path --authenticationDatabase admin
Enter fullscreen mode Exit fullscreen mode

Mongo restore command

mongorestore -d database_name -c collection_name
/folder_path/database_folder_name/collection_file_name.bson --host your_db_ip --port your_db_port --username db_username --password db_password --authenticationDatabase admin
Enter fullscreen mode Exit fullscreen mode

Mongo dump command with zip

mongodump --host your_db_ip --port your_db_port --authenticationDatabase admin --username db_username --password db_password -d database_name -c collection_name --gzip
Enter fullscreen mode Exit fullscreen mode

Mongo restore command with zip

mongorestore --gzip --db database_name --collection collection_name ./collection_name.bson.gz --host your_db_ip --port your_db_port --authenticationDatabase admin --username db_username --password db_password
Enter fullscreen mode Exit fullscreen mode

Top comments (0)