]> git.proxmox.com Git - pve-storage.git/blobdiff - test/prune_backups_test.pm
prune mark: correctly keep track of already included backups
[pve-storage.git] / test / prune_backups_test.pm
index 8bf564df7be76662c06c5fadec90494d1b90c00a..c69c4671f005a086027b1fe371756535b27204ca 100644 (file)
@@ -74,6 +74,23 @@ push @{$mocked_backups_lists->{novmid}}, (
        'ctime' => 1234,
     },
 );
+push @{$mocked_backups_lists->{threeway}}, (
+    {
+       'volid' => "$storeid:backup/vzdump-qemu-7654-2019_12_25-12_18_21.tar.zst",
+       'ctime' => $basetime - 7*24*60*60,
+       'vmid'  => 7654,
+    },
+    {
+       'volid' => "$storeid:backup/vzdump-qemu-7654-2019_12_31-12_18_21.tar.zst",
+       'ctime' => $basetime - 24*60*60,
+       'vmid'  => 7654,
+    },
+    {
+       'volid' => "$storeid:backup/vzdump-qemu-7654-2020_01_01-12_18_21.tar.zst",
+       'ctime' => $basetime,
+       'vmid'  => 7654,
+    },
+);
 my $current_list;
 my $mock_plugin = Test::MockModule->new('PVE::Storage::Plugin');
 $mock_plugin->redefine(list_volumes => sub {
@@ -361,6 +378,38 @@ my $tests = [
        },
        expected => generate_expected(\@vmids, undef, ['keep', 'keep', 'keep', 'keep', 'keep', 'keep']),
     },
+    {
+       description => 'daily=weekly=monthly=1',
+       keep => {
+           'keep-daily' => 1,
+           'keep-weekly' => 1,
+           'keep-monthly' => 1,
+       },
+       list => 'threeway',
+       expected => [
+           {
+               'volid' => "$storeid:backup/vzdump-qemu-7654-2019_12_25-12_18_21.tar.zst",
+               'ctime' => $basetime - 7*24*60*60,
+               'type'  => 'qemu',
+               'vmid'  => 7654,
+               'mark'  => 'keep',
+           },
+           {
+               'volid' => "$storeid:backup/vzdump-qemu-7654-2019_12_31-12_18_21.tar.zst",
+               'ctime' => $basetime - 24*60*60,
+               'type'  => 'qemu',
+               'vmid'  => 7654,
+               'mark'  => 'remove', # month is already covered by the backup kept by keep-weekly!
+           },
+           {
+               'volid' => "$storeid:backup/vzdump-qemu-7654-2020_01_01-12_18_21.tar.zst",
+               'ctime' => $basetime,
+               'type'  => 'qemu',
+               'vmid'  => 7654,
+               'mark'  => 'keep',
+           },
+       ],
+    },
 ];
 
 plan tests => scalar @$tests;