generalmongodb

Create and restore MongoDB backups

Backup

To back up the data contained in your database, create a dump file using the mongodump tool.

$ mongodump --authenticationDatabase admin --username root --password PASSWORD -d DATABASE_NAME -h localhost

This operation could take some time depending on the amount of data that you have stored in the database.

Restore

To restore data backed up using the previous command, restore a dump file using the mongorestore tool.

$ mongorestore --authenticationDatabase admin --username root --password PASSWORD PATH_TO_BACKUP_FILE

Note that the steps previously described will only back up the data contained inside your database. There may be other files that you should take into account when performing a full backup, such as files that may have been uploaded to the application. These files are stored in the application folder itself, so copy this folder to have a backup of your uploaded files.

Last modification December 21, 2022