31.6. Verifying Replication and Recovery
Verification is more than a green resource status. It should show that a write reaches the peer, that a client sees the primary's data, that a link outage is detected and repaired, and that the chosen recovery copy contains the expected bytes. The exercises below use the client, the bitmap, and file checksums to test each of those claims, and they restore an independent copy to show the difference between replication and backup.
31.6.1. Writing and Comparing Data Across a Switchover
A verification record should identify the data, the node that wrote it, and the
point in time. The example's records.txt accumulated lines as the procedure
progressed. The important checks are not the exact words but the comparison:
the same bytes appear on the peer after a clean switchover, the client sees what
the primary wrote, and the recovered copy matches the chosen authoritative
copy.
The measured hashes in this chapter are:
| Copy | SHA-256 |
|---|---|
Initial alpha 1 / beta 2 on both nodes |
669ac839f1f45f3c9715a1f97fa63316870a1c4a9847d3218933811ef93f93ae |
| Client's independent backup of that version | 669ac839f1f45f3c9715a1f97fa63316870a1c4a9847d3218933811ef93f93ae |
| Authoritative copy after split-brain resolution | 7052ff059e6c1bc09da6d8eda815823b0a07df12d7aa4357274db889e354fb07 |
| Preserved divergent copy from the losing node | d9693d8aee633d3c1b2ff5fc252a73a8a0c2de9bc15e8f6877c52dd2da148585 |
The initial hash matching on both nodes after the first planned switchover is
the basic replication check. It proves that the file's bytes traveled through
DRBD and that the new primary serves the same content. The later authoritative
hash differs because the file gained the client 3, during-failure 4, and
authoritative-alpha lines. The divergent hash differs because it contains
divergent-bravo instead of authoritative-alpha. The difference is the
evidence that split brain produced two histories, not one history with a lost
write.
For a production check, use a file whose contents and ownership matter, and
compare more than the file size. sha256sum detects changed bytes, but it does
not prove that the application's internal state is consistent. A database
should be checked with its native consistency tools, and a file service should
be checked with an actual client read after the service restarts. A checksum
taken while a writer is active can also capture a torn or partially written
file; stop writers or use an application-consistent snapshot for the
comparison.
31.6.2. Isolating Replication Traffic and Restoring Connectivity
A link failure is easy to simulate without touching the management network.
The nft command comes from the nftables package; install it with
sudo apt install nftables if the command is not present. On drbd1, create a
separate nftables table and a base chain for input. These
commands are silent when they succeed:
$ sudo nft add table inet ch31
Each nftables command in this sequence normally prints nothing. The table is a private container for the test rules:
$ sudo nft add chain inet ch31 input '{ type filter hook input priority filter; }'
$ sudo nft add rule inet ch31 input iifname "eth1" tcp dport 7789 drop
Add an output chain and rule so that locally generated traffic to the peer is also rejected:
$ sudo nft add chain inet ch31 output '{ type filter hook output priority filter; }'
$ sudo nft add rule inet ch31 output oifname "eth1" tcp dport 7789 reject with tcp reset
The nftables syntax used here has these parts:
| Element | Meaning |
|---|---|
add table inet ch31 |
Create an isolated table for this exercise |
add chain ... { type filter hook input priority filter; } |
Create a base chain attached to the input hook |
iifname "eth1" |
Match packets arriving on the replication interface |
oifname "eth1" |
Match packets leaving the replication interface |
tcp dport 7789 |
Match the DRBD replication port |
drop |
Silently discard the packet |
reject with tcp reset |
Reject with a TCP reset so the sender fails quickly |
delete table inet ch31 |
Remove the table, its chains, and all rules in it |
The input rule drops incoming replication packets and the output rule rejects
outgoing ones. The management interface eth0 is not matched, so the SSH
session continues to work. The isolated node's resource leaves the connected
state. This excerpt was captured on drbd1 during the initial provisioning of
the example, while drbd1 was primary and before the filesystem had been
created, so its activity counters are small; on a resource that has served
data, the counters are larger but the meaningful fields are the same:
$ cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C95F202D36359D5A59245EB
0: cs:WFConnection ro:Primary/Unknown ds:UpToDate/DUnknown C r-----
ns:524236 nr:0 dw:0 dr:524236 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
WFConnection means the node is waiting for the connection. The peer state is
unknown, and the local disk remains UpToDate. The primary can still serve
local writes, but they are not reaching the peer. This is the state that makes
a second failure dangerous: the primary is healthy but no longer replicated.
Remove the table to restore connectivity:
$ sudo nft delete table inet ch31
The command normally prints nothing. On drbd1, inspect the resource:
$ sudo drbdadm status r0
r0 role:Primary
disk:UpToDate
peer role:Secondary
replication:Established peer-disk:UpToDate
DRBD reconnects automatically when the packets can flow again. If it does not, check that the address and port are reachable, that the peer's resource is still configured, and that no other firewall rule is blocking TCP 7789. Do not leave the test table in place; if the node reboots, a persistent nftables configuration could make the outage survive the exercise. The table in this example exists only in the running ruleset and is removed explicitly.
31.6.3. Checking Client Writes During Peer Failure and Recovery
The client's view during a peer failure is deceptive: writes continue to
succeed because the primary's local disk is healthy. The client cannot tell
whether the write reached the peer. The administrator must check the DRBD
connection state, not just the client's exit status. The sequence in section
31.4.1 shows the pattern: the primary reports peer connection:Connecting, the
client appends during-failure 4, and the file read succeeds. When the peer
returns, the dirty bitmap sends the missed blocks and the peer becomes
UpToDate.
The check should include the write on the primary as well as the client read.
After the client appends, read the file on the primary. If the primary shows
the line but the peer is still Connecting, the line exists on one copy. If the
primary does not show the line, the problem is in NFS, the mount, or the client,
not in DRBD. After the peer reconnects, check the peer's disk state and, for a
critical file, compare a checksum on both nodes. A successful client write is
not evidence of redundancy.
During an extended peer outage, monitor the primary's free space and the
bitmap growth. The primary keeps accepting writes, but the amount that must be
resynchronized grows. If the link is likely to stay down, decide whether to
continue serving, degrade the service, or stop writes. DRBD 8.4 has no
on-no-quorum policy to make that decision automatically. The administrator or
the cluster manager must make it explicitly, and the choice should be part of
the runbook.
Test the client's recovery behavior too. After the peer returns, does the client need to remount? In this example it does not, because the NFS server stayed on the same primary throughout the peer outage. After a role change, the client must unmount the old primary and mount the new one unless a virtual IP and a cluster-managed NFS service handle the move. The difference between "peer failure" and "primary failure" is important: the first can leave the client untouched, while the second always interrupts the client's server.
31.6.4. Verifying Resynchronization and Restoring an Independent Backup
Resynchronization is complete when the rebuilt node's disk is UpToDate and a
read of the data matches the chosen source. The replacement procedure in
section 31.4.5 provides both checks: the SyncTarget counters show the copy in
progress, and the final sha256sum after completion matches the authoritative
hash. A status line that still says Inconsistent is not a success; keep
polling until it changes. A
matching checksum on a file that was written before the failure is good
evidence, but it does not prove that every block of a large device is correct.
For higher confidence, use DRBD's online verification with a configured
verify-alg, or compare application-level checksums over the whole dataset.
The independent backup is a separate recovery path. On the primary drbd2,
start the NFS server again:
$ sudo systemctl start nfs-server
The command normally prints nothing. On drbdclient, mount the export:
$ sudo mount -t nfs drbd2:/srv/drbd-data /mnt/drbd
The mount normally prints nothing. Restore the backup to a separate file rather than overwriting the live records. This makes the comparison safe and keeps the current data available:
$ cp ~/debian-handbook/drbd/backup-records.txt /mnt/drbd/restored-records.txt
The copy normally prints nothing. Compare the two files:
$ sha256sum ~/debian-handbook/drbd/backup-records.txt /mnt/drbd/restored-records.txt
669ac839f1f45f3c9715a1f97fa63316870a1c4a9847d3218933811ef93f93ae /home/john/debian-handbook/drbd/backup-records.txt
669ac839f1f45f3c9715a1f97fa63316870a1c4a9847d3218933811ef93f93ae /mnt/drbd/restored-records.txt
The two hashes match, so the backup file made it through NFS and the DRBD mount without change. The restored copy is the earlier two-line version, not the current five-line file. That is the point of a point-in-time backup: it restores what existed when the copy was taken, not the latest state. If the live file had been deleted or corrupted, this copy would restore the earlier content, but the later client and authoritative lines would still need to be recovered from another source or accepted as lost.
Remove the test file and unmount the client so the exercise does not leave a stray copy inside the replicated filesystem:
$ rm /mnt/drbd/restored-records.txt
$ sudo umount /mnt/drbd
On drbd2, as john, stop the NFS server:
$ sudo systemctl stop nfs-server
Each command normally prints nothing. Leaving restored-records.txt in the live
mount would replicate it to the peer, which is harmless here but untidy for a
verification procedure. Cleaning up also makes the next test start from a known
state.
A backup is only useful if it is restorable. Test the restore path on a separate file or a separate host, record how long it takes, and verify that the restored data is usable by the application. A copy that has never been read back is a hope, not a backup. The DRBD secondary improves availability, but it does not preserve the earlier version, and it cannot recover data that was deleted or corrupted on both nodes.