]>
git.proxmox.com Git - pve-storage.git/blob - PVE/API2/Storage/PruneBackups.pm
1 package PVE
::API2
::Storage
::PruneBackups
;
7 use PVE
::JSONSchema
qw(get_standard_option);
9 use PVE
::RPCEnvironment
;
11 use PVE
::Tools
qw(extract_param);
13 use base
qw(PVE::RESTHandler);
15 __PACKAGE__-
>register_method ({
19 description
=> "Get prune information for backups. NOTE: this is only a preview and might not be " .
20 "what a subsequent prune call does if backups are removed/added in the meantime.",
22 check
=> ['perm', '/storage/{storage}', ['Datastore.Audit', 'Datastore.AllocateSpace'], any
=> 1],
27 additionalProperties
=> 0,
29 node
=> get_standard_option
('pve-node'),
30 storage
=> get_standard_option
('pve-storage-id', {
31 completion
=> \
&PVE
::Storage
::complete_storage_enabled
,
33 'prune-backups' => get_standard_option
('prune-backups', {
34 description
=> "Use these retention options instead of those from the storage configuration.",
38 description
=> "Either 'qemu' or 'lxc'. Only consider backups for guests of this type.",
41 enum
=> ['qemu', 'lxc'],
43 vmid
=> get_standard_option
('pve-vmid', {
44 description
=> "Only consider backups for this guest.",
46 completion
=> \
&PVE
::Cluster
::complete_vmid
,
56 description
=> "Backup volume ID.",
60 description
=> "Creation time of the backup (seconds since the UNIX epoch).",
64 description
=> "Whether the backup would be kept or removed. For backups that don't " .
65 "use the standard naming scheme, it's 'protected'.",
69 description
=> "One of 'qemu', 'lxc', 'openvz' or 'unknown'.",
73 description
=> "The VM the backup belongs to.",
83 my $cfg = PVE
::Storage
::config
();
85 my $vmid = extract_param
($param, 'vmid');
86 my $type = extract_param
($param, 'type');
87 my $storeid = extract_param
($param, 'storage');
89 my $prune_backups = extract_param
($param, 'prune-backups');
90 $prune_backups = PVE
::JSONSchema
::parse_property_string
('prune-backups', $prune_backups)
91 if defined($prune_backups);
93 return PVE
::Storage
::prune_backups
($cfg, $storeid, $prune_backups, $vmid, $type, 1);
96 __PACKAGE__-
>register_method ({
100 description
=> "Prune backups. Only those using the standard naming scheme are considered.",
102 description
=> "You need the 'Datastore.Allocate' privilege on the storage " .
103 "(or if a VM ID is specified, 'Datastore.AllocateSpace' and 'VM.Backup' for the VM).",
109 additionalProperties
=> 0,
111 node
=> get_standard_option
('pve-node'),
112 storage
=> get_standard_option
('pve-storage-id', {
113 completion
=> \
&PVE
::Storage
::complete_storage
,
115 'prune-backups' => get_standard_option
('prune-backups', {
116 description
=> "Use these retention options instead of those from the storage configuration.",
119 description
=> "Either 'qemu' or 'lxc'. Only consider backups for guests of this type.",
122 enum
=> ['qemu', 'lxc'],
124 vmid
=> get_standard_option
('pve-vmid', {
125 description
=> "Only prune backups for this VM.",
126 completion
=> \
&PVE
::Cluster
::complete_vmid
,
131 returns
=> { type
=> 'string' },
135 my $rpcenv = PVE
::RPCEnvironment
::get
();
136 my $authuser = $rpcenv->get_user();
138 my $cfg = PVE
::Storage
::config
();
140 my $vmid = extract_param
($param, 'vmid');
141 my $type = extract_param
($param, 'type');
142 my $storeid = extract_param
($param, 'storage');
144 my $prune_backups = extract_param
($param, 'prune-backups');
145 $prune_backups = PVE
::JSONSchema
::parse_property_string
('prune-backups', $prune_backups)
146 if defined($prune_backups);
148 if (defined($vmid)) {
149 $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']);
150 $rpcenv->check($authuser, "/vms/$vmid", ['VM.Backup']);
152 $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.Allocate']);
155 my $id = (defined($vmid) ?
"$vmid@" : '') . $storeid;
157 PVE
::Storage
::prune_backups
($cfg, $storeid, $prune_backups, $vmid, $type, 0);
160 return $rpcenv->fork_worker('prunebackups', $id, $authuser, $worker);