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