From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 276D1609CE for ; Tue, 15 Dec 2020 11:59:34 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2599D10294 for ; Tue, 15 Dec 2020 11:59:34 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 9CFB41028C for ; Tue, 15 Dec 2020 11:59:33 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6661D45172 for ; Tue, 15 Dec 2020 11:59:33 +0100 (CET) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 15 Dec 2020 11:59:29 +0100 Message-Id: <20201215105929.11873-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.009 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [storage.pm] Subject: [pve-devel] [PATCH storage] fix #3199: by fixing usage of strftime X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Dec 2020 10:59:34 -0000 Signed-off-by: Fabian Ebner --- 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