- Step 1: Create Backup folder
sudo mkdir /var/backups/mongobackups
- Step 2: Backup database with following command
sudo mongodump -h SERVER_NAME:PORT -u DATABASE_USER -p PASSWORD --db appdb --out /var/backups/mongobackups/`date +"%m-%d-%y"`
An important argument to mongodump is --db, which specifies the name of the database which you want to back up. In this example appdb
is name of database that we want to backup. If you don't specify a database name, mongodump backups all of your databases. The second important argument is --out which specifies the directory in which the data will be dumped.