[pve-devel] [PATCH manager 1/2] fix #1594: add API path to trigger vzdump job manually
Stefan Reiter
s.reiter at proxmox.com
Wed Jul 31 13:23:54 CEST 2019
Since we cannot easily proxy the vzdump command to other nodes, we
expect the client to call this on all nodes they want to run the backup
job on (and use standard proxyto=>'node').
Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
I wasn't too sure regarding permissions, so I left it at the rather strict
Sys.Modify. This way, at least no one can use this to do stuff they couldn't
before (as in: if you had Sys.Modify permissions, you could trigger them
"immediately" before this patch too, by setting the day and time to "now" and
waiting a few minutes).
PVE/API2/Backup.pm | 61 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/PVE/API2/Backup.pm b/PVE/API2/Backup.pm
index ec6b4541..bf9a3330 100644
--- a/PVE/API2/Backup.pm
+++ b/PVE/API2/Backup.pm
@@ -9,7 +9,7 @@ use PVE::Tools qw(extract_param);
use PVE::Cluster qw(cfs_register_file cfs_lock_file cfs_read_file cfs_write_file);
use PVE::RESTHandler;
use PVE::RPCEnvironment;
-use PVE::JSONSchema;
+use PVE::JSONSchema qw(get_standard_option);
use PVE::Storage;
use PVE::Exception qw(raise_param_exc);
use PVE::VZDump;
@@ -491,4 +491,63 @@ __PACKAGE__->register_method({
die "$@" if ($@);
}});
+# this method is most useful when called on all nodes in parallel
+# (to correctly mimic scheduled behaviour)
+__PACKAGE__->register_method({
+ name => 'run_job',
+ path => '{id}/{node}/run',
+ method => 'POST',
+ description => "Run vzdump backup job definition on a specified node immediately.",
+ permissions => {
+ check => ['perm', '/', ['Sys.Modify']],
+ },
+ protected => 1,
+ proxyto => 'node',
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ id => {
+ type => 'string',
+ description => "The job ID.",
+ maxLength => 50,
+ },
+ node => get_standard_option('pve-node')
+ },
+ },
+ returns => { type => 'string' },
+ code => sub {
+ my ($param) = @_;
+
+ my $run_job = sub {
+ my $data = cfs_read_file('vzdump.cron');
+ my $jobs = $data->{jobs} || [];
+
+ my $found_job;
+ foreach my $job (@$jobs) {
+ if ($job->{id} eq $param->{id}) {
+ $found_job = $job;
+ last;
+ }
+ }
+
+ raise_param_exc({ id => "No such job '$param->{id}'" })
+ if !$found_job;
+
+ # remove scheduling-specific parameters
+ delete $found_job->{enabled};
+ delete $found_job->{starttime};
+ delete $found_job->{dow};
+ delete $found_job->{id};
+
+ $found_job->{lockwait} = 0;
+
+ # returns a upid
+ return PVE::API2::VZDump->vzdump($found_job);
+ };
+ my $val = cfs_lock_file('vzdump.cron', undef, $run_job);
+ die "$@" if ($@);
+
+ return $val;
+ }});
+
1;
--
2.20.1
More information about the pve-devel
mailing list