From 8725d56bc9d202825dc616ad7ba5298269678372 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Wed, 26 May 2021 17:38:05 +0200 Subject: [PATCH] also add buffer on receving side --- tests/basetest.py | 2 ++ tests/test_sendrecvpipes.py | 26 ++++++++++++++++++++++++++ zfs_autobackup/ZfsAutobackup.py | 11 +++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/basetest.py b/tests/basetest.py index acb5f43..d862d0d 100644 --- a/tests/basetest.py +++ b/tests/basetest.py @@ -1,4 +1,6 @@ +# To run tests as non-root, use this hack: +# chmod 4755 /usr/sbin/zpool /usr/sbin/zfs import subprocess import random diff --git a/tests/test_sendrecvpipes.py b/tests/test_sendrecvpipes.py index 00d6aab..94e4e5c 100644 --- a/tests/test_sendrecvpipes.py +++ b/tests/test_sendrecvpipes.py @@ -47,3 +47,29 @@ class TestSendRecvPipes(unittest2.TestCase): self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--compress="+compress]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") + + def test_buffer(self): + """test different buffer configurations""" + + + with self.subTest("local local pipe"): + with patch('time.strftime', return_value="20101111000000"): + self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--buffer=1M" ]).run()) + + shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") + + with self.subTest("remote local pipe"): + with patch('time.strftime', return_value="20101111000000"): + self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-source=localhost", "--buffer=1M"]).run()) + + shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") + + with self.subTest("local remote pipe"): + with patch('time.strftime', return_value="20101111000000"): + self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-target=localhost", "--buffer=1M"]).run()) + + shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") + + with self.subTest("remote remote pipe"): + with patch('time.strftime', return_value="20101111000000"): + self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-source=localhost", "--ssh-target=localhost", "--buffer=1M"]).run()) diff --git a/zfs_autobackup/ZfsAutobackup.py b/zfs_autobackup/ZfsAutobackup.py index 2b5dc7a..73675b5 100644 --- a/zfs_autobackup/ZfsAutobackup.py +++ b/zfs_autobackup/ZfsAutobackup.py @@ -16,7 +16,7 @@ from zfs_autobackup.ThinnerRule import ThinnerRule class ZfsAutobackup: """main class""" - VERSION = "3.1-beta6" + VERSION = "3.1-beta7" HEADER = "zfs-autobackup v{} - (c)2021 E.H.Eefting (edwin@datux.nl)".format(VERSION) def __init__(self, argv, print_arguments=True): @@ -163,7 +163,7 @@ class ZfsAutobackup: self.log.error("Target should not start with a /") sys.exit(255) - if args.compress and not args.ssh_source and not args.ssh_target: + if args.compress and args.ssh_source is None and args.ssh_target is None: self.warning("Using compression, but transfer is local.") def verbose(self, txt): @@ -323,6 +323,13 @@ class ZfsAutobackup: ret.append(ExecuteNode.PIPE) logger("zfs recv custom pipe : {}".format(recv_pipe)) + # IO buffer + if self.args.buffer: + #only add second buffer if its usefull. (e.g. non local transfer or other pipes active) + if self.args.ssh_source!=None or self.args.ssh_target!=None or self.args.recv_pipe or self.args.send_pipe or self.args.compress!=None: + logger("zfs recv buffer : {}".format(self.args.buffer)) + ret.extend(["mbuffer", "-q", "-s128k", "-m"+self.args.buffer, ExecuteNode.PIPE ]) + return ret # NOTE: this method also uses self.args. args that need extra processing are passed as function parameters: