2011-08-23 09:47:04 +04:00
#!/usr/bin/perl -w
use strict;
2011-10-17 15:49:48 +04:00
use PVE::SafeSyslog;
use PVE::Tools qw(extract_param);
use PVE::INotify;
use PVE::RPCEnvironment;
use PVE::CLIHandler;
use PVE::JSONSchema qw(get_standard_option);
use PVE::API2::Qemu;
use Data::Dumper; # fixme: remove
use base qw(PVE::CLIHandler);
$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
initlog('qmrestore');
die "please run as root\n" if $> != 0;
PVE::INotify::inotify_init();
my $rpcenv = PVE::RPCEnvironment->init('cli');
$rpcenv->init_request();
$rpcenv->set_language($ENV{LANG});
$rpcenv->set_user('root@pam');
__PACKAGE__->register_method({
name => 'qmrestore',
path => 'qmrestore',
method => 'POST',
description => "Restore QemuServer vzdump backups.",
parameters => {
additionalProperties => 0,
properties => {
vmid => get_standard_option('pve-vmid'),
archive => {
2011-10-19 13:31:06 +04:00
description => "The backup file. You can pass '-' to read from standard input.",
2011-10-17 15:49:48 +04:00
type => 'string',
maxLength => 255,
},
storage => get_standard_option('pve-storage-id', {
description => "Default storage.",
optional => 1,
}),
force => {
optional => 1,
type => 'boolean',
description => "Allow to overwrite existing VM.",
},
2011-10-18 11:14:05 +04:00
unique => {
optional => 1,
type => 'boolean',
description => "Assign a unique random ethernet address.",
},
2012-02-02 09:39:38 +04:00
pool => {
optional => 1,
type => 'string', format => 'pve-poolid',
description => "Add the VM to the specified pool.",
},
2011-10-17 15:49:48 +04:00
},
},
returns => {
type => 'string',
},
code => sub {
my ($param) = @_;
$param->{node} = PVE::INotify::nodename();
return PVE::API2::Qemu->create_vm($param);
}});
my $cmddef = [ __PACKAGE__, 'qmrestore', ['archive', 'vmid'], undef,
sub {
my $upid = shift;
my $status = PVE::Tools::upid_read_status($upid);
exit($status eq 'OK' ? 0 : -1);
}];
push @ARGV, 'help' if !scalar(@ARGV);
PVE::CLIHandler::handle_simple_cmd($cmddef, \@ARGV, undef, $0);
exit 0;
2011-08-23 09:47:04 +04:00
__END__
=head1 NAME
2011-10-17 15:49:48 +04:00
2011-08-23 09:47:04 +04:00
qmrestore - restore QemuServer vzdump backups
=head1 SYNOPSIS
2011-10-17 15:49:48 +04:00
=include synopsis
2011-08-23 09:47:04 +04:00
=head1 DESCRIPTION
2011-10-17 15:49:48 +04:00
Restore the QemuServer vzdump backup C<archive> to virtual machine
C<vmid>. Volumes are allocated on the original storage if there is no
C<storage> specified.
2011-08-23 09:47:04 +04:00
=head1 SEE ALSO
2011-10-17 15:49:48 +04:00
vzdump(1) vzrestore(1)
=include pve_copyright