[pve-devel] [PATCH] Added differential backup.

Kamil Trzcinski ayufan at osk-net.pl
Wed Aug 15 02:51:41 CEST 2012


Signed-off-by: Kamil Trzcinski <ayufan at ayufan.eu>
---
 PVE/QemuServer.pm        |   27 ++++++++++++++++++++++++---
 PVE/VZDump/QemuServer.pm |    3 ++-
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index d3a710e..d9c8cf0 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3011,8 +3011,19 @@ sub archive_read_firstfile {
 
     die "ERROR: file '$archive' does not exist\n" if ! -f $archive;
 
+    my $cmd = undef;
+
+    if ($archive =~ m!([^/]*vzdump-([a-z]*)-(\d*)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?$!) {
+	my $fullbackup = $archive;
+	$fullbackup =~ s!([^/]*vzdump-([a-z]+)-(\d+)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?!$1!;
+	$cmd = "pve-xdelta3 -q -d -c -R -s '$fullbackup' '$archive' |tar t|";
+    }
+    else {
+	$cmd = "tar tf '$archive'|";
+    }
+
     # try to detect archive type first
-    my $pid = open (TMP, "tar tf '$archive'|") ||
+    my $pid = open (TMP, $cmd) ||
 	die "unable to open file '$archive'\n";
     my $firstfile = <TMP>;
     kill 15, $pid;
@@ -3069,8 +3080,18 @@ sub restore_archive {
 
     # tar option "xf" does not autodetect compression when read from STDIN,
     # so we pipe to zcat
-    my $cmd = "zcat -f|tar xf " . PVE::Tools::shellquote($archive) . " " .
-	PVE::Tools::shellquote("--to-command=$tocmd");
+    my $cmd = undef;
+
+    if ($archive =~ m!([^/]*vzdump-([a-z]*)-(\d*)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?$!) {
+	my $fullbackup = $archive;
+	$fullbackup =~ s!([^/]*vzdump-([a-z]+)-(\d+)-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?)))--differential-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.vcdiff(\.(gz|lzo))?!$1!;
+	print "extracting from differential archive, using full backup '$fullbackup'\n";
+	$cmd = "pve-xdelta3 -q -d -c -R -s '$fullbackup' '$archive' |tar x " . PVE::Tools::shellquote("--to-command=$tocmd");
+    }
+    else {
+	$cmd = "zcat -f|tar xf " . PVE::Tools::shellquote($archive) . " " .
+		PVE::Tools::shellquote("--to-command=$tocmd");
+    }
 
     my $tmpdir = "/var/tmp/vzdumptmp$$";
     mkpath $tmpdir;
diff --git a/PVE/VZDump/QemuServer.pm b/PVE/VZDump/QemuServer.pm
index d555b09..d039598 100644
--- a/PVE/VZDump/QemuServer.pm
+++ b/PVE/VZDump/QemuServer.pm
@@ -384,7 +384,7 @@ sub assemble {
 }
 
 sub archive {
-    my ($self, $task, $vmid, $filename, $comp) = @_;
+    my ($self, $task, $vmid, $filename, $comp, $basefile) = @_;
 
     my $conffile = "$task->{tmpdir}/qemu-server.conf";
 
@@ -411,6 +411,7 @@ sub archive {
     my $cmd = "/usr/lib/qemu-server/vmtar $sparse $files";
     my $bwl = $opts->{bwlimit}*1024; # bandwidth limit for cstream
     $cmd .= "|cstream -t $bwl" if $opts->{bwlimit};
+    $cmd .= "|pve-xdelta3 -e -q -c -s '$basefile'" if $basefile;
     $cmd .= "|$comp" if $comp;
 
     if ($opts->{stdout}) {
-- 
1.7.2.5



More information about the pve-devel mailing list