Skip to content

Instantly share code, notes, and snippets.

@aquasmit
Last active September 17, 2017 03:53
Show Gist options
  • Save aquasmit/f526a54c97f89578ec29b1f4639fd492 to your computer and use it in GitHub Desktop.
Save aquasmit/f526a54c97f89578ec29b1f4639fd492 to your computer and use it in GitHub Desktop.
Backup MongoDB database

Backup MongoDB database

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment