[pve-devel] r5293 - qemu-server/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Oct 29 11:35:26 CEST 2010


Author: dietmar
Date: 2010-10-29 09:35:26 +0000 (Fri, 29 Oct 2010)
New Revision: 5293

Modified:
   qemu-server/trunk/ChangeLog
   qemu-server/trunk/Makefile
   qemu-server/trunk/changelog.Debian
   qemu-server/trunk/qmrestore
Log:


Modified: qemu-server/trunk/ChangeLog
===================================================================
--- qemu-server/trunk/ChangeLog	2010-10-28 10:39:20 UTC (rev 5292)
+++ qemu-server/trunk/ChangeLog	2010-10-29 09:35:26 UTC (rev 5293)
@@ -1,3 +1,8 @@
+2010-10-28  Seth Lauzon <seth.lauzon at gmail.com>
+
+	* qmrestore (restore_qemu): new option --repeat (repeat the restoration
+	process and increment the VMID automatically and skipping existing VMIDs)
+
 2010-10-28  Proxmox Support Team  <support at proxmox.com>
 
 	* QemuServer.pm (config_to_command): generate unique interface

Modified: qemu-server/trunk/Makefile
===================================================================
--- qemu-server/trunk/Makefile	2010-10-28 10:39:20 UTC (rev 5292)
+++ qemu-server/trunk/Makefile	2010-10-29 09:35:26 UTC (rev 5293)
@@ -2,7 +2,7 @@
 
 VERSION=1.1
 PACKAGE=qemu-server
-PKGREL=24
+PKGREL=25
 
 DESTDIR=
 PREFIX=/usr

Modified: qemu-server/trunk/changelog.Debian
===================================================================
--- qemu-server/trunk/changelog.Debian	2010-10-28 10:39:20 UTC (rev 5292)
+++ qemu-server/trunk/changelog.Debian	2010-10-29 09:35:26 UTC (rev 5293)
@@ -1,3 +1,9 @@
+qemu-server (1.1-25) unstable; urgency=low
+
+  * new --repeat option for qmrestore
+
+ -- Proxmox Support Team <support at proxmox.com>  Fri, 29 Oct 2010 11:33:30 +0200
+
 qemu-server (1.1-24) unstable; urgency=low
 
   * fix new -netdev syntax when used with multiple network devices.

Modified: qemu-server/trunk/qmrestore
===================================================================
--- qemu-server/trunk/qmrestore	2010-10-28 10:39:20 UTC (rev 5292)
+++ qemu-server/trunk/qmrestore	2010-10-29 09:35:26 UTC (rev 5293)
@@ -32,7 +32,7 @@
 
 openlog ('vzdump', 'cons,pid', 'daemon');
 
-my @std_opts = ('extract', 'storage=s', 'info', 'prealloc', 'unique');
+my @std_opts = ('extract', 'storage=s', 'info', 'prealloc', 'unique', 'repeat=i');
 
 sub print_usage {
     my $msg = shift;
@@ -64,17 +64,15 @@
     return $str;
 }
 
-my $quoted_cmd = shellquote ($0);
-foreach my $arg (@ARGV) {
-    $quoted_cmd .= " " . shellquote ($arg);
-}
-
 my $opts = {};
 if (!GetOptions ($opts, @std_opts)) {
     print_usage ();
     exit (-1);
 }
 
+die "you can't use --info and --repeat together\n" 
+    if $opts->{info} && $opts->{repeat};
+
 if ($#ARGV != 1) {
     print_usage ();
     exit (-1);
@@ -83,6 +81,14 @@
 my $archive = shift;
 my $vmid = PVE::VZDump::check_vmids ((shift))->[0];
 
+my $quoted_cmd = shellquote ($0);
+foreach my $o (keys %$opts) {
+    next if $o eq 'extract' || $o eq 'repeat';
+    $quoted_cmd .= " --$o";
+    $quoted_cmd .= " " . shellquote($opts->{$o}) if $o eq 'storage'; 
+}
+$quoted_cmd .= " " .  shellquote($archive);
+
 $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = $SIG{PIPE} = sub {
     die "interrupted by signal\n";
 };
@@ -259,7 +265,7 @@
 
     local $ENV{VZDUMP_TMPDIR} = $tmpdir;
  
-    my $subcmd = shellquote ("--to-command=${quoted_cmd}\ --extract");
+    my $subcmd = shellquote ("--to-command=${quoted_cmd}\ --extract\ $vmid");
     my $cmd = "tar xf '$archive' $subcmd";
     run_command ($cmd);
 
@@ -336,55 +342,74 @@
     die "ERROR: file '$archive' dos not lock like a QemuServer vzdump backup\n";
 }
 
-my $tmpdir = "/var/tmp/vzdumptmp$$";
+sub restore_archive {
+    my ($vmid) = @_;
 
-PVE::QemuServer::lock_config ($vmid, sub {
+    my $tmpdir = "/var/tmp/vzdumptmp$$";
 
-    my $conffile = PVE::QemuServer::config_file ($vmid);
+    my $restoresub = sub {
 
-    die "unable to restore VM '$vmid' - VM already exists\n"
-	if -f $conffile;
+	my $conffile = PVE::QemuServer::config_file($vmid);
 
-    mkpath $tmpdir;
+	die "unable to restore VM '$vmid' - VM already exists\n"
+	    if -f $conffile;
 
-    eval {
-	debugmsg ('info', "restore QemuServer backup '$archive' " .
-		  "using ID $vmid", undef, 1) if !$opts->{info};
+	mkpath $tmpdir;
 
-	restore_qemu ($archive, $vmid, $tmpdir);
+	eval {
+	    debugmsg ('info', "restore QemuServer backup '$archive' " .
+		      "using ID $vmid", undef, 1) if !$opts->{info};
 
-	if ($opts->{info}) {
-	    debugmsg ('info', "reading '$archive' successful");
-	} else {
-	    debugmsg ('info', "restore QemuServer backup '$archive' successful", 
-		      undef, 1);
+	    restore_qemu ($archive, $vmid, $tmpdir);
+
+	    if ($opts->{info}) {
+		debugmsg ('info', "reading '$archive' successful");
+	    } else {
+		debugmsg ('info', "restore QemuServer backup '$archive' successful", 
+			  undef, 1);
+	    }
+	};
+	my $err = $@;
+
+	if ($err) {
+	    local $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = sub {
+		debugmsg ('info', "got interrupt - ignored (cleanup phase)");
+	    };
+	    
+	    restore_cleanup ("$tmpdir/qmrestore.stat") if $err;
 	}
+
+	die $err if $err;
     };
+
+    PVE::QemuServer::lock_config ($vmid, $restoresub);
     my $err = $@;
 
-    if ($err) {
-	local $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = sub {
-	    debugmsg ('info', "got interrupt - ignored (cleanup phase)");
-	};
+    rmtree $tmpdir;
 
-	restore_cleanup ("$tmpdir/qmrestore.stat") if $err;
-    }
-
     die $err if $err;
-});
+}
 
+eval {
+    if ($opts->{info} || !$opts->{repeat}) {
+	restore_archive($vmid);
+    } else {
+	do {
+	    restore_archive($vmid);
+	    $vmid++;
+	    $opts->{repeat}--;
+	} while ($opts->{repeat} > 0);
+    }
+};
 my $err = $@;
 
-rmtree $tmpdir;
-
 if ($err) {
     if ($opts->{info}) {
 	debugmsg ('info', "reading '$archive' failed - $err");
     } else {
-
 	debugmsg ('err', "restore QemuServer backup '$archive' failed - $err", 
 		  undef, 1);
-    }
+	}
     exit (-1);
 }
 
@@ -409,6 +434,10 @@
 
  --prealloc                never generate sparse files
 
+ --repeat <number>         repeat the restoration process with
+                           VMID numbers incremented per run
+
+
 =head1 DESCRIPTION
 
 Restore the QemuServer vzdump backup <archive> to virtual machine




More information about the pve-devel mailing list