Linux: LVM snapshots of DRBD volumes

It is often convenient to use a Logical Volume (LVM2) as a DRBD backing device.  You then can use the DRBD device as usual, and create a filesystem on the DRBD device.  In addition to the many other benefits of LVM2, a DRBD device with an LVM backing device allows you to take snapshots of the device.  This article shows how to produce snapshots of these types of devices, and how to access your data.

A note on data consistency

The snapshot technique described here only works in the best of circumstances.  If you have a busy volume, or a filesystem type that does not ensure relational consistency, you will end up with filesystem corruption when you try to snapshot the volume.  Also, even if your filesystem is intact, if your application (such as a database), has not completed all its writes, you can end up with consistency problems within the application (database).  This is true even if you take the snapshot on the primary, instead of the secondary!

The only valid method to absolutely ensure data integrity is to quiesce all activity to the resource on the primary, verify that the secondary is up-to-date (if you're taking the snapshot on the secondary), and then snapshot the volume.  (This is, in no way a guarantee; it is simply a suggested strategy).  There are techniques to accomplish this for active filesystems and applications, but the techniques vary by filesystem and application.  If you are not sure how to quiesce (freeze) your filesystem and application(s), and data integrity is important, shut down your applications and cleanly unmount the filesystem before taking the snapshot!

Taking a snapshot of an active filesystem is never a valid strategy for backup and/or disaster recovery.  In these cases, you MUST ensure data integrity or your backups and/or DR plan is completely invalid.  However, if you need quick access to a volume, this technique can be an absolute lifesaver.  In future articles, I will try to show specific use cases where applications and the filesystem can be quiesced, and where this strategy is valid for backup and DR!