Video Transcript (English)
A common and robust way to create a backup in Linux is to use filesystem snapshots.
A snapshot is a complete copy of your data at a specific point in time. Snapshots can be used on all size systems, large or small.
In this video, we’ll cover some key factors to consider before creating a snapshot.
Like most backup options, snapshots are highly useful when it comes to disaster recovery.
Snapshots work by creating pointers between a source volume and the snapshot volume.
A snapshot volume is a point-in-time, read-only view of a source volume.
A volume is a container with a filesystem that allows us to store and access data.
Snapshots can be created with different tools depending on your operating system and needs, such as: Logical Volume Manager for Linux, MongoDB Ops Manager, or MongoDB Atlas
Most cloud providers have their own tools as well.
Now let’s go over some considerations when creating snapshots of MongoDB data.
First, it’s important for the database to be locked by using the fsyncLock() command. fsyncLock() forces MongoDB to flush all pending write operations to disk. It also locks the entire instance to prevent additional writes until the user releases the lock with a corresponding fsyncUnlock() command.
Another thing to consider is that sometimes components of a MongoDB deployment are stored separately.
For example, the journal is sometimes separated for performance reasons. The journal is a sequential, binary transaction log that’s used to bring the database into a valid state in the event of a hard shutdown.
If the journal is not a part of your snapshot, the snapshot will be incomplete.
If the journal is not a part of your snapshot, the snapshot will be incomplete.
It’s important to create a snapshot of your entire deployment.
Now let's discuss what happens after the snapshot is created.
After the snapshot is created, we need to decide how to extract the data from the snapshot for offline storage. There are several methods, but we’ll cover two of them: Snapshot volume archive, and Filesystem archive.
With a snapshot volume archive, we are taking a complete copy of the source volume, plus any changes that occurred while the snapshot was being created. We can do this by using the Linux `dd` utility, and it can make our resulting archive quite large.
With a filesystem archive, we are mounting our snapshot volume and using filesystem tools such as `tar` to archive the actual data files. Using this method can lead to a smaller archive.
Choosing which method to use comes down to what your backup plan requires. Some factors include size, the type of data, and performance requirements.
Awesome work! In this video, you learned some key factors to consider before creating a snapshot, such as: Locking the database before taking the snapshot. Unlocking the database once the snapshot is taken. Isolating the MongoDB deployment.