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

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Tue Jun 16 10:17:29 EDT 2009


Author: mark
Date: 2009-06-16 10:17:29 -0400 (Tue, 16 Jun 2009)
New Revision: 97

Modified:
   branches/replay/zetaback.in
   branches/replay/zetaback_agent.in
Log:
Started work on the zetaback_agent side of the equation


Modified: branches/replay/zetaback.in
===================================================================
--- branches/replay/zetaback.in	2009-06-10 20:55:32 UTC (rev 96)
+++ branches/replay/zetaback.in	2009-06-16 14:17:29 UTC (rev 97)
@@ -512,10 +512,11 @@
       $fs =~ s/$storefs\/?//;
       my ($whence) = ($snap =~ /__zb_dset_(\d+)/);
       next unless $whence;
+      # Treat a dataset backup as a full backup from the point of view of the
+      # backup lists
       $info{$fs}->{full}->{$whence}->{'snapshot'} = $snap;
-      # TODO - the info may need to be different here - no last_full or
-      # last_incremental
-      $info{$fs}->{last_full} = $whence if($whence > $info{$fs}->{last_full});
+      $info{$fs}->{last_full} = $whence if ($whence >
+          $info{$fs}->{last_full});
       $info{$fs}->{last_backup} = $whence if ($whence >
           $info{$fs}->{last_backup});
   }
@@ -561,7 +562,7 @@
 
 
   # compression is meaningless for dataset backups
-  if ($type ne "d") {
+  if ($type ne "s") {
     my $cl = config_get($host, 'compressionlevel');
     if ($cl >= 1 && $cl <= 9) {
         open(LBACKUP, "|gzip -$cl >$store/.$dumpname") ||
@@ -574,14 +575,14 @@
   # Do it. yeah.
   eval {
     if(my $pid = fork()) {
-      close(LBACKUP) unless ($type eq "d");
+      close(LBACKUP) unless ($type eq "s");
       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);
-      if ($type eq "d") {
+      if ($type eq "s") {
         my $storefs = get_fs_from_mountpoint($store);
         open STDOUT, "|__ZFS__ recv $storefs/$dumpname"
       } else {
@@ -591,7 +592,7 @@
       print STDERR "$cmd[0] failed: $?\n";
       exit($?);
     }
-    if ($type ne "d") {
+    if ($type ne "s") {
         die "dump failed (zero bytes)\n" if(-z "$store/.$dumpname");
         rename("$store/.$dumpname", "$store/$dumpname") || die "cannot rename dump\n";
     }
@@ -604,7 +605,7 @@
     die "zfs_full_backup: failed $@";
   }
   my $size;
-  if ($type ne "d") {
+  if ($type ne "s") {
     my @st = stat("$store/$dumpname");
     $size = pretty_size($st[7]);
   } else {
@@ -643,7 +644,7 @@
   my $point = time();
   my $dumpname = "$host/$fs\@$point";
 
-  zfs_do_backup($host, $fs, 'd', $base, $store, $dumpname);
+  zfs_do_backup($host, $fs, 's', $base, $store, $dumpname);
 }
 
 sub perform_retention($$) {
@@ -1032,7 +1033,6 @@
       if(time() > $backup_info->{last_full} + config_get($host, 'full_interval')) {
         $backup_type = 'full';
       }
-  
       # If we want an incremental, but have no full, then we need to upgrade to full
       if($backup_type eq 'incremental') {
         my $have_full_locally = 0;
@@ -1044,6 +1044,7 @@
       }
       $backup_type = 'full' if($FORCE_FULL);
       $backup_type = 'incremental' if($FORCE_INC);
+      $backup_type = 'dataset' if(config_get($host, 'dataset_backup') eq 1);
 
       print " => doing $backup_type backup\n" if($DEBUG);
       # We need to drop a __zb_base snap or a __zb_incr snap before we proceed
@@ -1081,6 +1082,21 @@
             $took_action = 1;
           }
         }
+        if($backup_type eq 'dataset') {
+          my @backups = sort { $b <=> $a } (keys %{$backup_info->{'full'}});
+          eval { zfs_dataset_backup($host, $diskname, $backups[0], $store); };
+          if ($@) {
+            chomp(my $err = $@);
+            print " => failure $err\n";
+          }
+          else {
+            # Unless there was an error backing up, remove all the other dset snaps
+            foreach (keys %snaps) {
+              zfs_remove_snap($host, $diskname, $_) if(/^__zb_dset_(\d+)/) 
+            }
+          }
+          $took_action = 1;
+        }
         unlock($host, dir_encode($diskname), 1);
       }
       $suppress{"$host:$diskname"} = 1;

Modified: branches/replay/zetaback_agent.in
===================================================================
--- branches/replay/zetaback_agent.in	2009-06-10 20:55:32 UTC (rev 96)
+++ branches/replay/zetaback_agent.in	2009-06-16 14:17:29 UTC (rev 97)
@@ -11,7 +11,7 @@
 
 use vars qw/%conf $version_string
             $PREFIX $CONF $LIST $FULL $SNAP $ZFS $BASE $RESTORE $VERSION
-            $BUG_6343779 $NEEDSFD/;
+            $BUG_6343779 $NEEDSFD $DSET/;
 $version_string = '0.1';
 $PREFIX = q^__PREFIX__^;
 $CONF = qq^$PREFIX/etc/zetaback_agent.conf^;
@@ -47,6 +47,7 @@
   "d=s" => \$SNAP,
   "f=s" => \$FULL,
   "i=s" => \$BASE,
+  "s=s" => \$DSET,
   "b=s" => \$BUG_6343779,
   "v"   => \$VERSION,
 );
@@ -86,6 +87,11 @@
 Perform an incremental backup.  The name of the backup will include 
 <timestamp>, which is provided by the backup server.
 
+=item -s <timestamp>
+
+Perform a dataset backup.  The name of the backup will include 
+<timestamp>, which is provided by the backup server.
+
 =item -l
 
 List ZFS filesystems.
@@ -189,7 +195,8 @@
   my $target = $ZFS . '@';
   die "zfs_agent_remove_snap: insufficient args\n" unless($ZFS && $SNAP);
   if($SNAP eq '__zb_incr' or
-     $SNAP =~ /__zb_full_\d+/) {
+     $SNAP =~ /__zb_full_\d+/ or
+     $SNAP =~ /__zb_dset_\d+/) {
     $target .= $SNAP;
   }
   else {
@@ -229,6 +236,22 @@
   exit;
 }
 
+sub zfs_agent_perform_dataset {
+  my $target = $ZFS . '@__zb_dset_' . $DSET;
+  my $base = $ZFS . '@__zb_dset_' . $BASE;
+  unless($ZFS && $DSET && $BASE) {
+    die "zfs_agent_perform_dataset: bad args\n"
+  }
+  `__ZFS__ snapshot $target`;
+  my @cmd = ("__ZFS__", "send", "-i", $base, $target);
+  if($NEEDSFD) {
+    fifo_exec(@cmd);
+  } else {
+    exec { $cmd[0] } @cmd;
+  }
+  exit;
+}
+
 sub zfs_agent_list {
   my %zfs;
   open(ZFSLIST, "__ZFS__ list -H -t snapshot,filesystem,volume |");
@@ -295,6 +318,7 @@
 if($ZFS && $RESTORE) { zfs_agent_perform_restore(); exit; }
 if($ZFS && $FULL) { zfs_agent_perform_full(); exit; }
 if($ZFS && $BASE) { zfs_agent_perform_incremental(); exit; }
+if($ZFS && $DSET) { zfs_agent_perform_dataset(); exit; }
 
 =pod
 



More information about the Zetaback-devel mailing list