]> git.proxmox.com Git - pve-storage.git/blame - PVE/CLI/pvesm.pm
(remote) export: check and untaint format
[pve-storage.git] / PVE / CLI / pvesm.pm
CommitLineData
c669f42d
DM
1package PVE::CLI::pvesm;
2
3use strict;
4use warnings;
5
9559a62a 6use POSIX qw(O_RDONLY O_WRONLY O_CREAT O_TRUNC);
c669f42d
DM
7use Fcntl ':flock';
8use File::Path;
c56f7a71 9use MIME::Base64 qw(encode_base64);
c669f42d 10
1ebd925d
FG
11use IO::Socket::IP;
12use IO::Socket::UNIX;
13use Socket qw(SOCK_STREAM);
14
c669f42d
DM
15use PVE::SafeSyslog;
16use PVE::Cluster;
17use PVE::INotify;
18use PVE::RPCEnvironment;
19use PVE::Storage;
25a95836 20use PVE::Tools qw(extract_param);
c669f42d
DM
21use PVE::API2::Storage::Config;
22use PVE::API2::Storage::Content;
25a95836 23use PVE::API2::Storage::PruneBackups;
2892b673 24use PVE::API2::Storage::Scan;
c669f42d 25use PVE::API2::Storage::Status;
c669f42d 26use PVE::JSONSchema qw(get_standard_option);
c26f3a71 27use PVE::PTY;
c669f42d
DM
28
29use PVE::CLIHandler;
30
31use base qw(PVE::CLIHandler);
32
33my $nodename = PVE::INotify::nodename();
34
42f2c57d
DC
35sub param_mapping {
36 my ($name) = @_;
37
38 my $password_map = PVE::CLIHandler::get_standard_mapping('pve-password', {
39 func => sub {
40 my ($value) = @_;
41 return $value if $value;
42 return PVE::PTY::read_password("Enter Password: ");
43 },
44 });
baf77120 45
0ca8eb4f
WB
46 my $enc_key_map = {
47 name => 'encryption-key',
48 desc => 'a file containing an encryption key, or the special value "autogen"',
49 func => sub {
50 my ($value) = @_;
51 return $value if $value eq 'autogen';
52 return PVE::Tools::file_get_contents($value);
53 }
54 };
55
c56f7a71
FG
56 my $master_key_map = {
57 name => 'master-pubkey',
58 desc => 'a file containing a PEM-formatted master public key',
59 func => sub {
60 my ($value) = @_;
61 return encode_base64(PVE::Tools::file_get_contents($value), '');
62 }
63 };
64
22b68016
AL
65 my $keyring_map = {
66 name => 'keyring',
67 desc => 'file containing the keyring to authenticate in the Ceph cluster',
68 func => sub {
69 my ($value) = @_;
70 return PVE::Tools::file_get_contents($value);
71 },
72 };
0ca8eb4f 73
42f2c57d
DC
74 my $mapping = {
75 'cifsscan' => [ $password_map ],
11a942a1 76 'cifs' => [ $password_map ],
39fc0c77 77 'pbs' => [ $password_map ],
22b68016
AL
78 'create' => [ $password_map, $enc_key_map, $master_key_map, $keyring_map ],
79 'update' => [ $password_map, $enc_key_map, $master_key_map, $keyring_map ],
42f2c57d
DC
80 };
81 return $mapping->{$name};
c26f3a71
WL
82}
83
f984732e
DM
84sub setup_environment {
85 PVE::RPCEnvironment->setup_default_cli_env();
86}
87
5f184292
FE
88__PACKAGE__->register_method ({
89 name => 'apiinfo',
90 path => 'apiinfo',
91 method => 'GET',
92 description => "Returns APIVER and APIAGE.",
93 parameters => {
94 additionalProperties => 0,
95 properties => {},
96 },
97 returns => {
98 type => 'object',
99 properties => {
100 apiver => { type => 'integer' },
101 apiage => { type => 'integer' },
102 },
103 },
104 code => sub {
105 return {
106 apiver => PVE::Storage::APIVER,
107 apiage => PVE::Storage::APIAGE,
108 };
109 }
110});
111
c669f42d
DM
112__PACKAGE__->register_method ({
113 name => 'path',
114 path => 'path',
115 method => 'GET',
116 description => "Get filesystem path for specified volume",
117 parameters => {
118 additionalProperties => 0,
119 properties => {
120 volume => {
121 description => "Volume identifier",
122 type => 'string', format => 'pve-volume-id',
f3bd890d 123 completion => \&PVE::Storage::complete_volume,
c669f42d
DM
124 },
125 },
126 },
127 returns => { type => 'null' },
128
129 code => sub {
130 my ($param) = @_;
131
132 my $cfg = PVE::Storage::config();
133
134 my $path = PVE::Storage::path ($cfg, $param->{volume});
135
136 print "$path\n";
137
138 return undef;
139
140 }});
141
fa017b96
FG
142__PACKAGE__->register_method ({
143 name => 'extractconfig',
144 path => 'extractconfig',
145 method => 'GET',
146 description => "Extract configuration from vzdump backup archive.",
147 permissions => {
148 description => "The user needs 'VM.Backup' permissions on the backed up guest ID, and 'Datastore.AllocateSpace' on the backup storage.",
149 user => 'all',
150 },
151 protected => 1,
152 parameters => {
153 additionalProperties => 0,
154 properties => {
155 volume => {
156 description => "Volume identifier",
157 type => 'string',
158 completion => \&PVE::Storage::complete_volume,
159 },
160 },
161 },
162 returns => { type => 'null' },
163 code => sub {
164 my ($param) = @_;
165 my $volume = $param->{volume};
166
167 my $rpcenv = PVE::RPCEnvironment::get();
168 my $authuser = $rpcenv->get_user();
169
170 my $storage_cfg = PVE::Storage::config();
1f37ad56
FE
171 PVE::Storage::check_volume_access(
172 $rpcenv,
173 $authuser,
174 $storage_cfg,
175 undef,
176 $volume,
177 'backup',
178 );
fa017b96 179
f303dec6
FE
180 if (PVE::Storage::parse_volume_id($volume, 1)) {
181 my (undef, undef, $ownervm) = PVE::Storage::parse_volname($storage_cfg, $volume);
182 $rpcenv->check($authuser, "/vms/$ownervm", ['VM.Backup']);
183 }
184
fa017b96
FG
185 my $config_raw = PVE::Storage::extract_vzdump_config($storage_cfg, $volume);
186
187 print "$config_raw\n";
188 return;
189 }});
190
c669f42d
DM
191my $print_content = sub {
192 my ($list) = @_;
193
61c261e7 194 my ($maxlenname, $maxsize) = (0, 0);
c669f42d 195 foreach my $info (@$list) {
c669f42d
DM
196 my $volid = $info->{volid};
197 my $sidlen = length ($volid);
198 $maxlenname = $sidlen if $sidlen > $maxlenname;
61c261e7 199 $maxsize = $info->{size} if ($info->{size} // 0) > $maxsize;
c669f42d 200 }
61c261e7
TL
201 my $sizemaxdigits = length($maxsize);
202
203 my $basefmt = "%-${maxlenname}s %-7s %-9s %${sizemaxdigits}s";
204 printf "$basefmt %s\n", "Volid", "Format", "Type", "Size", "VMID";
c669f42d
DM
205
206 foreach my $info (@$list) {
207 next if !$info->{vmid};
208 my $volid = $info->{volid};
209
61c261e7 210 printf "$basefmt %d\n", $volid, $info->{format}, $info->{content}, $info->{size}, $info->{vmid};
c669f42d
DM
211 }
212
213 foreach my $info (sort { $a->{format} cmp $b->{format} } @$list) {
214 next if $info->{vmid};
215 my $volid = $info->{volid};
216
61c261e7 217 printf "$basefmt\n", $volid, $info->{format}, $info->{content}, $info->{size};
c669f42d
DM
218 }
219};
220
221my $print_status = sub {
222 my $res = shift;
223
224 my $maxlen = 0;
225 foreach my $res (@$res) {
226 my $storeid = $res->{storage};
227 $maxlen = length ($storeid) if length ($storeid) > $maxlen;
228 }
229 $maxlen+=1;
230
d40e27de
TL
231 printf "%-${maxlen}s %10s %10s %15s %15s %15s %8s\n", 'Name', 'Type',
232 'Status', 'Total', 'Used', 'Available', '%';
233
c669f42d
DM
234 foreach my $res (sort { $a->{storage} cmp $b->{storage} } @$res) {
235 my $storeid = $res->{storage};
236
d40e27de
TL
237 my $active = $res->{active} ? 'active' : 'inactive';
238 my ($per, $per_fmt) = (0, '% 7.2f%%');
239 $per = ($res->{used}*100)/$res->{total} if $res->{total} > 0;
240
241 if (!$res->{enabled}) {
04301013 242 $per = 'N/A';
d40e27de
TL
243 $per_fmt = '% 8s';
244 $active = 'disabled';
245 }
c669f42d 246
d40e27de
TL
247 printf "%-${maxlen}s %10s %10s %15d %15d %15d $per_fmt\n", $storeid,
248 $res->{type}, $active, $res->{total}/1024, $res->{used}/1024,
249 $res->{avail}/1024, $per;
c669f42d
DM
250 }
251};
252
47f37b53
WB
253__PACKAGE__->register_method ({
254 name => 'export',
255 path => 'export',
256 method => 'GET',
a43a796c 257 description => "Used internally to export a volume.",
47f37b53
WB
258 protected => 1,
259 parameters => {
260 additionalProperties => 0,
261 properties => {
262 volume => {
263 description => "Volume identifier",
264 type => 'string',
265 completion => \&PVE::Storage::complete_volume,
266 },
267 format => {
268 description => "Export stream format",
269 type => 'string',
71460c8a 270 enum => $PVE::Storage::KNOWN_EXPORT_FORMATS,
47f37b53
WB
271 },
272 filename => {
273 description => "Destination file name",
274 type => 'string',
275 },
276 base => {
277 description => "Snapshot to start an incremental stream from",
278 type => 'string',
bef7920d 279 pattern => qr/[a-z0-9_\-]{1,40}/i,
47f37b53
WB
280 maxLength => 40,
281 optional => 1,
282 },
283 snapshot => {
284 description => "Snapshot to export",
285 type => 'string',
bef7920d 286 pattern => qr/[a-z0-9_\-]{1,40}/i,
47f37b53
WB
287 maxLength => 40,
288 optional => 1,
289 },
290 'with-snapshots' => {
291 description =>
292 "Whether to include intermediate snapshots in the stream",
293 type => 'boolean',
294 optional => 1,
295 default => 0,
296 },
3cc29a04
WB
297 'snapshot-list' => {
298 description => "Ordered list of snapshots to transfer",
299 type => 'string',
300 format => 'string-list',
301 optional => 1,
302 },
47f37b53
WB
303 },
304 },
305 returns => { type => 'null' },
306 code => sub {
307 my ($param) = @_;
308
3cc29a04
WB
309 my $with_snapshots = $param->{'with-snapshots'};
310 if (defined(my $list = $param->{'snapshot-list'})) {
311 $with_snapshots = PVE::Tools::split_list($list);
312 }
313
47f37b53
WB
314 my $filename = $param->{filename};
315
316 my $outfh;
317 if ($filename eq '-') {
318 $outfh = \*STDOUT;
319 } else {
9559a62a 320 sysopen($outfh, $filename, O_CREAT|O_WRONLY|O_TRUNC)
47f37b53
WB
321 or die "open($filename): $!\n";
322 }
323
324 eval {
325 my $cfg = PVE::Storage::config();
326 PVE::Storage::volume_export($cfg, $outfh, $param->{volume}, $param->{format},
3cc29a04 327 $param->{snapshot}, $param->{base}, $with_snapshots);
47f37b53
WB
328 };
329 my $err = $@;
330 if ($filename ne '-') {
331 close($outfh);
332 unlink($filename) if $err;
333 }
334 die $err if $err;
335 return;
336 }
337});
338
339__PACKAGE__->register_method ({
340 name => 'import',
341 path => 'import',
342 method => 'PUT',
a43a796c 343 description => "Used internally to import a volume.",
47f37b53
WB
344 protected => 1,
345 parameters => {
346 additionalProperties => 0,
347 properties => {
348 volume => {
349 description => "Volume identifier",
350 type => 'string',
351 completion => \&PVE::Storage::complete_volume,
352 },
353 format => {
354 description => "Import stream format",
355 type => 'string',
71460c8a 356 enum => $PVE::Storage::KNOWN_EXPORT_FORMATS,
47f37b53
WB
357 },
358 filename => {
228e5be9 359 description => "Source file name. For '-' stdin is used, the " .
1ebd925d
FG
360 "tcp://<IP-or-CIDR> format allows to use a TCP connection, " .
361 "the unix://PATH-TO-SOCKET format a UNIX socket as input." .
228e5be9 362 "Else, the file is treated as common file.",
47f37b53
WB
363 type => 'string',
364 },
365 base => {
366 description => "Base snapshot of an incremental stream",
367 type => 'string',
bef7920d 368 pattern => qr/[a-z0-9_\-]{1,40}/i,
47f37b53
WB
369 maxLength => 40,
370 optional => 1,
371 },
372 'with-snapshots' => {
373 description =>
374 "Whether the stream includes intermediate snapshots",
375 type => 'boolean',
376 optional => 1,
377 default => 0,
378 },
52595938
WB
379 'delete-snapshot' => {
380 description => "A snapshot to delete on success",
381 type => 'string',
bef7920d 382 pattern => qr/[a-z0-9_\-]{1,80}/i,
52595938
WB
383 maxLength => 80,
384 optional => 1,
385 },
a97d3ee4
FE
386 'allow-rename' => {
387 description => "Choose a new volume ID if the requested " .
388 "volume ID already exists, instead of throwing an error.",
389 type => 'boolean',
390 optional => 1,
391 default => 0,
392 },
3cc29a04
WB
393 snapshot => {
394 description => "The current-state snapshot if the stream contains snapshots",
395 type => 'string',
396 pattern => qr/[a-z0-9_\-]{1,40}/i,
397 maxLength => 40,
398 optional => 1,
399 },
47f37b53
WB
400 },
401 },
a97d3ee4 402 returns => { type => 'string' },
47f37b53
WB
403 code => sub {
404 my ($param) = @_;
405
406 my $filename = $param->{filename};
407
408 my $infh;
409 if ($filename eq '-') {
410 $infh = \*STDIN;
228e5be9
TL
411 } elsif ($filename =~ m!^tcp://(([^/]+)(/\d+)?)$!) {
412 my ($cidr, $ip, $subnet) = ($1, $2, $3);
413 if ($subnet) { # got real CIDR notation, not just IP
a2aae38c 414 my $ips = PVE::Network::get_local_ip_from_cidr($cidr);
ed2df8e3
TL
415 die "Unable to get any local IP address in network '$cidr'\n"
416 if scalar(@$ips) < 1;
417 die "Got multiple local IP address in network '$cidr'\n"
418 if scalar(@$ips) > 1;
419
420 $ip = $ips->[0];
228e5be9
TL
421 }
422 my $family = PVE::Tools::get_host_address_family($ip);
423 my $port = PVE::Tools::next_migrate_port($family, $ip);
424
425 my $sock_params = {
426 Listen => 1,
427 ReuseAddr => 1,
428 Proto => &Socket::IPPROTO_TCP,
429 GetAddrInfoFlags => 0,
430 LocalAddr => $ip,
431 LocalPort => $port,
432 };
433 my $socket = IO::Socket::IP->new(%$sock_params)
434 or die "failed to open socket: $!\n";
435
436 print "$ip\n$port\n"; # tell remote where to connect
437 *STDOUT->flush();
438
439 my $prev_alarm = alarm 0;
440 local $SIG{ALRM} = sub { die "timed out waiting for client\n" };
441 alarm 30;
442 my $client = $socket->accept; # Wait for a client
443 alarm $prev_alarm;
1ebd925d
FG
444 close($socket);
445
446 $infh = \*$client;
447 } elsif ($filename =~ m!^unix://(.*)$!) {
448 my $socket_path = $1;
449 my $socket = IO::Socket::UNIX->new(
450 Type => SOCK_STREAM(),
451 Local => $socket_path,
452 Listen => 1,
453 ) or die "failed to open socket: $!\n";
454
455 print "ready\n";
456 *STDOUT->flush();
457
458 my $prev_alarm = alarm 0;
459 local $SIG{ALRM} = sub { die "timed out waiting for client\n" };
460 alarm 30;
461 my $client = $socket->accept; # Wait for a client
462 alarm $prev_alarm;
228e5be9
TL
463 close($socket);
464
465 $infh = \*$client;
47f37b53 466 } else {
9559a62a 467 sysopen($infh, $filename, O_RDONLY)
47f37b53
WB
468 or die "open($filename): $!\n";
469 }
470
471 my $cfg = PVE::Storage::config();
52595938
WB
472 my $volume = $param->{volume};
473 my $delete = $param->{'delete-snapshot'};
a97d3ee4 474 my $imported_volid = PVE::Storage::volume_import($cfg, $infh, $volume, $param->{format},
3cc29a04
WB
475 $param->{snapshot}, $param->{base}, $param->{'with-snapshots'},
476 $param->{'allow-rename'});
a97d3ee4 477 PVE::Storage::volume_snapshot_delete($cfg, $imported_volid, $delete)
52595938 478 if defined($delete);
a97d3ee4 479 return $imported_volid;
47f37b53
WB
480 }
481});
482
25a95836
FE
483__PACKAGE__->register_method ({
484 name => 'prunebackups',
485 path => 'prunebackups',
486 method => 'GET',
8ca00a63
FE
487 description => "Prune backups. Only those using the standard naming scheme are considered. " .
488 "If no keep options are specified, those from the storage configuration are used.",
25a95836
FE
489 protected => 1,
490 proxyto => 'node',
491 parameters => {
492 additionalProperties => 0,
493 properties => {
494 'dry-run' => {
495 description => "Only show what would be pruned, don't delete anything.",
496 type => 'boolean',
497 optional => 1,
498 },
499 node => get_standard_option('pve-node'),
500 storage => get_standard_option('pve-storage-id', {
501 completion => \&PVE::Storage::complete_storage_enabled,
502 }),
a0933d7e 503 %{$PVE::Storage::Plugin::prune_backups_format},
25a95836
FE
504 type => {
505 description => "Either 'qemu' or 'lxc'. Only consider backups for guests of this type.",
506 type => 'string',
507 optional => 1,
508 enum => ['qemu', 'lxc'],
509 },
510 vmid => get_standard_option('pve-vmid', {
511 description => "Only consider backups for this guest.",
512 optional => 1,
513 completion => \&PVE::Cluster::complete_vmid,
514 }),
515 },
516 },
517 returns => {
518 type => 'object',
519 properties => {
520 dryrun => {
521 description => 'If it was a dry run or not. The list will only be defined in that case.',
522 type => 'boolean',
523 },
524 list => {
525 type => 'array',
526 items => {
527 type => 'object',
528 properties => {
529 volid => {
530 description => "Backup volume ID.",
531 type => 'string',
532 },
533 'ctime' => {
534 description => "Creation time of the backup (seconds since the UNIX epoch).",
535 type => 'integer',
536 },
537 'mark' => {
538 description => "Whether the backup would be kept or removed. For backups that don't " .
539 "use the standard naming scheme, it's 'protected'.",
540 type => 'string',
541 },
542 type => {
543 description => "One of 'qemu', 'lxc', 'openvz' or 'unknown'.",
544 type => 'string',
545 },
546 'vmid' => {
547 description => "The VM the backup belongs to.",
548 type => 'integer',
549 optional => 1,
550 },
551 },
552 },
553 },
554 },
555 },
556 code => sub {
557 my ($param) = @_;
558
559 my $dryrun = extract_param($param, 'dry-run') ? 1 : 0;
560
a0933d7e
FE
561 my $keep_opts;
562 foreach my $keep (keys %{$PVE::Storage::Plugin::prune_backups_format}) {
563 $keep_opts->{$keep} = extract_param($param, $keep) if defined($param->{$keep});
564 }
565 $param->{'prune-backups'} = PVE::JSONSchema::print_property_string(
566 $keep_opts, $PVE::Storage::Plugin::prune_backups_format) if $keep_opts;
567
25a95836
FE
568 my $list = [];
569 if ($dryrun) {
570 $list = PVE::API2::Storage::PruneBackups->dryrun($param);
571 } else {
572 PVE::API2::Storage::PruneBackups->delete($param);
573 }
574
575 return {
576 dryrun => $dryrun,
577 list => $list,
578 };
579 }});
580
39fc0c77
TL
581my $print_api_result = sub {
582 my ($data, $schema, $options) = @_;
583 PVE::CLIFormatter::print_api_result($data, $schema, undef, $options);
584};
585
c669f42d
DM
586our $cmddef = {
587 add => [ "PVE::API2::Storage::Config", 'create', ['type', 'storage'] ],
588 set => [ "PVE::API2::Storage::Config", 'update', ['storage'] ],
589 remove => [ "PVE::API2::Storage::Config", 'delete', ['storage'] ],
590 status => [ "PVE::API2::Storage::Status", 'index', [],
591 { node => $nodename }, $print_status ],
592 list => [ "PVE::API2::Storage::Content", 'index', ['storage'],
593 { node => $nodename }, $print_content ],
594 alloc => [ "PVE::API2::Storage::Content", 'create', ['storage', 'vmid', 'filename', 'size'],
595 { node => $nodename }, sub {
596 my $volid = shift;
e967e0ef 597 print "successfully created '$volid'\n";
c669f42d
DM
598 }],
599 free => [ "PVE::API2::Storage::Content", 'delete', ['volume'],
600 { node => $nodename } ],
957321a8 601 scan => {
2892b673 602 nfs => [ "PVE::API2::Storage::Scan", 'nfsscan', ['server'], { node => $nodename }, sub {
957321a8
TL
603 my $res = shift;
604
605 my $maxlen = 0;
606 foreach my $rec (@$res) {
607 my $len = length ($rec->{path});
608 $maxlen = $len if $len > $maxlen;
609 }
610 foreach my $rec (@$res) {
611 printf "%-${maxlen}s %s\n", $rec->{path}, $rec->{options};
612 }
613 }],
2892b673 614 cifs => [ "PVE::API2::Storage::Scan", 'cifsscan', ['server'], { node => $nodename }, sub {
957321a8
TL
615 my $res = shift;
616
617 my $maxlen = 0;
618 foreach my $rec (@$res) {
619 my $len = length ($rec->{share});
620 $maxlen = $len if $len > $maxlen;
621 }
622 foreach my $rec (@$res) {
623 printf "%-${maxlen}s %s\n", $rec->{share}, $rec->{description};
624 }
625 }],
2892b673 626 glusterfs => [ "PVE::API2::Storage::Scan", 'glusterfsscan', ['server'], { node => $nodename }, sub {
957321a8
TL
627 my $res = shift;
628
629 foreach my $rec (@$res) {
630 printf "%s\n", $rec->{volname};
631 }
632 }],
2892b673 633 iscsi => [ "PVE::API2::Storage::Scan", 'iscsiscan', ['portal'], { node => $nodename }, sub {
957321a8
TL
634 my $res = shift;
635
636 my $maxlen = 0;
637 foreach my $rec (@$res) {
638 my $len = length ($rec->{target});
639 $maxlen = $len if $len > $maxlen;
640 }
641 foreach my $rec (@$res) {
642 printf "%-${maxlen}s %s\n", $rec->{target}, $rec->{portal};
643 }
644 }],
2892b673 645 lvm => [ "PVE::API2::Storage::Scan", 'lvmscan', [], { node => $nodename }, sub {
957321a8
TL
646 my $res = shift;
647 foreach my $rec (@$res) {
648 printf "$rec->{vg}\n";
649 }
650 }],
2892b673 651 lvmthin => [ "PVE::API2::Storage::Scan", 'lvmthinscan', ['vg'], { node => $nodename }, sub {
957321a8
TL
652 my $res = shift;
653 foreach my $rec (@$res) {
654 printf "$rec->{lv}\n";
655 }
656 }],
39fc0c77
TL
657 pbs => [
658 "PVE::API2::Storage::Scan",
659 'pbsscan',
660 ['server', 'username'],
661 { node => $nodename },
662 $print_api_result,
663 $PVE::RESTHandler::standard_output_options,
664 ],
2892b673 665 zfs => [ "PVE::API2::Storage::Scan", 'zfsscan', [], { node => $nodename }, sub {
957321a8
TL
666 my $res = shift;
667
668 foreach my $rec (@$res) {
669 printf "$rec->{pool}\n";
670 }
671 }],
672 },
673 nfsscan => { alias => 'scan nfs' },
674 cifsscan => { alias => 'scan cifs' },
675 glusterfsscan => { alias => 'scan glusterfs' },
676 iscsiscan => { alias => 'scan iscsi' },
677 lvmscan => { alias => 'scan lvm' },
678 lvmthinscan => { alias => 'scan lvmthin' },
679 zfsscan => { alias => 'scan zfs' },
c669f42d 680 path => [ __PACKAGE__, 'path', ['volume']],
fa017b96 681 extractconfig => [__PACKAGE__, 'extractconfig', ['volume']],
47f37b53 682 export => [ __PACKAGE__, 'export', ['volume', 'format', 'filename']],
a97d3ee4
FE
683 import => [ __PACKAGE__, 'import', ['volume', 'format', 'filename'], {}, sub {
684 my $volid = shift;
685 print PVE::Storage::volume_imported_message($volid);
686 }],
5f184292
FE
687 apiinfo => [ __PACKAGE__, 'apiinfo', [], {}, sub {
688 my $res = shift;
689
690 print "APIVER $res->{apiver}\n";
691 print "APIAGE $res->{apiage}\n";
692 }],
25a95836
FE
693 'prune-backups' => [ __PACKAGE__, 'prunebackups', ['storage'], { node => $nodename }, sub {
694 my $res = shift;
695
696 my ($dryrun, $list) = ($res->{dryrun}, $res->{list});
697
698 return if !$dryrun;
699
c3e87d0f
FE
700 if (!scalar(@{$list})) {
701 print "No backups found\n";
702 return;
703 }
704
7b73d327
FE
705 print "NOTE: this is only a preview and might not be what a subsequent\n" .
706 "prune call does if backups are removed/added in the meantime.\n\n";
25a95836
FE
707
708 my @sorted = sort {
709 my $vmcmp = PVE::Tools::safe_compare($a->{vmid}, $b->{vmid}, sub { $_[0] <=> $_[1] });
710 return $vmcmp if $vmcmp ne 0;
711 return $a->{ctime} <=> $b->{ctime};
712 } @{$list};
713
714 my $maxlen = 0;
715 foreach my $backup (@sorted) {
716 my $volid = $backup->{volid};
717 $maxlen = length($volid) if length($volid) > $maxlen;
718 }
719 $maxlen+=1;
720
721 printf("%-${maxlen}s %15s %10s\n", 'Backup', 'Backup-ID', 'Prune-Mark');
722 foreach my $backup (@sorted) {
723 my $type = $backup->{type};
724 my $vmid = $backup->{vmid};
725 my $backup_id = defined($vmid) ? "$type/$vmid" : "$type";
726 printf("%-${maxlen}s %15s %10s\n", $backup->{volid}, $backup_id, $backup->{mark});
727 }
728 }],
c669f42d
DM
729};
730
7311;