all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v5 manager 2/2] Always use prune-backups instead of maxfiles internally
Date: Tue, 29 Sep 2020 10:37:05 +0200	[thread overview]
Message-ID: <20200929083705.20124-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20200929083705.20124-1-f.ebner@proxmox.com>

For the use case with '--dumpdir', it's not possible to call prune_backups
directly, so a little bit of special handling is required there.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/VZDump.pm | 42 ++++++++++++++++--------------------------
 1 file changed, 16 insertions(+), 26 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index 1fe4c4ee..c8f37d04 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -484,8 +484,10 @@ sub new {
 	die "internal error";
     }
 
-    if (!defined($opts->{'prune-backups'}) && !defined($opts->{maxfiles})) {
-	$opts->{maxfiles} = $defaults->{maxfiles};
+    if (!defined($opts->{'prune-backups'})) {
+	$opts->{maxfiles} //= $defaults->{maxfiles};
+	$opts->{'prune-backups'} = { 'keep-last' => $opts->{maxfiles} };
+	delete $opts->{maxfiles};
     }
 
     if ($opts->{tmpdir} && ! -d $opts->{tmpdir}) {
@@ -720,16 +722,11 @@ sub exec_backup_task {
 	my $bkname = "vzdump-$vmtype-$vmid";
 	my $basename = $bkname . strftime("-%Y_%m_%d-%H_%M_%S", localtime($task->{backup_time}));
 
-	my $maxfiles = $opts->{maxfiles};
 	my $prune_options = $opts->{'prune-backups'};
 
 	my $backup_limit = 0;
-	if (defined($maxfiles)) {
-	    $backup_limit = $maxfiles;
-	} elsif (defined($prune_options)) {
-	    foreach my $keep (values %{$prune_options}) {
-		$backup_limit += $keep;
-	    }
+	foreach my $keep (values %{$prune_options}) {
+	    $backup_limit += $keep;
 	}
 
 	if ($backup_limit && !$opts->{remove}) {
@@ -952,25 +949,18 @@ sub exec_backup_task {
 
 	# purge older backup
 	if ($opts->{remove}) {
-	    if ($maxfiles) {
+	    if (!defined($opts->{storage})) {
+		my $bklist = get_backup_file_list($opts->{dumpdir}, $bkname, $task->{target});
+		PVE::Storage::prune_mark_backup_group($bklist, $prune_options);
 
-		if ($self->{opts}->{pbs}) {
-		    my $args = [$pbs_group_name, '--quiet', '1', '--keep-last', $maxfiles];
-		    my $logfunc = sub { my $line = shift; debugmsg ('info', $line, $logfd); };
-		    PVE::Storage::PBSPlugin::run_raw_client_cmd(
-			$opts->{scfg}, $opts->{storage}, 'prune', $args, logfunc => $logfunc);
-		} else {
-		    my $bklist = get_backup_file_list($opts->{dumpdir}, $bkname, $task->{target});
-		    $bklist = [ sort { $b->{ctime} <=> $a->{ctime} } @$bklist ];
-
-		    while (scalar (@$bklist) >= $maxfiles) {
-			my $d = pop @$bklist;
-			my $archive_path = $d->{path};
-			debugmsg ('info', "delete old backup '$archive_path'", $logfd);
-			PVE::Storage::archive_remove($archive_path);
-		    }
+		foreach my $prune_entry (@{$bklist}) {
+		    next if $prune_entry->{mark} ne 'remove';
+
+		    my $archive_path = $prune_entry->{path};
+		    debugmsg ('info', "delete old backup '$archive_path'", $logfd);
+		    PVE::Storage::archive_remove($archive_path);
 		}
-	    } elsif (defined($prune_options)) {
+	    } else {
 		my $logfunc = sub { debugmsg($_[0], $_[1], $logfd) };
 		PVE::Storage::prune_backups($cfg, $opts->{storage}, $prune_options, $vmid, $vmtype, 0, $logfunc);
 	    }
-- 
2.20.1





  parent reply	other threads:[~2020-09-29  8:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29  8:37 [pve-devel] [PATCH-SERIES v5] fix #2649: introduce prune-backups property for storages supporting backups Fabian Ebner
2020-09-29  8:37 ` [pve-devel] [PATCH v5 manager 1/2] Allow prune-backups as an alternative to maxfiles Fabian Ebner
2020-09-29  8:37 ` Fabian Ebner [this message]
2020-10-01 14:36 ` [pve-devel] applied: [PATCH-SERIES v5] fix #2649: introduce prune-backups property for storages supporting backups Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200929083705.20124-3-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal