[Zetaback-devel] [zetaback commit] r93 - branches/replay

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Mon Jun 8 17:03:49 EDT 2009


Author: mark
Date: 2009-06-08 17:03:49 -0400 (Mon, 08 Jun 2009)
New Revision: 93

Modified:
   branches/replay/zetaback.in
Log:
Merge branch 'filesystem' into replay

Modified: branches/replay/zetaback.in
===================================================================
--- branches/replay/zetaback.in	2009-06-08 21:02:28 UTC (rev 92)
+++ branches/replay/zetaback.in	2009-06-08 21:03:49 UTC (rev 93)
@@ -29,6 +29,7 @@
 $conf{'default'}->{'time_format'} = "%Y-%m-%d %H:%M:%S";
 $conf{'default'}->{'retention'} = 14 * 86400;
 $conf{'default'}->{'compressionlevel'} = 1;
+$conf{'default'}->{'dataset_backup'} = 0;
 
 =pod
 
@@ -335,6 +336,11 @@
 less secure but faster cipher for some hosts, or using a different private 
 key.  There is no default for this setting.
 
+=item dataset_backup
+
+By default zetaback backs zfs filesystems up to files. This option lets you
+specify that the backup go be stored as a zfs dataset on the backup host.
+
 =back
 
 =head1 CONFIGURATION EXAMPLES
@@ -522,73 +528,103 @@
 
 # Lots of args.. internally called.
 sub zfs_do_backup($$$$$$) {
-  my ($host, $fs, $type, $point, $store, $dumpfile) = @_;
+  my ($host, $fs, $type, $point, $store, $dumpname) = @_;
   my $agent = config_get($host, 'agent');
   my $ssh_config = config_get($host, 'ssh_config');
   $ssh_config = "-F $ssh_config" if($ssh_config);
   print "Using custom ssh config file: $ssh_config\n" if($DEBUG);
 
+
+  # compression is meaningless for dataset backups
+  if ($type ne "d") {
+    my $cl = config_get($host, 'compressionlevel');
+    if ($cl >= 1 && $cl <= 9) {
+        open(LBACKUP, "|gzip -$cl >$store/.$dumpname") ||
+        die "zfs_full_backup: cannot create dump\n";
+    } else {
+        open(LBACKUP, ">$store/.$dumpname") ||
+        die "zfs_full_backup: cannot create dump\n";
+    }
+  }
   # Do it. yeah.
-  my $cl = config_get($host, 'compressionlevel');
-  if ($cl >= 1 && $cl <= 9) {
-    open(LBACKUP, "|gzip -$cl >$store/.$dumpfile") ||
-      die "zfs_full_backup: cannot create dump\n";
-  } else {
-    open(LBACKUP, ">$store/.$dumpfile") ||
-      die "zfs_full_backup: cannot create dump\n";
-  }
   eval {
     if(my $pid = fork()) {
-      close(LBACKUP);
+      close(LBACKUP) unless ($type eq "d");
       waitpid($pid, 0);
       die "error: $?" if($?);
     }
     else {
       my @cmd = ('ssh', split(/ /, $ssh_config), $host, $agent, '-z', $fs, "-$type", $point);
       open STDIN, "/dev/null" || exit(-1);
-      open STDOUT, ">&LBACKUP" || exit(-1);
+      if ($type eq "d") {
+        # TODO - specify the filesystem name to receive to here
+        open STDOUT, "|zfs recv $dumpname"
+      } else {
+        open STDOUT, ">&LBACKUP" || exit(-1);
+      }
       exec { $cmd[0] } @cmd;
       print STDERR "$cmd[0] failed: $?\n";
       exit($?);
     }
-    die "dump failed (zero bytes)\n" if(-z "$store/.$dumpfile");
-    rename("$store/.$dumpfile", "$store/$dumpfile") || die "cannot rename dump\n";
+    if ($type ne "d") {
+        die "dump failed (zero bytes)\n" if(-z "$store/.$dumpname");
+        rename("$store/.$dumpname", "$store/$dumpname") || die "cannot rename dump\n";
+    }
   };
   if($@) {
-    unlink("$store/.$dumpfile");
+    # TODO - what to do if you fail to receive a full zfs stream?
+    # nothing?
+    unlink("$store/.$dumpname");
     chomp(my $error = $@);
     $error =~ s/[\r\n]+/ /gsm;
     zetaback_log($host, "FAILED[$error] $host:$fs $type\n");
     die "zfs_full_backup: failed $@";
   }
-  my @st = stat("$store/$dumpfile");
-  my $size = pretty_size($st[7]);
+  my $size;
+  if ($type ne "d") {
+    my @st = stat("$store/$dumpname");
+    $size = pretty_size($st[7]);
+  } else {
+    # TODO - get correct name of the snapshot here in place of dumpname
+    $size = `zfs get -Ho value used $dumpname`;
+  }
   zetaback_log($host, "SUCCESS[$size] $host:$fs $type\n");
 }
 
 sub zfs_full_backup($$$) {
   my ($host, $fs, $store) = @_;
 
-  # Translate into a proper dumpfile nameA
+  # Translate into a proper dumpname
   my $point = time();
   my $efs = dir_encode($fs);
-  my $dumpfile = "$point.$efs.full";
+  my $dumpname = "$point.$efs.full";
 
-  zfs_do_backup($host, $fs, 'f', $point, $store, $dumpfile);
+  zfs_do_backup($host, $fs, 'f', $point, $store, $dumpname);
 }
 
 sub zfs_incremental_backup($$$$) {
   my ($host, $fs, $base, $store) = @_;
   my $agent = config_get($host, 'agent');
 
-  # Translate into a proper dumpfile nameA
+  # Translate into a proper dumpname
   my $point = time();
   my $efs = dir_encode($fs);
-  my $dumpfile = "$point.$efs.incremental.$base";
+  my $dumpname = "$point.$efs.incremental.$base";
 
-  zfs_do_backup($host, $fs, 'i', $base, $store, $dumpfile);
+  zfs_do_backup($host, $fs, 'i', $base, $store, $dumpname);
 }
 
+sub zfs_dataset_backup($$$$) {
+  my ($host, $fs, $base, $store) = @_;
+  my $agent = config_get($host, 'agent');
+
+  my $point = time();
+  # TODO - either put the filesystem 
+  my $dumpname = "$host/$fs\@$point";
+
+  zfs_do_backup($host, $fs, 'd', $base, $store, $dumpname);
+}
+
 sub perform_retention($$) {
   my ($host, $store) = @_;
   my $cutoff = time() - config_get($host, 'retention');



More information about the Zetaback-devel mailing list