[pve-devel] r5333 - vzdump/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Dec 6 10:41:10 CET 2010


Author: dietmar
Date: 2010-12-06 10:41:10 +0100 (Mon, 06 Dec 2010)
New Revision: 5333

Modified:
   vzdump/trunk/ChangeLog
   vzdump/trunk/OpenVZ.pm
   vzdump/trunk/Plugin.pm
   vzdump/trunk/VZDump.pm
   vzdump/trunk/vzrestore
Log:


Modified: vzdump/trunk/ChangeLog
===================================================================
--- vzdump/trunk/ChangeLog	2010-12-06 06:27:03 UTC (rev 5332)
+++ vzdump/trunk/ChangeLog	2010-12-06 09:41:10 UTC (rev 5333)
@@ -1,7 +1,11 @@
 2010-12-06  Proxmox Support Team  <support at proxmox.com>
 
+	* vzrestore (restore_openvz): allow restore from STDIN ('-')
+
 	* VZDump.pm (debugmsg): never print to STDOUT (use STDERR instead)
-	(run_command): allow to pass GLOB/IO:File references for $input
+	(run_command): new syntax, use %param hash
+	(run_command): allow to pass "<&XXX" for $input
+	(run_command): allow to specify $output ">&=N" 
 
 	* vzdump (print_usage): add new --stdout option (make sure that
 	nobody writes STDOUT by redirectind STDOUT to STDERR (saving old

Modified: vzdump/trunk/OpenVZ.pm
===================================================================
--- vzdump/trunk/OpenVZ.pm	2010-12-06 06:27:03 UTC (rev 5332)
+++ vzdump/trunk/OpenVZ.pm	2010-12-06 09:41:10 UTC (rev 5333)
@@ -355,16 +355,22 @@
 	$taropts .= " --remove-files"; # try to save space
     }
 
-    my $out = ">$filename";
+    my $cmd = "(";
+    $cmd .= "cd $snapdir;find . $findargs|sed 's/\\\\/\\\\\\\\/g'|";
+    $cmd .= "tar c${zflag}pf - $taropts --null -T -";
 
     if ($opts->{bwlimit}) {
 	my $bwl = $opts->{bwlimit}*1024; # bandwidth limit for cstream
-	$out = "|cstream -t $bwl $out";
+	$cmd .= "|cstream -t $bwl";
     }
 
-    $self->cmd ("(cd $snapdir;find . $findargs|sed 's/\\\\/\\\\\\\\/g'|" .
-		"tar c${zflag}pf - $taropts --null -T - $out )");
+    $cmd .= ")";
 
+    if ($opts->{stdout}) {
+	$self->cmd ($cmd, output => ">&=" . fileno($opts->{stdout}));
+    } else {
+	$self->cmd ("$cmd >$filename");
+    }
 }
 
 sub cleanup {

Modified: vzdump/trunk/Plugin.pm
===================================================================
--- vzdump/trunk/Plugin.pm	2010-12-06 06:27:03 UTC (rev 5332)
+++ vzdump/trunk/Plugin.pm	2010-12-06 09:41:10 UTC (rev 5333)
@@ -30,16 +30,16 @@
 }
 
 sub cmd {
-    my ($self, $cmdstr, $input) = @_;
+    my ($self, $cmdstr, %param) = @_;
 
-    return PVE::VZDump::run_command ($self->{logfd}, $cmdstr, $input);   
+    return PVE::VZDump::run_command($self->{logfd}, $cmdstr, %param);   
 }
 
 sub cmd_noerr {
-    my ($self, $cmdstr, $input) = @_;
+    my ($self, $cmdstr, %param) = @_;
 
     my $res;
-    eval { $res = $self->cmd ($cmdstr, $input); };
+    eval { $res = $self->cmd($cmdstr, %param); };
     $self->logerr ($@) if $@;
     return $res;
 }

Modified: vzdump/trunk/VZDump.pm
===================================================================
--- vzdump/trunk/VZDump.pm	2010-12-06 06:27:03 UTC (rev 5332)
+++ vzdump/trunk/VZDump.pm	2010-12-06 09:41:10 UTC (rev 5333)
@@ -82,12 +82,26 @@
 }
 
 sub run_command {
-    my ($logfd, $cmdstr, $input, $timeout) = @_;
+    my ($logfd, $cmdstr, %param) = @_;
 
-    $input = '' if !defined($input);
+    my $timeout;
+    my $input;
+    my $output;
 
-    my $reader = IO::File->new();
-    my $writer = ref($input) ? $input : IO::File->new();
+    foreach my $p (keys %param) {
+	if ($p eq 'timeout') {
+	    $timeout = $param{$p};
+	} elsif ($p eq 'input') {
+	    $input = $param{$p};
+	} elsif ($p eq 'output') {
+	    $output = $param{$p};
+	} else {
+	    die "got unknown parameter '$p' for run_command\n";
+	}
+    }
+
+    my $reader = $output && $output =~ m/^>&/ ? $output : IO::File->new();
+    my $writer = $input && $input =~ m/^<&/ ? $input : IO::File->new();
     my $error  = IO::File->new();
 
     my $orig_pid = $$;
@@ -104,20 +118,20 @@
 
     # catch exec errors
     if ($orig_pid != $$) {
-	debugmsg ('err', "command '$cmdstr' failed - fork failed", $logfd);
+	debugmsg ('err', "command '$cmdstr' failed - fork failed: $!", $logfd);
 	POSIX::_exit (1); 
 	kill ('KILL', $$); 
     }
 
     die $err if $err;
 
-    if (!ref($input)) {
+    if (ref($writer)) {
 	print $writer $input if defined $input;
 	close $writer;
     }
 
     my $select = new IO::Select;
-    $select->add ($reader);
+    $select->add ($reader) if ref($reader);
     $select->add ($error);
 
     my ($ostream, $estream, $logout, $logerr) = ('', '', '', '');
@@ -784,15 +798,18 @@
 	my $logfile = $task->{logfile} = "$opts->{dumpdir}/$basename.log";
 
 	my $ext = $opts->{compress} ? '.tgz' : '.tar';
-	my $tarfile = $task->{tarfile} = "$opts->{dumpdir}/$basename$ext";
 
-	$task->{tmptar} = $task->{tarfile};
-	$task->{tmptar} =~ s/\.[^\.]+$/\.dat/;
+	if ($opts->{stdout}) {
+	    $task->{tarfile} = '-';
+	} else {
+	    my $tarfile = $task->{tarfile} = "$opts->{dumpdir}/$basename$ext";
+	    $task->{tmptar} = $task->{tarfile};
+	    $task->{tmptar} =~ s/\.[^\.]+$/\.dat/;
+	    unlink $task->{tmptar};
+	}
 
 	$task->{vmtype} = $vmtype;
 
-	unlink $task->{tmptar};
-
 	if ($opts->{tmpdir}) {
 	    $task->{tmpdir} = "$opts->{tmpdir}/vzdumptmp$$"; 
 	} else {
@@ -938,6 +955,14 @@
 	$plugin->assemble ($task, $vmid);
 	
 	# produce archive 
+
+	if ($opts->{stdout}) {
+	    debugmsg ('info', "sending archive to stdout", $logfd);
+	    $plugin->archive ($task, $vmid, $task->{tmptar});
+	    $self->run_hook_script ('backup-end', $task, $logfd);
+	    return;
+	}
+
 	debugmsg ('info', "creating archive '$task->{tarfile}'", $logfd);
 	$plugin->archive ($task, $vmid, $task->{tmptar});
 

Modified: vzdump/trunk/vzrestore
===================================================================
--- vzdump/trunk/vzrestore	2010-12-06 06:27:03 UTC (rev 5332)
+++ vzdump/trunk/vzrestore	2010-12-06 09:41:10 UTC (rev 5333)
@@ -96,10 +96,14 @@
 
 	my $cmd = "tar xpf $archive --totals --sparse -C $private";
 
-	debugmsg ('info', "extracting archive '$archive'");
+	if ($archive eq '-') {
+	    debugmsg ('info', "extracting archive from STDIN");
+	    run_command ($cmd, input => "<&STDIN");
+	} else {
+	    debugmsg ('info', "extracting archive '$archive'");
+	    run_command ($cmd);
+	}
 
-	run_command ($cmd);
-
 	debugmsg ('info', "extracting configuration to '$conffile'");
 
 	my $qroot = $vzconf->{rootdir};
@@ -134,9 +138,11 @@
 
 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";
+if ($archive ne '-') {
+    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);




More information about the pve-devel mailing list