Database Reference
In-Depth Information
Once the backup system has read the drive from the snapshot, then the old blocks that have been subsequently changed
can be released back to the drive's free space chain (or whatever mechanism the filesystem uses to mark free space).
To make this an effective method of creating a backup, we must either have the MongoDB journal files existing
on this same device or get MongoDB to flush all outstanding disk writes to the disk so we can take a snapshot. The
feature that forces MongoDB to do this flushing is called fsync ; the function that blocks further writes is called a lock .
MongoDB has the ability to perform both operations at the same time, so that after the fsync, no further writes are
done to the disk until the lock is released. By having the journal on the same device or performing an fsync and lock,
we make the image of the database on the disk consistent and ensure that it stays consistent until we have completed
the snapshot.
You use the following commands to make MongoDB enter the fsync and lock state:
$mongo
>use admin
>db.fsyncLock()
{
"info" : "now locked against writes",
"ok" : 1
}
You use these commands to check the current state of the lock:
$mongo
>use admin
>db.currentOp()
{
"inprog" : [
],
"fsyncLock" : 1
}
The "fsyncLock": 1 status indicates that MongoDB's fsync process, which is responsible for writing changes to
the disk, is currently blocked from performing writes.
At this point, you can issue whatever commands are required to make your volume manager create the snapshot
of the folders where MongoDB has its datafiles stored. Once the snapshot is completed, you can use the following
commands to release the lock:
$mongo
>db.fsyncUnlock();
{ "ok" : 1, "info" : "unlock requested" }
Note that there may be a small delay before the lock is released; however, you can use the db.currentOp()
function to check the result.
When the lock is finally cleared, db.currentOp() will return the following:
$mongo
>use admin
>db.currentOp()
{ "inprog" : [] }
The { "inprog" : [] } line means that the lock has been released and MongoDB can start writing to the disk again.
Search WWH ::




Custom Search