====== Database - MongoDB - Backup and Restore ====== ===== Backup using mongodump ===== Use mongodump. mongodump [--host mongodb01.sharewiz.net] [--port 27017] [--collection --myCollection --db test] [--username peter --password "PASSWORD"] [--oplog (point-in-time snapshot)] [--out /opt/backup/test-YYYY-MM-DD] **NOTE:** * Permissions required: grant find action, backup role. * Outputs BSON file formats. * Connects to mongod or mongos instance (on port 27017 if default). * Creates ./dump in current directory. * mongodump 2.2+ will not work with older mongod. ---- ===== Restoring using mongorestore ===== mongorestore [--host mongodb01.sharewiz,net] [--port 27017] [--username peter --password 'PASSWORD'] [/opt/backup/test-YYYY-MM-DD/] [--oplogReplay (restore snapshot)] [--objcheck (checks integrity prior to commit)] **NOTE:** * Permissions required: * MongoDB 3.2.10 and earlier, requires anyAction on anyResource grants * MongoDB 3.2.11 and newer, restore role with --oplogReplay * By default, ./dump is in the environmental paths ---- ===== Backup using mongoexport ===== mongoexport [--db contacts --collection crm --out /opt/backups/contacts.json] [--username peter --password 'PASSWORD'] [--host mongodb01.sharewiz.net --port 27017] **NOTE:** * Permissions required: read role ---- ===== Restore using mongoimport ===== mongoimport [--file /opt/backups/contacts.json] [--db contacts --collection crm] [--username peter --password 'PASSWORD'] [--host mongodb01.sharewiz.net --port 27017] **NOTE:** * Permissions required: readWrite role ----