[pve-devel] [PATCH manager 1/1] vzdump: add 'logcomment' parameter

Dominik Csapak d.csapak at proxmox.com
Fri Dec 3 14:35:08 CET 2021


and use it from the jobs to log the job id and schedule

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/VZDump.pm | 6 ++++++
 PVE/Jobs.pm        | 2 +-
 PVE/Jobs/VZDump.pm | 3 ++-
 PVE/VZDump.pm      | 5 +++++
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm
index 2c0df4c3..1071add6 100644
--- a/PVE/API2/VZDump.pm
+++ b/PVE/API2/VZDump.pm
@@ -40,6 +40,12 @@ __PACKAGE__->register_method ({
 		description => "Write tar to stdout, not to a file.",
 		optional => 1,
 	    },
+	    logcomment => {
+		type => 'string',
+		description => 'Text to log at the beginning of the backup.',
+		optional => 1,
+		maxLength => 2048,
+	    },
         }),
     },
     returns => { type => 'string' },
diff --git a/PVE/Jobs.pm b/PVE/Jobs.pm
index ba3685ec..f18ab8e7 100644
--- a/PVE/Jobs.pm
+++ b/PVE/Jobs.pm
@@ -238,7 +238,7 @@ sub run_jobs {
 
 	my $plugin = PVE::Jobs::Plugin->lookup($type);
 	if (starting_job($id, $type)) {
-	    my $upid = eval { $plugin->run($cfg) };
+	    my $upid = eval { $plugin->run($cfg, $id, $schedule) };
 	    if (my $err = $@) {
 		warn $@ if $@;
 		started_job($id, $type, undef, $err);
diff --git a/PVE/Jobs/VZDump.pm b/PVE/Jobs/VZDump.pm
index 44fe33dc..c12408b9 100644
--- a/PVE/Jobs/VZDump.pm
+++ b/PVE/Jobs/VZDump.pm
@@ -65,7 +65,7 @@ sub encode_value {
 }
 
 sub run {
-    my ($class, $conf) = @_;
+    my ($class, $conf, $id, $schedule) = @_;
 
     # remove all non vzdump related options
     foreach my $opt (keys %$conf) {
@@ -78,6 +78,7 @@ sub run {
     }
 
     $conf->{quiet} = 1; # do not write to stdout/stderr
+    $conf->{logcomment} = "Job '$id' triggered by schedule '$schedule'.\n";
 
     PVE::Cluster::cfs_update(); # refresh vmlist
 
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index b5a5fadd..d02aea52 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -462,6 +462,7 @@ sub new {
 	cmdline => $cmdline,
 	opts => $opts,
 	skiplist => $skiplist,
+	logcomment => delete $opts->{logcomment},
     }, $class;
 
     my $findexcl = $self->{findexcl} = [];
@@ -1126,6 +1127,10 @@ sub exec_backup {
 
     debugmsg ('info', "starting new backup job: $self->{cmdline}", undef, 1);
 
+    if (my $text = $self->{logcomment}) {
+	debugmsg ('info', "$text", undef, 1);
+    }
+
     if (scalar(@{$self->{skiplist}})) {
 	my $skip_string = join(', ', sort { $a <=> $b } @{$self->{skiplist}});
 	debugmsg ('info', "skip external VMs: $skip_string");
-- 
2.30.2






More information about the pve-devel mailing list