diff --git a/tests/test_destroymissing.py b/tests/test_destroymissing.py index e2b49fa..3eb7783 100644 --- a/tests/test_destroymissing.py +++ b/tests/test_destroymissing.py @@ -13,10 +13,10 @@ class TestZfsNode(unittest2.TestCase): def test_destroymissing(self): #initial backup - with patch('time.strftime', return_value="10101111000000"): #1000 years in past + with patch('time.strftime', return_value="test-10101111000000"): #1000 years in past self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-holds".split(" ")).run()) - with patch('time.strftime', return_value="20101111000000"): #far in past + with patch('time.strftime', return_value="test-20101111000000"): #far in past self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-holds --allow-empty".split(" ")).run()) diff --git a/tests/test_encryption.py b/tests/test_encryption.py index 32fb60d..f27cef8 100644 --- a/tests/test_encryption.py +++ b/tests/test_encryption.py @@ -48,11 +48,11 @@ class TestZfsEncryption(unittest2.TestCase): self.prepare_encrypted_dataset("11111111", "test_source1/fs1/encryptedsourcekeyless", unload_key=True) # raw mode shouldn't need a key self.prepare_encrypted_dataset("22222222", "test_target1/encryptedtarget") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-progress --allow-empty --exclude-received".split(" ")).run()) self.assertFalse(ZfsAutobackup("test test_target1/encryptedtarget --verbose --no-progress --no-snapshot --exclude-received".split(" ")).run()) - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-progress --allow-empty --exclude-received".split(" ")).run()) self.assertFalse(ZfsAutobackup("test test_target1/encryptedtarget --verbose --no-progress --no-snapshot --exclude-received".split(" ")).run()) @@ -85,11 +85,11 @@ test_target1/test_source2/fs2/sub encryption self.prepare_encrypted_dataset("11111111", "test_source1/fs1/encryptedsource") self.prepare_encrypted_dataset("22222222", "test_target1/encryptedtarget") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-progress --decrypt --allow-empty --exclude-received".split(" ")).run()) self.assertFalse(ZfsAutobackup("test test_target1/encryptedtarget --verbose --no-progress --decrypt --no-snapshot --exclude-received".split(" ")).run()) - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-progress --decrypt --allow-empty --exclude-received".split(" ")).run()) self.assertFalse(ZfsAutobackup("test test_target1/encryptedtarget --verbose --no-progress --decrypt --no-snapshot --exclude-received".split(" ")).run()) @@ -120,11 +120,11 @@ test_target1/test_source2/fs2/sub encryptionroot - self.prepare_encrypted_dataset("11111111", "test_source1/fs1/encryptedsource") self.prepare_encrypted_dataset("22222222", "test_target1/encryptedtarget") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-progress --encrypt --debug --allow-empty --exclude-received".split(" ")).run()) self.assertFalse(ZfsAutobackup("test test_target1/encryptedtarget --verbose --no-progress --encrypt --debug --no-snapshot --exclude-received".split(" ")).run()) - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-progress --encrypt --debug --allow-empty --exclude-received".split(" ")).run()) self.assertFalse(ZfsAutobackup("test test_target1/encryptedtarget --verbose --no-progress --encrypt --debug --no-snapshot --exclude-received".split(" ")).run()) @@ -155,14 +155,14 @@ test_target1/test_source2/fs2/sub encryptionroot - self.prepare_encrypted_dataset("11111111", "test_source1/fs1/encryptedsource") self.prepare_encrypted_dataset("22222222", "test_target1/encryptedtarget") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup( "test test_target1 --verbose --no-progress --decrypt --encrypt --debug --allow-empty --exclude-received".split(" ")).run()) self.assertFalse(ZfsAutobackup( "test test_target1/encryptedtarget --verbose --no-progress --decrypt --encrypt --debug --no-snapshot --exclude-received".split( " ")).run()) - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup( "test test_target1 --verbose --no-progress --decrypt --encrypt --debug --allow-empty --exclude-received".split(" ")).run()) self.assertFalse(ZfsAutobackup( diff --git a/tests/test_externalfailures.py b/tests/test_externalfailures.py index b5960dc..821c718 100644 --- a/tests/test_externalfailures.py +++ b/tests/test_externalfailures.py @@ -32,7 +32,7 @@ class TestExternalFailures(unittest2.TestCase): def test_initial_resume(self): # inital backup, leaves resume token - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.generate_resume() # --test should resume and succeed @@ -81,11 +81,11 @@ test_target1/test_source2/fs2/sub@test-20101111000000 def test_incremental_resume(self): # initial backup - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) # incremental backup leaves resume token - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.generate_resume() # --test should resume and succeed @@ -138,7 +138,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 self.skipTest("Resume not supported in this ZFS userspace version") # inital backup, leaves resume token - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.generate_resume() # remove corresponding source snapshot, so it becomes invalid @@ -148,11 +148,11 @@ test_target1/test_source2/fs2/sub@test-20101111000000 shelltest("zfs destroy test_target1/test_source1/fs1/sub; true") # --test try again, should abort old resume - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --test".split(" ")).run()) # try again, should abort old resume - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) r = shelltest("zfs list -H -o name -r -t all test_target1") @@ -176,22 +176,22 @@ test_target1/test_source2/fs2/sub@test-20101111000000 self.skipTest("Resume not supported in this ZFS userspace version") # initial backup - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) # icremental backup, leaves resume token - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.generate_resume() # remove corresponding source snapshot, so it becomes invalid shelltest("zfs destroy test_source1/fs1@test-20101111000001") # --test try again, should abort old resume - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --test".split(" ")).run()) # try again, should abort old resume - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) r = shelltest("zfs list -H -o name -r -t all test_target1") @@ -215,17 +215,17 @@ test_target1/test_source2/fs2/sub@test-20101111000000 if "0.6.5" in ZFS_USERSPACE: self.skipTest("Resume not supported in this ZFS userspace version") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) # generate resume - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.generate_resume() with OutputIO() as buf: with redirect_stdout(buf): # incremental, doesnt want previous anymore - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): self.assertFalse(ZfsAutobackup( "test test_target1 --no-progress --verbose --keep-target=0 --allow-empty".split(" ")).run()) @@ -253,11 +253,11 @@ test_target1/test_source2/fs2/sub@test-20101111000002 if "0.6.5" in ZFS_USERSPACE: self.skipTest("Resume not supported in this ZFS userspace version") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) # generate resume - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.generate_resume() shelltest("zfs destroy test_source1/fs1@test-20101111000001") @@ -265,7 +265,7 @@ test_target1/test_source2/fs2/sub@test-20101111000002 with OutputIO() as buf: with redirect_stdout(buf): # incremental, doesnt want previous anymore - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): self.assertFalse(ZfsAutobackup( "test test_target1 --no-progress --verbose --no-snapshot".split( " ")).run()) @@ -277,14 +277,14 @@ test_target1/test_source2/fs2/sub@test-20101111000002 def test_missing_common(self): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) # remove common snapshot and leave nothing shelltest("zfs release zfs_autobackup:test test_source1/fs1@test-20101111000000") shelltest("zfs destroy test_source1/fs1@test-20101111000000") - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertTrue(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) #UPDATE: offcourse the one thing that wasn't tested had a bug :( (in ExecuteNode.run()). @@ -295,7 +295,7 @@ test_target1/test_source2/fs2/sub@test-20101111000002 # #recreate target pool without any features # # shelltest("zfs set compress=on test_source1; zpool destroy test_target1; zpool create test_target1 -o feature@project_quota=disabled /dev/ram2") # -# with patch('time.strftime', return_value="20101111000000"): +# with patch('time.strftime', return_value="test-20101111000000"): # self.assertFalse(ZfsAutobackup("test test_target1 --verbose --allow-empty --no-progress".split(" ")).run()) # # r = shelltest("zfs list -H -o name -r -t all test_target1") diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 6090b2a..6f11dfd 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -11,17 +11,17 @@ class TestZfsNode(unittest2.TestCase): def test_keepsource0target10queuedsend(self): """Test if thinner doesnt destroy too much early on if there are no common snapshots YET. Issue #84""" - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup( "test test_target1 --no-progress --verbose --keep-source=0 --keep-target=10 --allow-empty --no-send".split( " ")).run()) - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup( "test test_target1 --no-progress --verbose --keep-source=0 --keep-target=10 --allow-empty --no-send".split( " ")).run()) - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): self.assertFalse(ZfsAutobackup( "test test_target1 --no-progress --verbose --keep-source=0 --keep-target=10 --allow-empty".split( " ")).run()) diff --git a/tests/test_scaling.py b/tests/test_scaling.py index 49568f6..0e54db6 100644 --- a/tests/test_scaling.py +++ b/tests/test_scaling.py @@ -33,7 +33,7 @@ class TestZfsScaling(unittest2.TestCase): run_counter=0 with patch.object(ExecuteNode,'run', run_count) as p: - with patch('time.strftime', return_value="20101112000000"): + with patch('time.strftime', return_value="test-20101112000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --keep-source=10000 --keep-target=10000 --no-holds --allow-empty".split(" ")).run()) @@ -46,7 +46,7 @@ class TestZfsScaling(unittest2.TestCase): run_counter=0 with patch.object(ExecuteNode,'run', run_count) as p: - with patch('time.strftime', return_value="20101112000001"): + with patch('time.strftime', return_value="test-20101112000001"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --keep-source=10000 --keep-target=10000 --no-holds --allow-empty".split(" ")).run()) @@ -73,7 +73,7 @@ class TestZfsScaling(unittest2.TestCase): run_counter=0 with patch.object(ExecuteNode,'run', run_count) as p: - with patch('time.strftime', return_value="20101112000000"): + with patch('time.strftime', return_value="test-20101112000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-holds --allow-empty".split(" ")).run()) @@ -87,7 +87,7 @@ class TestZfsScaling(unittest2.TestCase): run_counter=0 with patch.object(ExecuteNode,'run', run_count) as p: - with patch('time.strftime', return_value="20101112000001"): + with patch('time.strftime', return_value="test-20101112000001"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-holds --allow-empty".split(" ")).run()) diff --git a/tests/test_sendrecvpipes.py b/tests/test_sendrecvpipes.py index a8ac73e..48e2a07 100644 --- a/tests/test_sendrecvpipes.py +++ b/tests/test_sendrecvpipes.py @@ -16,25 +16,25 @@ class TestSendRecvPipes(unittest2.TestCase): with self.subTest("local local pipe"): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") with self.subTest("remote local pipe"): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-source=localhost", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") with self.subTest("local remote pipe"): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-target=localhost", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") with self.subTest("remote remote pipe"): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-source=localhost", "--ssh-target=localhost", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) def test_compress(self): @@ -43,7 +43,7 @@ class TestSendRecvPipes(unittest2.TestCase): for compress in zfs_autobackup.compressors.COMPRESS_CMDS.keys(): with self.subTest("compress "+compress): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): 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") @@ -53,25 +53,25 @@ class TestSendRecvPipes(unittest2.TestCase): with self.subTest("local local pipe"): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-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"): + with patch('time.strftime', return_value="test-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"): + with patch('time.strftime', return_value="test-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"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--ssh-source=localhost", "--ssh-target=localhost", "--buffer=1M"]).run()) def test_rate(self): @@ -79,7 +79,7 @@ class TestSendRecvPipes(unittest2.TestCase): start=time.time() - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup(["test", "test_target1", "--exclude-received", "--no-holds", "--no-progress", "--rate=50k" ]).run()) #not a great way of verifying but it works. diff --git a/tests/test_zfsautobackup.py b/tests/test_zfsautobackup.py index 666d78b..e95c02b 100644 --- a/tests/test_zfsautobackup.py +++ b/tests/test_zfsautobackup.py @@ -33,7 +33,7 @@ class TestZfsAutobackup(unittest2.TestCase): def test_snapshotmode(self): """test snapshot tool mode""" - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test --no-progress --verbose".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -57,7 +57,7 @@ test_target1 with self.subTest("no datasets selected"): with OutputIO() as buf: with redirect_stderr(buf): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertTrue(ZfsAutobackup("nonexisting test_target1 --verbose --debug --no-progress".split(" ")).run()) print(buf.getvalue()) @@ -67,7 +67,7 @@ test_target1 with self.subTest("defaults with full verbose and debug"): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --debug --no-progress".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -96,7 +96,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 """) with self.subTest("bare defaults, allow empty"): - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --allow-empty --no-progress".split(" ")).run()) @@ -167,14 +167,14 @@ test_target1/test_source2/fs2/sub@test-20101111000001 userrefs 1 - #make sure time handling is correctly. try to make snapshots a year appart and verify that only snapshots mostly 1y old are kept with self.subTest("test time checking"): - with patch('time.strftime', return_value="20111111000000"): + with patch('time.strftime', return_value="test-20111111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --allow-empty --verbose --no-progress".split(" ")).run()) time_str="20111112000000" #month in the "future" future_timestamp=time_secs=time.mktime(time.strptime(time_str,"%Y%m%d%H%M%S")) with patch('time.time', return_value=future_timestamp): - with patch('time.strftime', return_value="20111111000001"): + with patch('time.strftime', return_value="test-20111111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --allow-empty --verbose --keep-source 1y1y --keep-target 1d1y --no-progress".split(" ")).run()) @@ -214,7 +214,7 @@ test_target1/test_source2/fs2/sub@test-20111111000001 r=shelltest("zfs snapshot test_source1/fs1@othersimple") r=shelltest("zfs snapshot test_source1/fs1@otherdate-20001111000000") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -249,7 +249,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 r=shelltest("zfs snapshot test_source1/fs1@othersimple") r=shelltest("zfs snapshot test_source1/fs1@otherdate-20001111000000") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --other-snapshots".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -284,7 +284,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 def test_nosnapshot(self): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-snapshot --no-progress".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -308,7 +308,7 @@ test_target1/test_source2/fs2 def test_nosend(self): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-send --no-progress".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -331,7 +331,7 @@ test_target1 def test_ignorereplicated(self): r=shelltest("zfs snapshot test_source1/fs1@otherreplication") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --ignore-replicated".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -360,7 +360,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 def test_noholds(self): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-holds --no-progress".split(" ")).run()) r=shelltest("zfs get -r userrefs test_source1 test_source2 test_target1") @@ -392,7 +392,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 userrefs 0 - def test_strippath(self): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --strip-path=1 --no-progress".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -428,7 +428,7 @@ test_target1/fs2/sub@test-20101111000000 r=shelltest("zfs set refreservation=1M test_source1/fs1") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --clear-refreservation".split(" ")).run()) r=shelltest("zfs get refreservation -r test_source1 test_source2 test_target1") @@ -466,7 +466,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 refreservation - self.skipTest("This zfs-userspace version doesnt support -o") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --clear-mountpoint --debug".split(" ")).run()) r=shelltest("zfs get canmount -r test_source1 test_source2 test_target1") @@ -499,18 +499,18 @@ test_target1/test_source2/fs2/sub@test-20101111000000 canmount - - def test_rollback(self): #initial backup - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) #make change r=shelltest("zfs mount test_target1/test_source1/fs1") r=shelltest("touch /test_target1/test_source1/fs1/change.txt") - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): #should fail (busy) self.assertTrue(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): #rollback, should succeed self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --rollback".split(" ")).run()) @@ -518,14 +518,14 @@ test_target1/test_source2/fs2/sub@test-20101111000000 canmount - - def test_destroyincompat(self): #initial backup - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) #add multiple compatible snapshot (written is still 0) r=shelltest("zfs snapshot test_target1/test_source1/fs1@compatible1") r=shelltest("zfs snapshot test_target1/test_source1/fs1@compatible2") - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): #should be ok, is compatible self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) @@ -535,19 +535,19 @@ test_target1/test_source2/fs2/sub@test-20101111000000 canmount - - r=shelltest("zfs snapshot test_target1/test_source1/fs1@incompatible1") - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): #--test should fail, now incompatible self.assertTrue(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --test".split(" ")).run()) - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): #should fail, now incompatible self.assertTrue(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) - with patch('time.strftime', return_value="20101111000003"): + with patch('time.strftime', return_value="test-20101111000003"): #--test should succeed by destroying incompatibles self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --destroy-incompatible --test".split(" ")).run()) - with patch('time.strftime', return_value="20101111000003"): + with patch('time.strftime', return_value="test-20101111000003"): #should succeed by destroying incompatibles self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --destroy-incompatible".split(" ")).run()) @@ -585,13 +585,13 @@ test_target1/test_source2/fs2/sub@test-20101111000003 #test all ssh directions - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --ssh-source localhost --exclude-received".split(" ")).run()) - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --ssh-target localhost --exclude-received".split(" ")).run()) - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --ssh-source localhost --ssh-target localhost".split(" ")).run()) @@ -636,7 +636,7 @@ test_target1/test_source2/fs2/sub@test-20101111000002 def test_minchange(self): #initial - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --min-change 100000".split(" ")).run()) #make small change, use umount to reflect the changes immediately @@ -646,7 +646,7 @@ test_target1/test_source2/fs2/sub@test-20101111000002 #too small change, takes no snapshots - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --min-change 100000".split(" ")).run()) #make big change @@ -654,7 +654,7 @@ test_target1/test_source2/fs2/sub@test-20101111000002 r=shelltest("zfs umount test_source1/fs1; zfs mount test_source1/fs1") #bigger change, should take snapshot - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --min-change 100000".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -687,7 +687,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 def test_test(self): #initial - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --test".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -704,12 +704,12 @@ test_target1 """) #actual make initial backup - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) #test incremental - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --allow-empty --verbose --test".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -745,7 +745,7 @@ test_target1/test_source2/fs2/sub@test-20101111000001 shelltest("zfs create test_target1/test_source1") shelltest("zfs send test_source1/fs1@migrate1| zfs recv test_target1/test_source1/fs1") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -778,15 +778,15 @@ test_target1/test_source2/fs2/sub@test-20101111000000 def test_keep0(self): """test if keep-source=0 and keep-target=0 dont delete common snapshot and break backup""" - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --keep-source=0 --keep-target=0".split(" ")).run()) #make snapshot, shouldnt delete 0 - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test --no-progress --verbose --keep-source=0 --keep-target=0 --allow-empty".split(" ")).run()) #make snapshot 2, shouldnt delete 0 since it has holds, but will delete 1 since it has no holds - with patch('time.strftime', return_value="20101111000002"): + with patch('time.strftime', return_value="test-20101111000002"): self.assertFalse(ZfsAutobackup("test --no-progress --verbose --keep-source=0 --keep-target=0 --allow-empty".split(" ")).run()) r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) @@ -818,7 +818,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 """) #make another backup but with no-holds. we should naturally endup with only number 3 - with patch('time.strftime', return_value="20101111000003"): + with patch('time.strftime', return_value="test-20101111000003"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --keep-source=0 --keep-target=0 --no-holds --allow-empty".split(" ")).run()) r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) @@ -848,7 +848,7 @@ test_target1/test_source2/fs2/sub@test-20101111000003 # run with snapshot-only for 4, since we used no-holds, it will delete 3 on the source, breaking the backup - with patch('time.strftime', return_value="20101111000004"): + with patch('time.strftime', return_value="test-20101111000004"): self.assertFalse(ZfsAutobackup("test --no-progress --verbose --keep-source=0 --keep-target=0 --allow-empty".split(" ")).run()) r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) @@ -883,7 +883,7 @@ test_target1/test_source2/fs2/sub@test-20101111000003 r = shelltest("zfs snapshot test_source1@test") l=LogConsole(show_verbose=True, show_debug=False, color=False) - n=ZfsNode("test",l) + n=ZfsNode(snapshot_time_format="bla", hold_name="bla", logger=l) d=ZfsDataset(n,"test_source1@test") sp=d.send_pipe([], prev_snapshot=None, resume_token=None, show_progress=True, raw=False, send_pipes=[], send_properties=True, write_embedded=True, zfs_compressed=True) diff --git a/tests/test_zfsautobackup31.py b/tests/test_zfsautobackup31.py index baa9111..4d56856 100644 --- a/tests/test_zfsautobackup31.py +++ b/tests/test_zfsautobackup31.py @@ -10,10 +10,10 @@ class TestZfsAutobackup31(unittest2.TestCase): def test_no_thinning(self): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --keep-target=0 --keep-source=0 --no-thinning".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) @@ -54,10 +54,10 @@ test_target1/test_source2/fs2/sub@test-20101111000001 shelltest("zfs create test_target1/a") shelltest("zfs create test_target1/b") - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1/a --no-progress --verbose --debug".split(" ")).run()) - with patch('time.strftime', return_value="20101111000001"): + with patch('time.strftime', return_value="test-20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1/b --no-progress --verbose".split(" ")).run()) r=shelltest("zfs list -H -o name -r -t snapshot test_target1") @@ -75,7 +75,7 @@ test_target1/b/test_target1/a/test_source1/fs1/sub@test-20101111000000 def test_zfs_compressed(self): - with patch('time.strftime', return_value="20101111000000"): + with patch('time.strftime', return_value="test-20101111000000"): self.assertFalse( ZfsAutobackup("test test_target1 --no-progress --verbose --debug --zfs-compressed".split(" ")).run()) diff --git a/tests/test_zfsnode.py b/tests/test_zfsnode.py index 4d64e00..e916205 100644 --- a/tests/test_zfsnode.py +++ b/tests/test_zfsnode.py @@ -12,60 +12,60 @@ class TestZfsNode(unittest2.TestCase): def test_consistent_snapshot(self): logger = LogStub() description = "[Source]" - node = ZfsNode("test", logger, description=description) + node = ZfsNode(snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) with self.subTest("first snapshot"): - node.consistent_snapshot(node.selected_datasets(exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=200000), "test-1", 100000) + node.consistent_snapshot(node.selected_datasets(property_name="autobackup:test",exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=200000), "test-20101111000001", 100000) r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) self.assertEqual(r, """ test_source1 test_source1/fs1 -test_source1/fs1@test-1 +test_source1/fs1@test-20101111000001 test_source1/fs1/sub -test_source1/fs1/sub@test-1 +test_source1/fs1/sub@test-20101111000001 test_source2 test_source2/fs2 test_source2/fs2/sub -test_source2/fs2/sub@test-1 +test_source2/fs2/sub@test-20101111000001 test_source2/fs3 test_source2/fs3/sub test_target1 """) with self.subTest("second snapshot, no changes, no snapshot"): - node.consistent_snapshot(node.selected_datasets(exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=200000), "test-2", 1) + node.consistent_snapshot(node.selected_datasets(property_name="autobackup:test",exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=200000), "test-20101111000002", 1) r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) self.assertEqual(r, """ test_source1 test_source1/fs1 -test_source1/fs1@test-1 +test_source1/fs1@test-20101111000001 test_source1/fs1/sub -test_source1/fs1/sub@test-1 +test_source1/fs1/sub@test-20101111000001 test_source2 test_source2/fs2 test_source2/fs2/sub -test_source2/fs2/sub@test-1 +test_source2/fs2/sub@test-20101111000001 test_source2/fs3 test_source2/fs3/sub test_target1 """) with self.subTest("second snapshot, no changes, empty snapshot"): - node.consistent_snapshot(node.selected_datasets(exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=200000), "test-2", 0) + node.consistent_snapshot(node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=200000), "test-20101111000002", 0) r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) self.assertEqual(r, """ test_source1 test_source1/fs1 -test_source1/fs1@test-1 -test_source1/fs1@test-2 +test_source1/fs1@test-20101111000001 +test_source1/fs1@test-20101111000002 test_source1/fs1/sub -test_source1/fs1/sub@test-1 -test_source1/fs1/sub@test-2 +test_source1/fs1/sub@test-20101111000001 +test_source1/fs1/sub@test-20101111000002 test_source2 test_source2/fs2 test_source2/fs2/sub -test_source2/fs2/sub@test-1 -test_source2/fs2/sub@test-2 +test_source2/fs2/sub@test-20101111000001 +test_source2/fs2/sub@test-20101111000002 test_source2/fs3 test_source2/fs3/sub test_target1 @@ -74,12 +74,12 @@ test_target1 def test_consistent_snapshot_prepostcmds(self): logger = LogStub() description = "[Source]" - node = ZfsNode("test", logger, description=description, debug_output=True) + node = ZfsNode(snapshot_time_format="test", hold_name="test", logger=logger, description=description, debug_output=True) with self.subTest("Test if all cmds are executed correctly (no failures)"): with OutputIO() as buf: with redirect_stdout(buf): - node.consistent_snapshot(node.selected_datasets(exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=1), "test-1", + node.consistent_snapshot(node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=1), "test-1", 0, pre_snapshot_cmds=["echo pre1", "echo pre2"], post_snapshot_cmds=["echo post1 >&2", "echo post2 >&2"] @@ -95,7 +95,7 @@ test_target1 with OutputIO() as buf: with redirect_stdout(buf): with self.assertRaises(ExecuteError): - node.consistent_snapshot(node.selected_datasets(exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=1), "test-1", + node.consistent_snapshot(node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=1), "test-1", 0, pre_snapshot_cmds=["echo pre1", "false", "echo pre2"], post_snapshot_cmds=["echo post1", "false", "echo post2"] @@ -112,7 +112,7 @@ test_target1 with redirect_stdout(buf): with self.assertRaises(ExecuteError): #same snapshot name as before so it fails - node.consistent_snapshot(node.selected_datasets(exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=1), "test-1", + node.consistent_snapshot(node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, exclude_unchanged=False, min_change=1), "test-1", 0, pre_snapshot_cmds=["echo pre1", "echo pre2"], post_snapshot_cmds=["echo post1", "echo post2"] @@ -137,8 +137,8 @@ test_target1 logger = LogStub() description = "[Source]" - node = ZfsNode("test", logger, description=description) - s = pformat(node.selected_datasets(exclude_paths=[], exclude_received=False, exclude_unchanged=True, min_change=1)) + node = ZfsNode(snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) + s = pformat(node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, exclude_unchanged=True, min_change=1)) print(s) # basics @@ -150,7 +150,7 @@ test_target1 def test_validcommand(self): logger = LogStub() description = "[Source]" - node = ZfsNode("test", logger, description=description) + node = ZfsNode(snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) with self.subTest("test invalid option"): self.assertFalse(node.valid_command(["zfs", "send", "--invalid-option", "nonexisting"])) @@ -160,7 +160,7 @@ test_target1 def test_supportedsendoptions(self): logger = LogStub() description = "[Source]" - node = ZfsNode("test", logger, description=description) + node = ZfsNode(snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) # -D propably always supported self.assertGreater(len(node.supported_send_options), 0) @@ -168,7 +168,7 @@ test_target1 logger = LogStub() description = "[Source]" # NOTE: this could hang via ssh if we dont close filehandles properly. (which was a previous bug) - node = ZfsNode("test", logger, description=description, ssh_to='localhost') + node = ZfsNode(snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description, ssh_to='localhost') self.assertIsInstance(node.supported_recv_options, list) diff --git a/zfs_autobackup/ZfsAutobackup.py b/zfs_autobackup/ZfsAutobackup.py index c8dc515..e47a03c 100644 --- a/zfs_autobackup/ZfsAutobackup.py +++ b/zfs_autobackup/ZfsAutobackup.py @@ -135,6 +135,13 @@ class ZfsAutobackup: parser.add_argument('--buffer', metavar='SIZE', default=None, help='Add zfs send and recv buffers to smooth out IO bursts. (e.g. 128M. requires mbuffer)') + parser.add_argument('--snapshot-format', metavar='FORMAT', default="{}-%Y%m%d%H%M%S", + help='Snapshot naming format. Default: %(default)s') + parser.add_argument('--property-format', metavar='FORMAT', default="autobackup:{}", + help='Select property naming format. Default: %(default)s') + parser.add_argument('--hold-format', metavar='FORMAT', default="zfs_autobackup:{}", + help='Hold naming format. Default: %(default)s') + parser.add_argument('--version', action='store_true', help='Show version.') @@ -464,6 +471,19 @@ class ZfsAutobackup: if self.args.test: self.warning("TEST MODE - SIMULATING WITHOUT MAKING ANY CHANGES") + #format all the names + property_name = self.args.property_format.format(self.args.backup_name) + snapshot_time_format = self.args.snapshot_format.format(self.args.backup_name) + hold_name = self.args.hold_format.format(self.args.backup_name) + + self.verbose("") + self.verbose("Selecting dataset property : {}".format(property_name)) + self.verbose("Snapshot format : {}".format(snapshot_time_format)) + + if not self.args.no_holds: + self.verbose("Hold name : {}".format(hold_name)) + + ################ create source zfsNode self.set_title("Source settings") @@ -472,17 +492,9 @@ class ZfsAutobackup: source_thinner = None else: source_thinner = Thinner(self.args.keep_source) - source_node = ZfsNode(self.args.backup_name, self, ssh_config=self.args.ssh_config, + source_node = ZfsNode(snapshot_time_format=snapshot_time_format, hold_name=hold_name, logger=self, ssh_config=self.args.ssh_config, ssh_to=self.args.ssh_source, readonly=self.args.test, debug_output=self.args.debug_output, description=description, thinner=source_thinner) - source_node.verbose( - "Selecting dataset property: 'autobackup:{}'".format( - self.args.backup_name, self.args.backup_name)) - - source_node.verbose("Snapshot prefix : '{}-'".format(self.args.backup_name)) - - if not self.args.no_holds: - source_node.verbose("Hold name : '{}'".format("zfs_autobackup:" + self.args.backup_name)) ################# select source datasets @@ -503,7 +515,7 @@ class ZfsAutobackup: self.warning("Source and target are on the same host, excluding received datasets from selection.") exclude_received = True - source_datasets = source_node.selected_datasets(exclude_received=exclude_received, + source_datasets = source_node.selected_datasets(property_name=property_name,exclude_received=exclude_received, exclude_paths=exclude_paths, exclude_unchanged=self.args.exclude_unchanged, min_change=self.args.min_change) @@ -517,7 +529,8 @@ class ZfsAutobackup: ################# snapshotting if not self.args.no_snapshot: self.set_title("Snapshotting") - source_node.consistent_snapshot(source_datasets, source_node.new_snapshotname(), + snapshot_name=time.strftime(snapshot_time_format) + source_node.consistent_snapshot(source_datasets, snapshot_name, min_changed_bytes=self.args.min_change, pre_snapshot_cmds=self.args.pre_snapshot_cmd, post_snapshot_cmds=self.args.post_snapshot_cmd) @@ -532,7 +545,7 @@ class ZfsAutobackup: target_thinner = None else: target_thinner = Thinner(self.args.keep_target) - target_node = ZfsNode(self.args.backup_name, self, ssh_config=self.args.ssh_config, + target_node = ZfsNode(snapshot_time_format=snapshot_time_format, hold_name=hold_name, logger=self, ssh_config=self.args.ssh_config, ssh_to=self.args.ssh_target, readonly=self.args.test, debug_output=self.args.debug_output, description="[Target]", diff --git a/zfs_autobackup/ZfsDataset.py b/zfs_autobackup/ZfsDataset.py index 44b8035..de89846 100644 --- a/zfs_autobackup/ZfsDataset.py +++ b/zfs_autobackup/ZfsDataset.py @@ -321,15 +321,14 @@ class ZfsDataset: return True def is_ours(self): - """return true if this snapshot is created by this backup_name""" - if re.match("^" + self.zfs_node.backup_name + "-[0-9]*$", self.snapshot_name): - return True - else: + """return true if this snapshot name has format""" + try: + test = self.timestamp + except ValueError as e: + self.error(str(e)) return False - @property - def _hold_name(self): - return "zfs_autobackup:" + self.zfs_node.backup_name + return True @property def holds(self): @@ -341,30 +340,26 @@ class ZfsDataset: def is_hold(self): """did we hold this snapshot?""" - return self._hold_name in self.holds + return self.zfs_node.hold_name in self.holds def hold(self): """hold dataset""" self.debug("holding") - self.zfs_node.run(["zfs", "hold", self._hold_name, self.name], valid_exitcodes=[0, 1]) + self.zfs_node.run(["zfs", "hold", self.zfs_node.hold_name, self.name], valid_exitcodes=[0, 1]) def release(self): """release dataset""" if self.zfs_node.readonly or self.is_hold(): self.debug("releasing") - self.zfs_node.run(["zfs", "release", self._hold_name, self.name], valid_exitcodes=[0, 1]) + self.zfs_node.run(["zfs", "release", self.zfs_node.hold_name, self.name], valid_exitcodes=[0, 1]) @property def timestamp(self): """get timestamp from snapshot name. Only works for our own snapshots with the correct format. """ - time_str = re.findall("^.*-([0-9]*)$", self.snapshot_name)[0] - if len(time_str) != 14: - raise (Exception("Snapshot has invalid timestamp in name: {}".format(self.snapshot_name))) - # new format: - time_secs = time.mktime(time.strptime(time_str, "%Y%m%d%H%M%S")) + time_secs = time.mktime(time.strptime(self.snapshot_name, self.zfs_node.snapshot_time_format)) return time_secs def from_names(self, names): diff --git a/zfs_autobackup/ZfsNode.py b/zfs_autobackup/ZfsNode.py index b738bb3..1461ffb 100644 --- a/zfs_autobackup/ZfsNode.py +++ b/zfs_autobackup/ZfsNode.py @@ -17,9 +17,13 @@ from .ExecuteNode import ExecuteError class ZfsNode(ExecuteNode): """a node that contains zfs datasets. implements global (systemwide/pool wide) zfs commands""" - def __init__(self, backup_name, logger, ssh_config=None, ssh_to=None, readonly=False, description="", + def __init__(self, snapshot_time_format, hold_name, logger, ssh_config=None, ssh_to=None, readonly=False, + description="", debug_output=False, thinner=None): - self.backup_name = backup_name + + self.snapshot_time_format = snapshot_time_format + self.hold_name = hold_name + self.description = description self.logger = logger @@ -54,7 +58,7 @@ class ZfsNode(ExecuteNode): if self.__thinner is not None: return self.__thinner.thin(objects, keep_objects) else: - return ( keep_objects, [] ) + return (keep_objects, []) @CachedProperty def supported_send_options(self): @@ -129,8 +133,9 @@ class ZfsNode(ExecuteNode): bytes_left = self._progress_total_bytes - bytes_ minutes_left = int((bytes_left / (bytes_ / (time.time() - self._progress_start_time))) / 60) - self.logger.progress("Transfer {}% {}MB/s (total {}MB, {} minutes left)".format(percentage, speed, int( - self._progress_total_bytes / (1024 * 1024)), minutes_left)) + self.logger.progress( + "Transfer {}% {}MB/s (total {}MB, {} minutes left)".format(percentage, speed, int( + self._progress_total_bytes / (1024 * 1024)), minutes_left)) return @@ -158,11 +163,8 @@ class ZfsNode(ExecuteNode): def debug(self, txt): self.logger.debug("{} {}".format(self.description, txt)) - def new_snapshotname(self): - """determine uniq new snapshotname""" - return self.backup_name + "-" + time.strftime("%Y%m%d%H%M%S") - - def consistent_snapshot(self, datasets, snapshot_name, min_changed_bytes, pre_snapshot_cmds=[], post_snapshot_cmds=[]): + def consistent_snapshot(self, datasets, snapshot_name, min_changed_bytes, pre_snapshot_cmds=[], + post_snapshot_cmds=[]): """create a consistent (atomic) snapshot of specified datasets, per pool. """ @@ -214,7 +216,7 @@ class ZfsNode(ExecuteNode): except Exception as e: pass - def selected_datasets(self, exclude_received, exclude_paths, exclude_unchanged, min_change): + def selected_datasets(self, property_name, exclude_received, exclude_paths, exclude_unchanged, min_change): """determine filesystems that should be backed up by looking at the special autobackup-property, systemwide returns: list of ZfsDataset @@ -225,7 +227,7 @@ class ZfsNode(ExecuteNode): # get all source filesystems that have the backup property lines = self.run(tab_split=True, readonly=True, cmd=[ "zfs", "get", "-t", "volume,filesystem", "-o", "name,value,source", "-H", - "autobackup:" + self.backup_name + property_name ]) # The returnlist of selected ZfsDataset's: @@ -249,7 +251,9 @@ class ZfsNode(ExecuteNode): source = raw_source # determine it - if dataset.is_selected(value=value, source=source, inherited=inherited, exclude_received=exclude_received, exclude_paths=exclude_paths, exclude_unchanged=exclude_unchanged, min_change=min_change): + if dataset.is_selected(value=value, source=source, inherited=inherited, exclude_received=exclude_received, + exclude_paths=exclude_paths, exclude_unchanged=exclude_unchanged, + min_change=min_change): selected_filesystems.append(dataset) return selected_filesystems