]> git.proxmox.com Git - pve-manager.git/blob - bin/vzrestore
ba85f2bc948827674ae2a735fd3e95e72391fff6
[pve-manager.git] / bin / vzrestore
1 #!/usr/bin/perl -w
2
3 use strict;
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::OpenVZ;
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('vzrestore');
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 => 'vzrestore',
32 path => 'vzrestore',
33 method => 'POST',
34 description => "Restore OpenVZ containers.",
35 parameters => {
36 additionalProperties => 0,
37 properties => {
38 vmid => get_standard_option('pve-vmid'),
39 archive => {
40 description => "The backup file. You can pass '-' to read from standard input.",
41 type => 'string',
42 maxLength => 255,
43 },
44 storage => get_standard_option('pve-storage-id', {
45 description => "Target storage.",
46 default => 'local',
47 optional => 1,
48 }),
49 force => {
50 optional => 1,
51 type => 'boolean',
52 description => "Allow to overwrite existing container.",
53 },
54 },
55 },
56 returns => {
57 type => 'string',
58 },
59 code => sub {
60 my ($param) = @_;
61
62 $param->{ostemplate} = extract_param($param, 'archive');
63
64 $param->{node} = PVE::INotify::nodename();
65
66 $param->{restore} = 1;
67
68 return PVE::API2::OpenVZ->create_vm($param);
69 }});
70
71 my $cmddef = [ __PACKAGE__, 'vzrestore', ['archive', 'vmid'], undef,
72 sub {
73 my $upid = shift;
74 my $status = PVE::Tools::upid_read_status($upid);
75 exit($status eq 'OK' ? 0 : -1);
76 }];
77
78 push @ARGV, 'help' if !scalar(@ARGV);
79
80 PVE::CLIHandler::handle_simple_cmd($cmddef, \@ARGV, undef, $0);
81
82 exit 0;
83
84 __END__
85
86 =head1 NAME
87
88 vzrestore - restore OpenVZ vzdump backups
89
90 =head1 SYNOPSIS
91
92 =include synopsis
93
94 =head1 DESCRIPTION
95
96 Restores OpenVZ vzdump backups.
97
98 =head1 SEE ALSO
99
100 vzdump(1) qmrestore(1)
101
102 =include pve_copyright