Commit c8653ebb authored by Thomas Lamprecht's avatar Thomas Lamprecht Committed by Dietmar Maurer

Added functionality do disable temporary a backup job

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: 's avatarThomas Lamprecht <t.lamprecht@proxmox.com>
parent 1b23db69
...@@ -101,12 +101,13 @@ sub parse_vzdump_cron_config { ...@@ -101,12 +101,13 @@ sub parse_vzdump_cron_config {
next if $line =~ m/^\s*$/; next if $line =~ m/^\s*$/;
next if $line =~ m/^PATH\s*=/; # we always overwrite path 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 { eval {
my $minute = int($1); my $minute = int($1);
my $hour = int($2); my $hour = int($2);
my $dow = $3; my $dow = $3;
my $param = $6; my $param = $7;
my $enabled = $5;
my $dowhash = parse_dow($dow, 1); my $dowhash = parse_dow($dow, 1);
die "unable to parse day of week '$dow' in '$filename'\n" if !$dowhash; die "unable to parse day of week '$dow' in '$filename'\n" if !$dowhash;
...@@ -114,6 +115,7 @@ sub parse_vzdump_cron_config { ...@@ -114,6 +115,7 @@ sub parse_vzdump_cron_config {
my $args = PVE::Tools::split_args($param); my $args = PVE::Tools::split_args($param);
my $opts = PVE::JSONSchema::get_options($vzdump_properties, $args, 'vmid'); my $opts = PVE::JSONSchema::get_options($vzdump_properties, $args, 'vmid');
$opts->{enabled} = !defined($enabled);
$opts->{id} = "$digest:$jid"; $opts->{id} = "$digest:$jid";
$jid++; $jid++;
$opts->{starttime} = sprintf "%02d:%02d", $hour, $minute; $opts->{starttime} = sprintf "%02d:%02d", $hour, $minute;
...@@ -151,6 +153,7 @@ sub write_vzdump_cron_config { ...@@ -151,6 +153,7 @@ sub write_vzdump_cron_config {
my $jobs = $cfg->{jobs} || []; my $jobs = $cfg->{jobs} || [];
foreach my $job (@$jobs) { foreach my $job (@$jobs) {
my $enabled = ($job->{enabled}) ? '' : '#';
my $dh = parse_dow($job->{dow}); my $dh = parse_dow($job->{dow});
my $dow; my $dow;
if ($dh->{mon} && $dh->{tue} && $dh->{wed} && $dh->{thu} && if ($dh->{mon} && $dh->{tue} && $dh->{wed} && $dh->{thu} &&
...@@ -176,7 +179,7 @@ sub write_vzdump_cron_config { ...@@ -176,7 +179,7 @@ sub write_vzdump_cron_config {
my $cmd = PVE::VZDump::command_line($job); 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} || []; my $ejobs = $cfg->{ejobs} || [];
...@@ -246,6 +249,12 @@ __PACKAGE__->register_method({ ...@@ -246,6 +249,12 @@ __PACKAGE__->register_method({
description => "Day of week selection.", description => "Day of week selection.",
default => 'mon,tue,wed,thu,fri,sat,sun', default => 'mon,tue,wed,thu,fri,sat,sun',
}, },
enabled => {
type => 'boolean',
optional => 1,
description => "Enable or disable the job.",
default => '1',
},
}), }),
}, },
returns => { type => 'null' }, returns => { type => 'null' },
...@@ -258,7 +267,7 @@ __PACKAGE__->register_method({ ...@@ -258,7 +267,7 @@ __PACKAGE__->register_method({
my $data = cfs_read_file('vzdump.cron'); my $data = cfs_read_file('vzdump.cron');
$param->{dow} = 'mon,tue,wed,thu,fri,sat,sun' if !defined($param->{dow}); $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); PVE::VZDump::verify_vzdump_parameters($param, 1);
push @{$data->{jobs}}, $param; push @{$data->{jobs}}, $param;
...@@ -323,7 +332,7 @@ __PACKAGE__->register_method({ ...@@ -323,7 +332,7 @@ __PACKAGE__->register_method({
type => 'string', type => 'string',
description => "The job ID.", description => "The job ID.",
maxLength => 50, maxLength => 50,
} },
}, },
}, },
returns => { type => 'null' }, returns => { type => 'null' },
...@@ -389,6 +398,12 @@ __PACKAGE__->register_method({ ...@@ -389,6 +398,12 @@ __PACKAGE__->register_method({
description => "A list of settings you want to delete.", description => "A list of settings you want to delete.",
optional => 1, optional => 1,
}, },
enabled => {
type => 'boolean',
optional => 1,
description => "Enable or disable the job.",
default => '1',
},
}), }),
}, },
returns => { type => 'null' }, returns => { type => 'null' },
......
...@@ -1311,7 +1311,8 @@ sub command_line { ...@@ -1311,7 +1311,8 @@ sub command_line {
} }
foreach my $p (keys %$param) { 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 $v = $param->{$p};
my $pd = $confdesc->{$p} || die "no such vzdump option '$p'\n"; my $pd = $confdesc->{$p} || die "no such vzdump option '$p'\n";
if ($p eq 'exclude-path') { if ($p eq 'exclude-path') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment