Restore a Snapshot To restore a snapshot created with the above method, issue the following sequence of com- mands: 

lvcreate --size 1G --name mdb-new vg0 gzip -d -c mdb-snap01.gz | dd of=/dev/vg0/mdb-new mount /dev/vg0/mdb-new /srv/mongodb 

The above sequence does the following: 

• Creates a new logical volume named mdb-new , in the /dev/vg0 volume group. The path to the new device will be /dev/vg0/mdb-new . 

Warning: This volume will have a maximum size of 1 gigabyte. The original file system must have had a total size of 1 gigabyte or smaller, or else the restoration will fail. Change 1G to your desired volume size. 

• Uncompresses and unarchives the mdb-snap01.gz into the mdb-new disk image. 

• Mounts the mdb-new disk image to the /srv/mongodb directory. Modify the mount point to correspond to your MongoDB data file location, or other location as needed. 

Note: The restored snapshot will have a stale mongod.lock file. If you do not remove this file from the snap- shot, and MongoDB may assume that the stale lock file indicates an unclean shutdown. If you’re running with storage.journal.enabled enabled, and you do not use db.fsyncLock() , you do not need to remove the mongod.lock file. If you use db.fsyncLock() you will need to remove the lock. 

Restore Directly from a Snapshot To restore a backup without writing to a compressed gz file, use the following sequence of commands: 

umount /dev/vg0/mdb-snap01 lvcreate --size 1G --name mdb-new vg0 dd if =/dev/vg0/mdb-snap01 of=/dev/vg0/mdb-new mount /dev/vg0/mdb-new /srv/mongodb 

Remote Backup Storage You can implement off-system backups using the combined process (page 246) and SSH. 

This sequence is identical to procedures explained above, except that it archives and compresses the backup on a remote system using SSH. 

Consider the following procedure: 

umount /dev/vg0/mdb-snap01 dd if =/dev/vg0/mdb-snap01 | ssh username@example.com gzip > /opt/backup/mdb-snap01.gz lvcreate --size 1G --name mdb-new vg0 ssh username@example.com gzip -d -c /opt/backup/mdb-snap01.gz | dd of=/dev/vg0/mdb-new mount /dev/vg0/mdb-new /srv/mongodb 

## Create Backups on Instances that do not have Journaling Enabled 

If your mongod instance does not run with journaling enabled, or if your journal is on a separate volume, obtaining a functional backup of a consistent state is more complicated. As described in this section, you must flush all writes to disk and lock the database to prevent writes during the backup process. If you have a replica set configuration, then for your backup use a secondary which is not receiving reads (i.e. hidden member ). 

