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