[pve-devel] [RFC 1/2] Added functionality do disable temporary a backup job

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jul 20 09:27:41 CEST 2015


Added an option to disable a backup job while preserving its
settings. When a job is disabled a '#' is added in front of the vzdump
command in the vzdump.cron file. So the cron job still fires,
but only a comment gets executed. If we would comment out the cron job
a bit more changes to the parser would be needed.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 PVE/API2/Backup.pm | 25 ++++++++++++++++++++-----
 PVE/VZDump.pm      |  3 ++-
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/PVE/API2/Backup.pm b/PVE/API2/Backup.pm
index 990fb1e..e86b723 100644
--- a/PVE/API2/Backup.pm
+++ b/PVE/API2/Backup.pm
@@ -101,12 +101,13 @@ sub parse_vzdump_cron_config {
 	next if $line =~ m/^\s*$/;
 	next if $line =~ m/^PATH\s*=/; # we always overwrite path
 
-	if ($line =~ m|^(\d+)\s+(\d+)\s+\*\s+\*\s+(\S+)\s+root\s+(/\S+/)?vzdump(\s+(.*))?$|) {
+	if ($line =~ m|^(\d+)\s+(\d+)\s+\*\s+\*\s+(\S+)\s+root\s+(/\S+/)?(#)?vzdump(\s+(.*))?$|) {
 	    eval {
 		my $minute = int($1);
 		my $hour = int($2);
 		my $dow = $3;
-		my $param = $6;
+		my $param = $7;
+		my $enabled = $5;
 
 		my $dowhash = parse_dow($dow, 1);
 		die "unable to parse day of week '$dow' in '$filename'\n" if !$dowhash;
@@ -114,6 +115,7 @@ sub parse_vzdump_cron_config {
 		my $args = PVE::Tools::split_args($param);
 		my $opts = PVE::JSONSchema::get_options($vzdump_properties, $args, 'vmid');
 
+		$opts->{enabled} = !defined($enabled);
 		$opts->{id} = "$digest:$jid";
 		$jid++;
 		$opts->{starttime} = sprintf "%02d:%02d", $hour, $minute;
@@ -151,6 +153,7 @@ sub write_vzdump_cron_config {
 
     my $jobs = $cfg->{jobs} || [];
     foreach my $job (@$jobs) {
+	my $enabled = ($job->{enabled}) ? '' : '#';
 	my $dh = parse_dow($job->{dow});
 	my $dow;
 	if ($dh->{mon} && $dh->{tue} && $dh->{wed} && $dh->{thu} &&
@@ -176,7 +179,7 @@ sub write_vzdump_cron_config {
 
 	my $cmd = PVE::VZDump::command_line($job);
 
-	$out .= sprintf "$minute $hour * * %-11s root $cmd\n", $dow;
+	$out .= sprintf "$minute $hour * * %-11s root $enabled$cmd\n", $dow;
     }
 
     my $ejobs = $cfg->{ejobs} || [];
@@ -246,6 +249,12 @@ __PACKAGE__->register_method({
 		description => "Day of week selection.",
 		default => 'mon,tue,wed,thu,fri,sat,sun',
 	    },
+	    enabled => {
+		type => 'boolean',
+		optional => 1,
+		description => "Enable or disable the job.",
+		default => '1',
+	    },
        }),
     },
     returns => { type => 'null' },
@@ -258,7 +267,7 @@ __PACKAGE__->register_method({
 	my $data = cfs_read_file('vzdump.cron');
 
 	$param->{dow} = 'mon,tue,wed,thu,fri,sat,sun' if !defined($param->{dow});
-
+	$param->{enabled} = 1 if !defined($param->{enabled});
 	PVE::VZDump::verify_vzdump_parameters($param, 1);
 
 	push @{$data->{jobs}}, $param;
@@ -323,7 +332,7 @@ __PACKAGE__->register_method({
 		type => 'string',
 		description => "The job ID.",
 		maxLength => 50,
-	    }
+	    },
 	},
     },
     returns => { type => 'null' },
@@ -389,6 +398,12 @@ __PACKAGE__->register_method({
 		description => "A list of settings you want to delete.",
 		optional => 1,
 	    },
+	    enabled => {
+		type => 'boolean',
+		optional => 1,
+		description => "Enable or disable the job.",
+		default => '1',
+	    },
        }),
     },
     returns => { type => 'null' },
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index 61341ca..852a7d0 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -1293,7 +1293,8 @@ sub command_line {
     }
 
     foreach my $p (keys %$param) {
-	next if $p eq 'id' || $p eq 'vmid' || $p eq 'starttime' || $p eq 'dow' || $p eq 'stdout';
+	next if $p eq 'id' || $p eq 'vmid' || $p eq 'starttime' ||
+	        $p eq 'dow' || $p eq 'stdout' || $p eq 'enabled';
 	my $v = $param->{$p};
 	my $pd = $confdesc->{$p} || die "no such vzdump option '$p'\n";
 	if ($p eq 'exclude-path') {
-- 
2.1.4




More information about the pve-devel mailing list