mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-06-04 14:58:38 +00:00

in addition to listing the vzdump.cron jobs, also list from the jobs.cfg file. updates/creations go into the new jobs.cfg only now and on update, starttime+dow get converted to a schedule this transformation is straight forward, since 'dow' is already in a compatible format (e.g. 'mon,tue') and we simply append the starttime (if any) id on creation is optional for now (for api compat), but will be autogenerated (uuid). on update, we simply take the id from before (the ids of the other entries in vzdump.cron will change but they would anyway) as long as we have the vzdump.cron file, we must lock both vzdump.cron and jobs.cfg, since we often update both we also change the backupinfo api call to read the jobs.cfg too Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
154 lines
3.5 KiB
Perl
154 lines
3.5 KiB
Perl
package PVE::API2::Cluster::BackupInfo;
|
|
|
|
use strict;
|
|
use warnings;
|
|
use Digest::SHA;
|
|
|
|
use PVE::SafeSyslog;
|
|
use PVE::Tools qw(extract_param);
|
|
use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_write_file);
|
|
use PVE::RESTHandler;
|
|
use PVE::RPCEnvironment;
|
|
use PVE::JSONSchema;
|
|
use PVE::Storage;
|
|
use PVE::Exception qw(raise_param_exc);
|
|
use PVE::VZDump;
|
|
use PVE::VZDump::Common;
|
|
|
|
use base qw(PVE::RESTHandler);
|
|
|
|
sub get_included_vmids {
|
|
my $vzconf = cfs_read_file('vzdump.cron');
|
|
|
|
my $all_jobs = $vzconf->{jobs} || [];
|
|
my @all_vmids = ();
|
|
|
|
for my $job (@$all_jobs) {
|
|
my $job_included_guests = PVE::VZDump::get_included_guests($job);
|
|
push @all_vmids, ( map { @{$_} } values %{$job_included_guests} );
|
|
}
|
|
|
|
my $vzjobs = cfs_read_file('jobs.cfg');
|
|
|
|
for my $job (values %{$vzjobs->{ids}}) {
|
|
next if $job->{type} ne 'vzdump';
|
|
|
|
my $job_included_guests = PVE::VZDump::get_included_guests($job);
|
|
push @all_vmids, ( map { @{$_} } values %{$job_included_guests} );
|
|
}
|
|
|
|
return { map { $_ => 1 } @all_vmids };
|
|
}
|
|
|
|
__PACKAGE__->register_method({
|
|
name => 'index',
|
|
path => '',
|
|
method => 'GET',
|
|
description => "Index for backup info related endpoints",
|
|
parameters => {
|
|
additionalProperties => 0,
|
|
properties => {},
|
|
},
|
|
returns => {
|
|
type => 'array',
|
|
description => 'Directory index.',
|
|
items => {
|
|
type => "object",
|
|
properties => {
|
|
subdir => {
|
|
type => 'string',
|
|
description => 'API sub-directory endpoint',
|
|
},
|
|
},
|
|
},
|
|
links => [ { rel => 'child', href => "{subdir}" } ],
|
|
},
|
|
code => sub {
|
|
return [
|
|
{ subdir => 'not-backed-up' },
|
|
];
|
|
}});
|
|
|
|
__PACKAGE__->register_method({
|
|
name => 'get_guests_not_in_backup',
|
|
path => 'not-backed-up',
|
|
method => 'GET',
|
|
protected => 1,
|
|
description => "Shows all guests which are not covered by any backup job.",
|
|
permissions => {
|
|
check => ['perm', '/', ['Sys.Audit']],
|
|
},
|
|
parameters => {
|
|
additionalProperties => 0,
|
|
properties => {},
|
|
},
|
|
returns => {
|
|
type => 'array',
|
|
description => 'Contains the guest objects.',
|
|
items => {
|
|
type => 'object',
|
|
properties => {
|
|
vmid => {
|
|
type => 'integer',
|
|
description => 'VMID of the guest.',
|
|
},
|
|
name => {
|
|
type => 'string',
|
|
description => 'Name of the guest',
|
|
optional => 1,
|
|
},
|
|
type => {
|
|
type => 'string',
|
|
description => 'Type of the guest.',
|
|
enum => ['qemu', 'lxc'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
code => sub {
|
|
my $rpcenv = PVE::RPCEnvironment::get();
|
|
my $user = $rpcenv->get_user();
|
|
my $rrd = PVE::Cluster::rrd_dump();
|
|
my $included_vmids = get_included_vmids();
|
|
my $vmlist = PVE::Cluster::get_vmlist();
|
|
my @vmids = ( keys %{$vmlist->{ids}} );
|
|
|
|
# remove VMIDs to which the user has no permission to not leak infos
|
|
# like the guest name
|
|
my @allowed_vmids = grep {
|
|
$rpcenv->check($user, "/vms/$_", [ 'VM.Audit' ], 1);
|
|
} @vmids;
|
|
|
|
my $result = [];
|
|
|
|
for my $vmid (@allowed_vmids) {
|
|
|
|
next if $included_vmids->{$vmid};
|
|
|
|
my $type = $vmlist->{ids}->{$vmid}->{type};
|
|
my $node = $vmlist->{ids}->{$vmid}->{node};
|
|
|
|
my $conf;
|
|
my $name = "";
|
|
|
|
if ($type eq 'qemu') {
|
|
$conf = PVE::QemuConfig->load_config($vmid, $node);
|
|
$name = $conf->{name};
|
|
} elsif ($type eq 'lxc') {
|
|
$conf = PVE::LXC::Config->load_config($vmid, $node);
|
|
$name = $conf->{hostname};
|
|
} else {
|
|
die "VMID $vmid is neither Qemu nor LXC guest\n";
|
|
}
|
|
|
|
push @{$result}, {
|
|
vmid => int($vmid),
|
|
name => $name,
|
|
type => $type,
|
|
};
|
|
}
|
|
|
|
return $result;
|
|
}});
|
|
1;
|