2

I need to create off-site full backups of an LVM block device. Thinking the old dd over SSH method.

To ensure I have a consistent backup, should I create an LVM snapshot first?
So new changed blocks are written to the snapshot logical volume while I dd the original logical volume?
Then I'll just lvremove the snapshot to continue writing to the main logical volume.

Also I see that everyone says dd is the slowest and most inefficient way of doing this. What's the other option?
I can't see how you can get much faster for a full backup of a block device, without compression.

EDIT: Ok one thing I just remembered is that of course dd will transfer the blocks regardless of data at the FS-level. So for a 300GB LV with a single 1K text file, dd will transfer the full 300GB worth of blocks. Fair enough. The LV I'll be doing this to is kept at about 80% so not too worried about the extra 20% being transferred each time.

1

Snapshots: If the partition you want to backup is currently mounted, then yes, make a snapshot first. But, you should dd the snapshot, not the original volume. The content of the original volume will change if it is still mounted.

So new changed blocks are written to the snapshot logical volume while I dd the original logical volume?

No. If a block changes, then the old content is first copied to the snapshot. Then the block in the original volume gets overwritten with the new content. See http://tldp.org/HOWTO/LVM-HOWTO/snapshotintro.html for another explanation (I admit that it's not very intuitive how snapshots work. This double-copy is also why snapshotted volumes have bad write performance).

Also I see that everyone says dd is the slowest and most inefficient way of doing this. What's the other option?

As you said, the main problem is that will copy all blocks, regardless if the filesystem actually uses them. Alternatives are

  1. file-based backups (e.g. good old tar files). This of course has its own drawbacks, e.g. that you can't do restore a crashed disk with a simple dd, not saving bootloaders etc...
  2. Hybrid solutions. http://www.partimage.org/ does something like a "smart" dd of the disk. It understands enough of ext2/3/xfs to know which blocks are actually in use, and only copies those, assuming zero-filled blocks for everything else. partimage unfortunately doesn't support ext4 or btrfs.
  • Ah yes, I always forget LVM snapshots are that way round. Hence you do an lvremove to discard the snapshot and an lvconvert --merge to revert to the original state. The reason I'm going for block-level is that the LV contains a very large number of small files on slow storage and I suspect that a dd even when effectively transferring an extra 20% of data (free space) each time will be faster than a tar or rsync. Will let you know how I get on. – batfastad Jan 4 '16 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.