Commit 80bae398 authored by Dietmar Maurer's avatar Dietmar Maurer

cleanup vzdump backup/cron code

parent 2a911669
......@@ -170,19 +170,12 @@ sub write_vzdump_cron_config {
} else {
die "unable to parse job start time\n";
}
$job->{quiet} = 1; # we do not want messages from cron
my $param = "";
foreach my $p (keys %$job) {
next if $p eq 'id' || $p eq 'vmid' || $p eq 'starttime' || $p eq 'dow';
my $v = $job->{$p};
$param .= " --$p " . PVE::Tools::shellquote($v) if defined($v) && $v ne '';
}
if ($job->{vmid}) {
$param .= " " . join(' ', PVE::Tools::split_list($job->{vmid}));
}
my $cmd = PVE::VZDump::command_line($job);
$out .= sprintf "$minute $hour * * %-11s root vzdump$param\n", $dow;
$out .= sprintf "$minute $hour * * %-11s root $cmd\n", $dow;
}
my $ejobs = $cfg->{ejobs} || [];
......@@ -259,12 +252,7 @@ __PACKAGE__->register_method({
$param->{dow} = 'mon,tue,wed,thu,fri,sat,sun' if !defined($param->{dow});
$param->{all} = 1 if defined($param->{exclude});
raise_param_exc({ all => "option conflicts with option 'vmid'"})
if $param->{all} && $param->{vmid};
raise_param_exc({ vmid => "property is missing"})
if !$param->{all} && !$param->{vmid};
PVE::VZDump::verify_vzdump_parameters($param, 1);
push @{$data->{jobs}}, $param;
......@@ -400,15 +388,14 @@ __PACKAGE__->register_method({
die "no options specified\n" if !scalar(keys %$param);
raise_param_exc({ all => "option conflicts with option 'vmid'"})
if $param->{all} && $param->{vmid};
PVE::VZDump::verify_vzdump_parameters($param);
my $delete = extract_param($param, 'delete');
my @delete = PVE::Tools::split_list(extract_param($param, 'delete'));
foreach my $job (@$jobs) {
if ($job->{id} eq $param->{id}) {
foreach my $k (PVE::Tools::split_list($delete)) {
foreach my $k (@delete) {
if (!PVE::VZDump::option_exists($k)) {
raise_param_exc({ delete => "unknown option '$k'" });
}
......@@ -422,18 +409,14 @@ __PACKAGE__->register_method({
$job->{all} = 1 if defined($job->{exclude});
if ($param->{vmid}) {
if (defined($param->{vmid})) {
delete $job->{all};
delete $job->{exclude};
} elsif ($param->{all}) {
delete $job->{vmid};
}
raise_param_exc({ all => "option conflicts with option 'vmid'"})
if $job->{all} && $job->{vmid};
raise_param_exc({ vmid => "property is missing"})
if !$job->{all} && !$job->{vmid};
PVE::VZDump::verify_vzdump_parameters($job, 1);
cfs_write_file('vzdump.cron', $data);
......
......@@ -2,7 +2,7 @@ package PVE::API2::VZDump;
use strict;
use warnings;
use PVE::Exception qw(raise_param_exc);;
use PVE::Exception qw(raise_param_exc);
use PVE::Tools qw(extract_param);
use PVE::Cluster qw(cfs_register_file cfs_read_file);
use PVE::INotify;
......@@ -54,26 +54,16 @@ __PACKAGE__->register_method ({
# by default we set --rsyncable for gzip
local $ENV{GZIP} = "--rsyncable" if !$ENV{GZIP};
$param->{all} = 1 if defined($param->{exclude});
raise_param_exc({ all => "option conflicts with option 'vmid'"})
if $param->{all} && $param->{vmid};
raise_param_exc({ vmid => "property is missing"})
if !$param->{all} && !$param->{vmid};
PVE::VZDump::verify_vzdump_parameters($param, 1);
# silent exit if we run on wrong node
exit(0) if $param->{node} && $param->{node} ne $nodename;
my $cmdline = PVE::VZDump::command_line($param);
# convert string lists to arrays
my @vmids = PVE::Tools::split_list(extract_param($param, 'vmid'));
my $cmdline = 'vzdump';
$cmdline .= ' ' . join(' ', @vmids) if scalar(@vmids);
foreach my $p (keys %$param) {
$cmdline .= " --$p $param->{$p}";
}
$param->{vmids} = PVE::VZDump::check_vmids(@vmids) if !$param->{all};
my @exclude = PVE::Tools::split_list(extract_param($param, 'exclude'));
$param->{exclude} = PVE::VZDump::check_vmids(@exclude);
......
......@@ -3,6 +3,7 @@ package PVE::VZDump;
use strict;
use warnings;
use Fcntl ':flock';
use PVE::Exception qw(raise_param_exc);
use PVE::SafeSyslog;
use IO::File;
use IO::Select;
......@@ -1140,4 +1141,41 @@ sub json_config_properties {
return $prop;
}
sub verify_vzdump_parameters {
my ($param, $check_missing) = @_;
raise_param_exc({ all => "option conflicts with option 'vmid'"})
if $param->{all} && $param->{vmid};
raise_param_exc({ exclude => "option conflicts with option 'vmid'"})
if $param->{exclude} && $param->{vmid};
$param->{all} = 1 if defined($param->{exclude});
return if !$check_missing;
raise_param_exc({ vmid => "property is missing"})
if !$param->{all} && !$param->{vmid};
}
sub command_line {
my ($param) = @_;
my $cmd = "vzdump";
if ($param->{vmid}) {
$cmd .= " " . join(' ', PVE::Tools::split_list($param->{vmid}));
}
foreach my $p (keys %$param) {
next if $p eq 'id' || $p eq 'vmid' || $p eq 'starttime' || $p eq 'dow';
my $v = $param->{$p};
my $pd = $confdesc->{$p} || die "no such vzdump option '$p'\n";
$cmd .= " --$p " . PVE::Tools::shellquote($v) if defined($v) && $v ne '';
}
return $cmd;
}
1;
......@@ -202,13 +202,7 @@ Ext.define('PVE.dc.BackupEdit', {
values.all = 1;
values.exclude = values.vmid;
delete values.vmid;
} else {
if (!me.create) {
PVE.Utils.assemble_field_data(values, { 'delete': 'all' });
PVE.Utils.assemble_field_data(values, { 'delete': 'exclude' });
}
}
return values;
}
});
......
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