davidbartonau / lvm-thin-sendrcv

Send and receive incremental / thin LVM snapshots on a live volume. Replication / synchronisation of an LVM volume to a remote server by transmitting only the difference between snapshots of a live / running volume.
GNU General Public License v3.0
23 stars 5 forks source link

lvm-thin-sendrcv

Send and receive incremental / thin LVM snapshots. Replication / synchronisation of an LVM volume to a remote server by transmitting only the difference between snapshots.

Status

Working in an initial form. Needs a little setup, documented at LVMSnapSend.md. Remember, you must never write to the target volume.

Monitor your thin LVs using LVMSpaceCheck Also useful is DDRandom.md

Purpose

LVM volumes (LVs) are useful, however synchronising them between machines is generally slow, especially when repeated. The goals of this project are:

The use case I am aiming for is to have VM images synchronised across to another server.

Prerequisites / Platform

This is only intended to run on thinly provisioned LVM.

I will be testing on Ubuntu, but welcome feedback for other platforms / OSes.

Goals

~~This is literally the start of the project. So far there is nothing. ~~Goals for the project are:

There is absolutely no intent to support synchronising without a snapshot.

Performance

Running on a single AWS small instance and via SSH, I am getting changes detected, read, transferred, and written at roughly 10MB/s. This means that for 50MB of writes, it takes ~5 seconds to do a sync. This is irrespective of the size of the underlying device. For devices in the 10s or 100s of GB this is a boon.

Running rsyncs of large file collections in the 10s and 100s of MB total e.g. /usr/bin or /usr/lib the size of changed blocks is very close to the size of the files. In other words, 10MB of files leads to 11 - 12 MB of block changes.

This performance makes it seem reasonable that we could potentially be synchronising the device every minute (or more frequently) once a service has been written.

Alternatives

Sponsors

This project is sponsored by:

Technical approach

Thin LVM is not the most well documented API. The high level approach for now is:

I will be maintaining at least a basic LVM document to outline how thing LVM snapshotting works as it seems like a useful service.

# Get the chunk size
lvs -o lv_name,chunksize volg/volg-thinpool

# Get the device IDs
SNAP1_ID=$(lvs --noheadings -o thin_id volg/thin_volume_snap4)
SNAP2_ID=$(lvs --noheadings -o thin_id volg/thin_volume_snap5)

# Reserve the metadata
dmsetup message /dev/mapper/volg-volg--thinpool-tpool 0 reserve_metadata_snap
dmsetup status /dev/mapper/volg-volg--thinpool-tpool  # Get the snapshot ID piping through: cut -f 7 -d " "

# Determine the difference between the snapshots
thin_delta  -m --snap1 $SNAP1_ID --snap2 $SNAP2_ID /dev/mapper/volg-volg--thinpool_tmeta

# Release the metadata snapshot.  Try to keep this window short.
dmsetup message /dev/mapper/volg-volg--thinpool-tpool 0 release_metadata_snap

# Take those blocks and push them to the target device / file.