This guide describes DRBD version 8.4 and above. For 8.3 please look here.


10.3. Using automated LVM snapshots during DRBD synchronization

While DRBD is synchronizing, the SyncTarget's state is Inconsistent until the synchronization completes. If in this situation the SyncSource happens to fail (beyond repair), this puts you in an unfortunate position: the node with good data is dead, and the surviving node has bad data.

When serving DRBD off an LVM Logical Volume, you can mitigate this problem by creating an automated snapshot when synchronization starts, and automatically removing that same snapshot once synchronization has completed successfully.

In order to enable automated snapshotting during resynchronization, add the following lines to your resource configuration:

Automating snapshots before DRBD synchronization. 

resource r0 {
  handlers {
    before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh";
    after-resync-target "/usr/lib/drbd/unsnapshot-resync-target-lvm.sh";
  }
}

The two scripts parse the $DRBD_RESOURCE$ environment variable which DRBD automatically passes to any handler it invokes. The snapshot-resync-target-lvm.sh script then create an LVM snapshot for any volume the resource contains immediately before synchronization kicks off. In case the script fails, the synchronization does not commence.

Once synchronization completes, the unsnapshot-resync-target-lvm.sh script removes the snapshot, which is then no longer needed. In case unsnapshotting fails, the snapshot continues to linger around.

[Important]Important

You should review dangling snapshots as soon as possible. A full snapshot causes both the snapshot itself and its origin volume to fail.

If at any time your SyncSource does fail beyond repair and you decide to revert to your latest snapshot on the peer, you may do so by issuing the lvconvert -M command.


This guide describes DRBD version 8.4 and above. For 8.3 please look here.