This file is indexed.

/usr/sbin/vzrestore is in vzdump 1.2.6-3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/perl -w
#
#    Copyright (C) 2007-2009 Proxmox Server Solutions GmbH
#
#    Copyright: vzdump is under GNU GPL, the GNU General Public License.
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; version 2 dated June, 1991.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the
#    Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
#    MA 02110-1301, USA.
#
#    Author: Dietmar Maurer <dietmar@proxmox.com>
#

use strict;
use Getopt::Long;
use Sys::Syslog;
use File::Path;
use PVE::VZDump;
use PVE::VZDump::OpenVZ;

$ENV{LANG} = "C"; # avoid locale related issues/warnings

openlog ('vzdump', 'cons,pid', 'daemon');

my $force = 0;

sub print_usage {
    my $msg = shift;

    print STDERR "ERROR: $msg\n\n" if $msg;

    print STDERR "usage: $0 [OPTIONS] <ARCHIVE> <VMID>\n";
    print STDERR "\n";
    print STDERR "\t--force      overwrite existing conf file, private and root directory\n\n";
}

if (!GetOptions ('force' => \$force)) {
    print_usage ();
    exit (-1);
}

if ($#ARGV != 1) {
    print_usage ();
    exit (-1);
} 

my $archive = shift;
my $vmid = PVE::VZDump::check_vmids ((shift))->[0];

$SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = $SIG{PIPE} = sub {
    die "interrupted by signal\n";
};

sub debugmsg { PVE::VZDump::debugmsg (@_); } # just a shortcut

sub run_command { PVE::VZDump::run_command (undef, @_); } # just a shortcut

sub restore_openvz {
    my ($archive, $vmid) = @_;

    my $vzconf =  PVE::VZDump::OpenVZ::read_global_vz_config ();
    my $cfgdir = PVE::VZDump::OpenVZ::VZDIR . "/conf";

    my $conffile = "$cfgdir/${vmid}.conf";
    my $private = $vzconf->{privatedir};
    $private =~ s/\$VEID/$vmid/;
    my $root = $vzconf->{rootdir};
    $root =~ s/\$VEID/$vmid/;

    print "you choose to force overwriting VPS config file, private and root directories.\n" if $force;

    die "unable to restore VM '$vmid' - VM already exists\n"
	if !$force && -f $conffile;              ;
 
    die "unable to restore VPS '${vmid}' - " .
    	"directory '$private' already exists\n"
	if !$force && -d $private;
   
    die "unable to restore VPS '${vmid}' - " .
	"directory '$root' already exists\n"
	if !$force && -d $root;

    eval {
	mkpath $private || die "unable to create private dir '$private'";
	mkpath $root || die "unable to create private dir '$private'";

	my $cmd = "tar xpf $archive --totals --sparse -C $private";

	debugmsg ('info', "extracting archive '$archive'");

	run_command ($cmd);

	debugmsg ('info', "extracting configuration to '$conffile'");

	my $qroot = $vzconf->{rootdir};
	$qroot =~ s|/|\\\/|g;
	my $qprivate = $vzconf->{privatedir};
	$qprivate =~ s|/|\\\/|g;

	my $scmd = "sed -e 's/VE_ROOT=.*/VE_ROOT=\\\"$qroot\\\"/' -e 's/VE_PRIVATE=.*/VE_PRIVATE=\\\"$qprivate\\\"/'  <'$private/etc/vzdump/vps.conf' >'$conffile'";

	run_command ($scmd);

	foreach my $s (PVE::VZDump::OpenVZ::SCRIPT_EXT) {
	    my $tfn = "$cfgdir/${vmid}.$s";
	    my $sfn = "$private/etc/vzdump/vps.$s";
	    if (-f $sfn) {
		run_command ("cp '$sfn' '$tfn'");
	    }
	}

	rmtree "$private/etc/vzdump";
    };

    my $err = $@;

    if ($err) {
	rmtree $private;
	rmtree $root;
	unlink $conffile;
	die $err;
    }
}

my $plugin = PVE::VZDump::OpenVZ->new();

my $firstfile = PVE::VZDump::read_firstfile ($archive);
if ($firstfile eq 'qemu-server.conf') {
    die "ERROR: please use 'qmrestore' to restore QemuServer VMs\n";
}

my $lock = $plugin->lock_vm ($vmid);

eval {
    debugmsg ('info', "restore openvz backup '$archive' using ID $vmid", undef, 1);
    restore_openvz ($archive, $vmid);
    debugmsg ('info', "restore openvz backup '$archive' successful", undef, 1);
};
my $err = $@;

$plugin->unlock_vm ($vmid);

if ($err) {
    debugmsg ('err', "restore openvz backup '$archive' failed - $err", undef, 1);
    exit (-1);
}

exit (0);

__END__

=head1 NAME
                                          
vzrestore - restore OpenVZ vzdump backups

=head1 SYNOPSIS

vzrestore <archive> <VMID>

=head1 DESCRIPTION

Restore the OpenVZ vzdump backup <archive> to virtual machine <VMID>.

=head1 SEE ALSO

    vzdump(1) qmrestore(1)