5
0
mirror of git://git.proxmox.com/git/pve-storage.git synced 2025-02-26 21:57:31 +03:00

fix #3199: by fixing usage of strftime

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.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Fabian Ebner 2020-12-15 11:59:29 +01:00 committed by Thomas Lamprecht
parent 32dbc619a5
commit 189e67ffa6
2 changed files with 50 additions and 2 deletions

View File

@ -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 {

View File

@ -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;