public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH storage] fix #3199: by fixing usage of strftime
@ 2020-12-15 10:59 Fabian Ebner
  2020-12-15 13:40 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Fabian Ebner @ 2020-12-15 10:59 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Fabian Ebner <f.ebner@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





^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pve-devel] applied: [PATCH storage] fix #3199: by fixing usage of strftime
  2020-12-15 10:59 [pve-devel] [PATCH storage] fix #3199: by fixing usage of strftime Fabian Ebner
@ 2020-12-15 13:40 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2020-12-15 13:40 UTC (permalink / raw)
  To: Proxmox VE development discussion, Fabian Ebner

On 15.12.20 11:59, Fabian Ebner wrote:
> 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.



applied, thanks!




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-15 13:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-15 10:59 [pve-devel] [PATCH storage] fix #3199: by fixing usage of strftime Fabian Ebner
2020-12-15 13:40 ` [pve-devel] applied: " Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal