]>
git.proxmox.com Git - pve-storage.git/blob - PVE/API2/Storage/PruneBackups.pm
a84d1c8089b19d6435e86d3bd1d753c99357a990
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 exactly " .
20 "what a subsequent prune call does, if the hour changes or if backups are removed/added " .
23 check
=> ['perm', '/storage/{storage}', ['Datastore.Audit', 'Datastore.AllocateSpace'], any
=> 1],
28 additionalProperties
=> 0,
30 node
=> get_standard_option
('pve-node'),
31 storage
=> get_standard_option
('pve-storage-id', {
32 completion
=> \
&PVE
::Storage
::complete_storage_enabled
,
34 'prune-backups' => get_standard_option
('prune-backups', {
35 description
=> "Use these retention options instead of those from the storage configuration.",
39 description
=> "Either 'qemu' or 'lxc'. Only consider backups for guests of this type.",
42 enum
=> ['qemu', 'lxc'],
44 vmid
=> get_standard_option
('pve-vmid', {
45 description
=> "Only consider backups for this guest.",
47 completion
=> \
&PVE
::Cluster
::complete_vmid
,
57 description
=> "Backup volume ID.",
61 description
=> "Creation time of the backup (seconds since the UNIX epoch).",
65 description
=> "Whether the backup would be kept or removed. For backups that don't " .
66 "use the standard naming scheme, it's 'protected'.",
70 description
=> "One of 'qemu', 'lxc', 'openvz' or 'unknown'.",
74 description
=> "The VM the backup belongs to.",
84 my $cfg = PVE
::Storage
::config
();
86 my $vmid = extract_param
($param, 'vmid');
87 my $type = extract_param
($param, 'type');
88 my $storeid = extract_param
($param, 'storage');
90 my $prune_backups = extract_param
($param, 'prune-backups');
91 $prune_backups = PVE
::JSONSchema
::parse_property_string
('prune-backups', $prune_backups)
92 if defined($prune_backups);
94 return PVE
::Storage
::prune_backups
($cfg, $storeid, $prune_backups, $vmid, $type, 1);
97 __PACKAGE__-
>register_method ({
101 description
=> "Prune backups. Only those using the standard naming scheme are considered.",
103 description
=> "You need the 'Datastore.Allocate' privilege on the storage " .
104 "(or if a VM ID is specified, 'Datastore.AllocateSpace' and 'VM.Backup' for the VM).",
110 additionalProperties
=> 0,
112 node
=> get_standard_option
('pve-node'),
113 storage
=> get_standard_option
('pve-storage-id', {
114 completion
=> \
&PVE
::Storage
::complete_storage
,
116 'prune-backups' => get_standard_option
('prune-backups', {
117 description
=> "Use these retention options instead of those from the storage configuration.",
120 description
=> "Either 'qemu' or 'lxc'. Only consider backups for guests of this type.",
123 enum
=> ['qemu', 'lxc'],
125 vmid
=> get_standard_option
('pve-vmid', {
126 description
=> "Only prune backups for this VM.",
127 completion
=> \
&PVE
::Cluster
::complete_vmid
,
132 returns
=> { type
=> 'string' },
136 my $rpcenv = PVE
::RPCEnvironment
::get
();
137 my $authuser = $rpcenv->get_user();
139 my $cfg = PVE
::Storage
::config
();
141 my $vmid = extract_param
($param, 'vmid');
142 my $type = extract_param
($param, 'type');
143 my $storeid = extract_param
($param, 'storage');
145 my $prune_backups = extract_param
($param, 'prune-backups');
146 $prune_backups = PVE
::JSONSchema
::parse_property_string
('prune-backups', $prune_backups)
147 if defined($prune_backups);
149 if (defined($vmid)) {
150 $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']);
151 $rpcenv->check($authuser, "/vms/$vmid", ['VM.Backup']);
153 $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.Allocate']);
156 my $id = (defined($vmid) ?
"$vmid@" : '') . $storeid;
158 PVE
::Storage
::prune_backups
($cfg, $storeid, $prune_backups, $vmid, $type, 0);
161 return $rpcenv->fork_worker('prunebackups', $id, $authuser, $worker);