From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 5ABC81FF0AF for ; Fri, 06 Nov 2026 15:49:27 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E23BB216E8; Fri, 06 Nov 2026 15:49:09 +0100 (CET) Message-ID: Date: Fri, 6 Nov 2026 15:49:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH manager 06/19] vzdump: notification: capture guest logs right after each backup To: Thomas Lamprecht , pve-devel@lists.proxmox.com References: <20261101225849.884587-1-t.lamprecht@proxmox.com> <20261101225849.884587-7-t.lamprecht@proxmox.com> Content-Language: en-US From: Fiona Ebner In-Reply-To: <20261101225849.884587-7-t.lamprecht@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1793976543288 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.289 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) 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 Message-ID-Hash: AD3EIEMWP4BW5VG4CKMUSO3CXQ2NU3UT X-Message-ID-Hash: AD3EIEMWP4BW5VG4CKMUSO3CXQ2NU3UT X-MailFrom: f.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Am 01.11.26 um 11:59 PM schrieb Thomas Lamprecht: > The log of a guest backup is written to a path derived from the guest > alone and was only read back when sending the notification at the end > of the job. This relies on no other backup of the guest starting in the > meantime, which no longer holds once backup jobs can run alongside each > other. > > Read the log as the last step of each guest backup instead. Logs > longer than the notification size limit are cut, as they would not be > included anyway. > > Signed-off-by: Thomas Lamprecht > --- > PVE/VZDump.pm | 27 +++++++++++++++++++-------- > 1 file changed, 19 insertions(+), 8 deletions(-) > > diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm > index defe9e0a5..d07ced61b 100644 > --- a/PVE/VZDump.pm > +++ b/PVE/VZDump.pm > @@ -368,24 +368,35 @@ sub read_vzdump_defaults { > return $res; > } > > -my sub read_backup_task_logs { > +use constant MAX_LOG_SIZE => 1024 * 1024; > + > +my sub read_guest_log { > + my ($path) = @_; > + > + open(my $fh, '<', $path) or return undef; Nit: should we log/capture the error code? > + my $log = ''; > + read($fh, $log, MAX_LOG_SIZE + 1); # anything longer is not sent anyway > + close($fh); > + > + return $log; > +} > + > +my sub format_backup_task_logs { > my ($task_list) = @_; > > my $task_logs = ""; > > for my $task (@$task_list) { > my $vmid = $task->{vmid}; > - my $log_file = $task->{tmplog}; > if (!$task->{tmplog}) { > $task_logs .= "$vmid: no log available\n\n"; > next; > } > - if (open(my $TMP, '<', "$log_file")) { > - while (my $line = <$TMP>) { > + if (defined(my $log = $task->{log})) { > + for my $line (split(/^/m, $log)) { > next if $line =~ /^status: \d+/; # not useful in mails > $task_logs .= encode8bit("$vmid: $line"); > } > - close($TMP); > } else { > $task_logs .= "$vmid: Could not open log file\n\n"; > } > @@ -484,8 +495,6 @@ my sub get_hostname { > return $hostname; > } > > -use constant MAX_LOG_SIZE => 1024 * 1024; > - > sub send_notification { > my ($self, $tasklist, $total_time, $err, $detail_pre, $detail_post) = @_; > > @@ -514,7 +523,7 @@ sub send_notification { > > my $text_log_part = "$cmdline\n\n"; > $text_log_part .= $detail_pre . "\n" if defined($detail_pre); > - $text_log_part .= read_backup_task_logs($tasklist); > + $text_log_part .= format_backup_task_logs($tasklist); > $text_log_part .= $detail_post if defined($detail_post); > > if (length($text_log_part) > MAX_LOG_SIZE) { > @@ -1385,6 +1394,8 @@ sub exec_backup_task { > eval { $self->run_hook_script('log-end', $task); }; > debugmsg('warn', $@) if $@; # message already contains command with phase name > > + $task->{log} = read_guest_log($task->{tmplog}) if $task->{tmplog}; Nit: we could unlink $task->{tmplog} here after reading, and maybe even drop it from the hash since we are not supposed to access it afterwards anymore. Of course then the check for $task->{tmplog} in format_backup_task_logs() would need to be dropped too. We could put "$vmid: no log available\n\n" in $task->{log} at the beginning of the task, so we end up with that message if it never is replaced. > + > die $err if $err && $err =~ m/^interrupted by signal$/; > } >