From 77f1c164147bda516dda6efe0cd7583f012a1259 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sat, 3 Jul 2021 14:31:34 +0200 Subject: [PATCH] fix #84 --- tests/test_regressions.py | 53 ++++++++++++++++++++++++++++----- tests/test_zfsautobackup.py | 6 +--- zfs_autobackup/ZfsAutobackup.py | 2 +- zfs_autobackup/ZfsDataset.py | 12 +++++--- 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 79a7128..6090b2a 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -8,12 +8,51 @@ class TestZfsNode(unittest2.TestCase): prepare_zpools() self.longMessage=True - # #resume initial backup - # def test_keepsource0(self): + def test_keepsource0target10queuedsend(self): + """Test if thinner doesnt destroy too much early on if there are no common snapshots YET. Issue #84""" - # #somehow only specifying --allow-empty --keep-source 0 failed: - # with patch('time.strftime', return_value="20101111000000"): - # self.assertFalse(ZfsAutobackup("test test_target1 --verbose --allow-empty --keep-source 0".split(" ")).run()) + with patch('time.strftime', return_value="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"): - # self.assertFalse(ZfsAutobackup("test test_target1 --verbose --allow-empty --keep-source 0".split(" ")).run()) + with patch('time.strftime', return_value="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"): + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --keep-source=0 --keep-target=10 --allow-empty".split( + " ")).run()) + + r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) + self.assertMultiLineEqual(r, """ +test_source1 +test_source1/fs1 +test_source1/fs1@test-20101111000002 +test_source1/fs1/sub +test_source1/fs1/sub@test-20101111000002 +test_source2 +test_source2/fs2 +test_source2/fs2/sub +test_source2/fs2/sub@test-20101111000002 +test_source2/fs3 +test_source2/fs3/sub +test_target1 +test_target1/test_source1 +test_target1/test_source1/fs1 +test_target1/test_source1/fs1@test-20101111000000 +test_target1/test_source1/fs1@test-20101111000001 +test_target1/test_source1/fs1@test-20101111000002 +test_target1/test_source1/fs1/sub +test_target1/test_source1/fs1/sub@test-20101111000000 +test_target1/test_source1/fs1/sub@test-20101111000001 +test_target1/test_source1/fs1/sub@test-20101111000002 +test_target1/test_source2 +test_target1/test_source2/fs2 +test_target1/test_source2/fs2/sub +test_target1/test_source2/fs2/sub@test-20101111000000 +test_target1/test_source2/fs2/sub@test-20101111000001 +test_target1/test_source2/fs2/sub@test-20101111000002 +""") diff --git a/tests/test_zfsautobackup.py b/tests/test_zfsautobackup.py index c69eba2..666d78b 100644 --- a/tests/test_zfsautobackup.py +++ b/tests/test_zfsautobackup.py @@ -312,8 +312,6 @@ test_target1/test_source2/fs2 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) - #(only parents are created ) - #TODO: it probably shouldn't create these self.assertMultiLineEqual(r,""" test_source1 test_source1/fs1 @@ -337,8 +335,6 @@ test_target1 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) - #(only parents are created ) - #TODO: it probably shouldn't create these self.assertMultiLineEqual(r,""" test_source1 test_source1/fs1 @@ -851,7 +847,7 @@ test_target1/test_source2/fs2/sub@test-20101111000003 """) - # make snapshot 4, since we used no-holds, it will delete 3 on the source, breaking the backup + # 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"): self.assertFalse(ZfsAutobackup("test --no-progress --verbose --keep-source=0 --keep-target=0 --allow-empty".split(" ")).run()) diff --git a/zfs_autobackup/ZfsAutobackup.py b/zfs_autobackup/ZfsAutobackup.py index 6520003..2733899 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-rc4" + VERSION = "3.1-rc5" HEADER = "zfs-autobackup v{} - (c)2021 E.H.Eefting (edwin@datux.nl)".format(VERSION) def __init__(self, argv, print_arguments=True): diff --git a/zfs_autobackup/ZfsDataset.py b/zfs_autobackup/ZfsDataset.py index bd4d3c2..089df2b 100644 --- a/zfs_autobackup/ZfsDataset.py +++ b/zfs_autobackup/ZfsDataset.py @@ -874,9 +874,13 @@ class ZfsDataset: :type target_keeps: list of ZfsDataset """ - # on source: destroy all obsoletes before common. + # on source: destroy all obsoletes before common. (since we cant send them anyways) # But after common, only delete snapshots that target also doesn't want - before_common = True + if common_snapshot: + before_common = True + else: + before_common = False + for source_snapshot in self.snapshots: if common_snapshot and source_snapshot.snapshot_name == common_snapshot.snapshot_name: before_common = False @@ -888,8 +892,8 @@ class ZfsDataset: # on target: destroy everything thats obsolete, except common_snapshot for target_snapshot in target_dataset.snapshots: - if (target_snapshot in target_obsoletes) and ( - not common_snapshot or target_snapshot.snapshot_name != common_snapshot.snapshot_name): + if (target_snapshot in target_obsoletes) \ + and ( not common_snapshot or (target_snapshot.snapshot_name != common_snapshot.snapshot_name)): if target_snapshot.exists: target_snapshot.destroy()