]>
Commit | Line | Data |
---|---|---|
1e3baf05 | 1 | #!/usr/bin/perl -w |
1e3baf05 DM |
2 | |
3 | use strict; | |
3e16d5fc DM |
4 | use PVE::SafeSyslog; |
5 | use PVE::Tools qw(extract_param); | |
6 | use PVE::INotify; | |
7 | use PVE::RPCEnvironment; | |
8 | use PVE::CLIHandler; | |
9 | use PVE::JSONSchema qw(get_standard_option); | |
10 | use PVE::API2::Qemu; | |
11 | ||
12 | use Data::Dumper; # fixme: remove | |
13 | ||
14 | use base qw(PVE::CLIHandler); | |
15 | ||
16 | $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin'; | |
17 | ||
18 | initlog('qmrestore'); | |
19 | ||
20 | die "please run as root\n" if $> != 0; | |
21 | ||
22 | PVE::INotify::inotify_init(); | |
23 | ||
24 | my $rpcenv = PVE::RPCEnvironment->init('cli'); | |
25 | ||
26 | $rpcenv->init_request(); | |
27 | $rpcenv->set_language($ENV{LANG}); | |
28 | $rpcenv->set_user('root@pam'); | |
29 | ||
30 | __PACKAGE__->register_method({ | |
31 | name => 'qmrestore', | |
32 | path => 'qmrestore', | |
33 | method => 'POST', | |
34 | description => "Restore QemuServer vzdump backups.", | |
35 | parameters => { | |
36 | additionalProperties => 0, | |
37 | properties => { | |
38 | vmid => get_standard_option('pve-vmid'), | |
39 | archive => { | |
40 | description => "The backup file.", | |
41 | type => 'string', | |
42 | maxLength => 255, | |
43 | }, | |
44 | storage => get_standard_option('pve-storage-id', { | |
45 | description => "Default storage.", | |
46 | optional => 1, | |
47 | }), | |
48 | force => { | |
49 | optional => 1, | |
50 | type => 'boolean', | |
51 | description => "Allow to overwrite existing VM.", | |
52 | }, | |
53 | }, | |
54 | }, | |
55 | returns => { | |
56 | type => 'string', | |
57 | }, | |
58 | code => sub { | |
59 | my ($param) = @_; | |
60 | ||
61 | $param->{node} = PVE::INotify::nodename(); | |
62 | ||
63 | return PVE::API2::Qemu->create_vm($param); | |
64 | }}); | |
65 | ||
66 | my $cmddef = [ __PACKAGE__, 'qmrestore', ['archive', 'vmid'], undef, | |
67 | sub { | |
68 | my $upid = shift; | |
69 | my $status = PVE::Tools::upid_read_status($upid); | |
70 | exit($status eq 'OK' ? 0 : -1); | |
71 | }]; | |
72 | ||
73 | push @ARGV, 'help' if !scalar(@ARGV); | |
74 | ||
75 | PVE::CLIHandler::handle_simple_cmd($cmddef, \@ARGV, undef, $0); | |
76 | ||
77 | exit 0; | |
1e3baf05 DM |
78 | |
79 | __END__ | |
80 | ||
81 | =head1 NAME | |
3e16d5fc | 82 | |
1e3baf05 DM |
83 | qmrestore - restore QemuServer vzdump backups |
84 | ||
85 | =head1 SYNOPSIS | |
86 | ||
3e16d5fc | 87 | =include synopsis |
1e3baf05 DM |
88 | |
89 | =head1 DESCRIPTION | |
90 | ||
3e16d5fc DM |
91 | Restore the QemuServer vzdump backup C<archive> to virtual machine |
92 | C<vmid>. Volumes are allocated on the original storage if there is no | |
93 | C<storage> specified. | |
1e3baf05 DM |
94 | |
95 | =head1 SEE ALSO | |
96 | ||
3e16d5fc DM |
97 | vzdump(1) vzrestore(1) |
98 | ||
99 | =include pve_copyright |