mpalmer / lvmsync

Synchronise LVM LVs across a network by sending only snapshotted changes
http://theshed.hezmatt.org/lvmsync
GNU General Public License v3.0
380 stars 60 forks source link

If destdevice is a file, lvmsync truncates it #44

Closed inejge closed 9 years ago

inejge commented 9 years ago

I recently tried using lvmsync to migrate a LVM-backed VM to an image file. The only thing that stops it from working is that destdevice is opened with the 'w+' mode, which truncates it if it's a file. If I change the mode to 'r+', syncing to a file works:

--- lvmsync-3.3.1/bin/lvmsync.orig      2015-03-08 12:55:07.000000000 +0100
+++ lvmsync-3.3.1/bin/lvmsync   2015-03-08 12:02:05.000000000 +0100
@@ -145,7 +145,7 @@
        snapback.puts handshake if snapback

        verbose "Writing changed data to #{destdev.inspect}"
-       File.open(destdev, 'w+') do |dest|
+       File.open(destdev, 'r+') do |dest|
                while header = instream.read(12)
                        offset, chunksize = header.unpack("QN")
                        offset = ntohq(offset)

Is there a reason not to use 'r+' here?

mpalmer commented 9 years ago

No reason comes to mind. I've released 3.3.2 with your patch. Thanks!