[pve-devel] [PATCH storage] fix #3199: by fixing usage of strftime
Fabian Ebner
f.ebner at proxmox.com
Tue Dec 15 11:59:29 CET 2020
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
This is embarassing...
In a very early version I wanted to parse the date from the backup name, and
when switching to using the ctime and localtime() instead, I forgot to update
the usage of strftime.
PVE/Storage.pm | 4 ++--
test/prune_backups_test.pm | 48 ++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index c1a21b4..76d17c6 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1697,8 +1697,8 @@ sub prune_mark_backup_group {
$prune_mark->($prune_list, $keep->{'keep-weekly'}, sub {
my ($ctime) = @_;
my ($sec, $min, $hour, $day, $month, $year) = localtime($ctime);
- my $iso_week = int(strftime("%V", $sec, $min, $hour, $day, $month - 1, $year - 1900));
- my $iso_week_year = int(strftime("%G", $sec, $min, $hour, $day, $month - 1, $year - 1900));
+ my $iso_week = int(strftime("%V", $sec, $min, $hour, $day, $month, $year));
+ my $iso_week_year = int(strftime("%G", $sec, $min, $hour, $day, $month, $year));
return "$iso_week/$iso_week_year";
});
$prune_mark->($prune_list, $keep->{'keep-monthly'}, sub {
diff --git a/test/prune_backups_test.pm b/test/prune_backups_test.pm
index c69c467..a87c4b3 100644
--- a/test/prune_backups_test.pm
+++ b/test/prune_backups_test.pm
@@ -91,6 +91,23 @@ push @{$mocked_backups_lists->{threeway}}, (
'vmid' => 7654,
},
);
+push @{$mocked_backups_lists->{weekboundary}}, (
+ {
+ 'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_03-12_18_21.tar.zst",
+ 'ctime' => $basetime + (366-31+2)*24*60*60,
+ 'vmid' => 7654,
+ },
+ {
+ 'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_04-12_18_21.tar.zst",
+ 'ctime' => $basetime + (366-31+3)*24*60*60,
+ 'vmid' => 7654,
+ },
+ {
+ 'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_07-12_18_21.tar.zst",
+ 'ctime' => $basetime + (366-31+6)*24*60*60,
+ 'vmid' => 7654,
+ },
+);
my $current_list;
my $mock_plugin = Test::MockModule->new('PVE::Storage::Plugin');
$mock_plugin->redefine(list_volumes => sub {
@@ -410,6 +427,37 @@ my $tests = [
},
],
},
+ {
+ description => 'daily=weekly=1,weekboundary',
+ keep => {
+ 'keep-daily' => 1,
+ 'keep-weekly' => 1,
+ },
+ list => 'weekboundary',
+ expected => [
+ {
+ 'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_03-12_18_21.tar.zst",
+ 'ctime' => $basetime + (366-31+2)*24*60*60,
+ 'type' => 'qemu',
+ 'vmid' => 7654,
+ 'mark' => 'remove',
+ },
+ {
+ 'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_04-12_18_21.tar.zst",
+ 'ctime' => $basetime + (366-31+3)*24*60*60,
+ 'type' => 'qemu',
+ 'vmid' => 7654,
+ 'mark' => 'keep',
+ },
+ {
+ 'volid' => "$storeid:backup/vzdump-qemu-7654-2020_12_07-12_18_21.tar.zst",
+ 'ctime' => $basetime + (366-31+6)*24*60*60,
+ 'type' => 'qemu',
+ 'vmid' => 7654,
+ 'mark' => 'keep',
+ },
+ ],
+ },
];
plan tests => scalar @$tests;
--
2.20.1
More information about the pve-devel
mailing list