Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: reverse mode #18

Open
piojan opened this issue Mar 19, 2021 · 0 comments
Open

Feature: reverse mode #18

piojan opened this issue Mar 19, 2021 · 0 comments

Comments

@piojan
Copy link

piojan commented Mar 19, 2021

One usage of your script is to make backup of LVM volumes. Or more precisely snapshots of LVM volumes. This works quite well.
However there are some security considerations that might make it better to initiate the backup process from the backup target - if the production machine is impacted then the backups are still inaccessible.

I have made a small modification. Looks like it is working for LVM2LVM copy. I have not touched any aspects of file creating and safety. Would be nice if someone reviews this (maybe improves) and merges.

diff blocksync.py blocksync_v2.py
110c110,114
<     f, size = do_open(dev, 'rb+')
---
>     if options.reverse:
>       f, size = do_open(dev, 'rb')
>     else:
>       f, size = do_open(dev, 'rb+')
>
133,138c137,146
<             newblock = stdin.read(blocksize)
<             newblocklen = len(newblock)
<             f.seek(-newblocklen, 1)
<             f.write(newblock)
<             if USE_DONTNEED:
<                 fadvise(f, f.tell() - newblocklen, newblocklen, POSIX_FADV_DONTNEED)
---
>           if options.reverse:
>               stdout.write(block)
>               stdout.flush()
>           else:
>               newblock = stdin.read(blocksize)
>               newblocklen = len(newblock)
>               f.seek(-newblocklen, 1)
>               f.write(newblock)
>               if USE_DONTNEED:
>                   fadvise(f, f.tell() - newblocklen, newblocklen, POSIX_FADV_DONTNEED)
188c196,199
<         f, size = do_open(srcdev, 'rb')
---
>         if options.reverse:
>           f, size = do_open(srcdev, 'rb+')
>       else:
>           f, size = do_open(srcdev, 'rb')
245a257,259
>     if options.reverse:
>         cmd += ['-R']
>
320,322c334,343
<                 p_in.write(l_block)
<                 p_in.flush()
<
---
>                 if options.reverse:
>                   newblock = p_out.read(blocksize)
>                   newblocklen = len(newblock)
>                   f.seek(-newblocklen, 1)
>                   f.write(newblock)
>                   if USE_DONTNEED:
>                       fadvise(f, f.tell() - newblocklen, newblocklen, POSIX_FADV_DONTNEED)
>               else:
>                   p_in.write(l_block)
>                   p_in.flush()
361a383
>     parser.add_option("-R", "--reverse", dest = "reverse", action = "store_true", help = "Remote location to local", default = False)

froloffw7 added a commit to froloffw7/blocksync that referenced this issue May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant