6

I'm trying to back up an LVM volume using Duplicity (note: not just the file contents of the volume, but the actual volume itself, byte-for-byte).

The best way I've so far found is to dd all the data on the LVM volume to a temporary file, include that file in the backup set, and delete it after the backup is made. This seems horribly inefficient, though: I'm needlessly thrashing the disk and duplicating all the data.

What would seem to be needed is a way to do essentially the opposite of mount -o loop. In other words, I don't want to mount a file as a block device: instead, I want to 'mount' a block device as a regular (read-only) binary file — one that Duplicity will then read from and back up for me.

Is there any way to achieve this?

George
  • 179

4 Answers4

4

There is a software project called diskfile, a FUSE filesystem which exposes block devices as regular readonly files. For example, with a folder mountpoint, you could call diskfile /dev/dm-0 mountpoint, and then mountpoint/dm-0 will be a regular file with the same contents as /dev/dm-0.

Daniel H
  • 1,696
3

It's not that duplicity has special treatment for block devices, it sees them for what they are, "block special files". For example,

$ stat /dev/dm-0
  File: ‘/dev/dm-0’
  Size: 0           Blocks: 0          IO Block: 4096   block special file
Device: 5h/5d   Inode: 10311       Links: 1     Device type: fc,0
Access: (0660/brw-rw----)  Uid: (    0/    root)   Gid: (    6/    disk)
Access: 2015-01-15 14:19:24.674418470 -0600
Modify: 2015-01-15 14:19:20.917418645 -0600
Change: 2015-01-15 14:19:20.917418645 -0600
 Birth: -

compared to:

$ stat /etc/passwd
  File: ‘/etc/passwd’
  Size: 2740        Blocks: 8          IO Block: 4096   regular file
Device: fc00h/64512d    Inode: 3802485     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-01-15 17:15:01.166461694 -0600
Modify: 2015-01-12 17:02:41.134820776 -0600
Change: 2015-01-12 17:02:41.201820651 -0600
 Birth: -

Duplicity will backup the block special file the same way tar or rsync does.

The only solution that comes to mind would be to write a fuse filesystem to presents all of your block devices as regular files. But that's probably out of the scope of this question.

Ben Grimm
  • 131
2

That's how block devices already work by default. They can be read by any program – after all, dd uses just the standard open() and read() functions to create the image.

grawity
  • 501,077
1

This is the normal way things already work.

Just add -r or -o ro to the mount options to make it read-only.


Man mount

 ro      The same as -r; mount the file system read-only 
         (even the super-user may not write it).
Hennes
  • 65,804
  • 7
  • 115
  • 169