How to Back Up and Restore MongoDB

mongoDB

How to Back Up and Restore MongoDB

Simple 2 command MongoDB

mongodump     –> For dump all mongodb
mongorestore  –> For restore all mongodb

You can also specify the –host and –port of the MongoDB instance that the mongodump should connect to.

For example:

mongodump –host=mongodb.example.net –port=27017

To specify a different output directory, you can use the –out or -o option:

mongodump –out=/data/backup/

To limit the amount of data included in the database dump, you can specify –db and –collection as options to mongodump. For example:

mongodump –collection=myCollection –db=test

Create Backups from Non-Local mongod Instances

The –host and –port options for mongodump allow you to connect to and backup from a remote host. Consider the following example:

mongodump –host=mongodb1.test.com –port=3017 –username=user –password=”pass” –out=/opt/backup/mongodump

Basic mongorestore Operations

The mongorestore utility restores a binary backup created by mongodump. By default, mongorestore looks for a database backup in the dump/ directory.

The mongorestore utility restores data by connecting to a running mongod directly.

mongorestore can restore either an entire database backup or a subset of the backup.

Related posts

How to Install ISPConfig with Nginx Web Server on Ubuntu 24.04

Understanding Linux File Systems A Comprehensive Guide

20 Linux Administration Tips and Tricks to Help You Excel in a DevOps Career