Changeset 5e96e8bf8df93ecf69ca4d8e4a0adb3672f83138

Show
Ignore:
Timestamp:
07/09/09 21:15:21 (5 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1247174121 +0000
git-parent:

[683020e5dcf5161ad15e36a41a8d6750db4a33ea]

git-author:
Mark Harrison <mark@omniti.com> 1247174121 +0000
Message:

Store the zfs snapshots as non-nested filesystems - fix multiple backups on parent filesystems

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • zetaback.in

    r683020e r5e96e8b  
    511511      my @F = split(' '); 
    512512      my ($fs, $snap) = split('@', $F[0]); 
    513       $fs =~ s/$storefs\/?//; 
     513      #$fs =~ s/$storefs\/?//; 
     514      $fs = get_real_fs_name($fs); 
    514515      my ($whence) = ($snap =~ /(\d+)/); 
    515516      next unless $whence; 
     
    557558sub zfs_do_backup($$$$$$;$) { 
    558559  my ($host, $fs, $type, $point, $store, $dumpname, $base) = @_; 
     560  my ($storefs, $mungedname); 
    559561  my $agent = config_get($host, 'agent'); 
    560562  my $ssh_config = config_get($host, 'ssh_config'); 
    561563  $ssh_config = "-F $ssh_config" if($ssh_config); 
    562564  print "Using custom ssh config file: $ssh_config\n" if($DEBUG); 
    563   my $storefs; 
    564565 
    565566  # compression is meaningless for dataset backups 
     
    586587      $storefs="$storefs/$host"; 
    587588    } 
    588     print STDERR "Receiving to zfs filesystem $storefs/$dumpname\n" 
     589    $mungedname = munge_fs_name($dumpname); 
     590    print STDERR "Receiving to zfs filesystem $storefs/$mungedname\n" 
    589591      if($DEBUG); 
    590     zfs_create_intermediate_filesystems("$storefs/$dumpname"); 
    591     open(LBACKUP, "|__ZFS__ recv $storefs/$dumpname"); 
     592    zfs_create_intermediate_filesystems("$storefs/$mungedname"); 
     593    open(LBACKUP, "|__ZFS__ recv $storefs/$mungedname"); 
    592594  } 
    593595  # Do it. yeah. 
     
    617619      rename("$store/.$dumpname", "$store/$dumpname") || die "cannot rename dump\n"; 
    618620    } else { 
    619       my $storefs = get_fs_from_mountpoint($store); 
    620       `__ZFS__ list $storefs/$dumpname`; 
    621       die "dump failed (received snapshot $storefs/$dumpname does not exist)\n" 
     621      # Set the real filesystem name as a zfs property 
     622      my $fsname = (split('@', $dumpname))[0]; 
     623      my $mungedfs = (split('@', $mungedname))[0]; 
     624      `__ZFS__ set com.omniti.labs.zetaback:fsname=$fsname $storefs/$mungedfs`; 
     625      # Check everything is ok 
     626      `__ZFS__ list $storefs/$mungedname`; 
     627      die "dump failed (received snapshot $storefs/$mungedname does not exist)\n" 
    622628        if $?; 
    623629    } 
     
    629635    chomp(my $error = $@); 
    630636    $error =~ s/[\r\n]+/ /gsm; 
     637    # TODO - this isn't being shown - why? 
    631638    zetaback_log($host, "FAILED[$error] $host:$fs $type\n"); 
     639    # TODO - run zfs set to set the real filesystem name 
    632640    die "zfs_full_backup: failed $@"; 
    633641  } 
     
    637645    $size = pretty_size($st[7]); 
    638646  } else { 
    639     my $storefs = get_fs_from_mountpoint($store); 
    640     $size = `__ZFS__ get -Ho value used $storefs/$dumpname`; 
     647    $size = `__ZFS__ get -Ho value used $storefs/$mungedname`; 
    641648    chomp $size; 
    642649  } 
     650  # TODO - this isn't being shown - why? 
    643651  zetaback_log($host, "SUCCESS[$size] $host:$fs $type\n"); 
    644652} 
     
    656664      } 
    657665  } 
     666} 
     667 
     668sub munge_fs_name($) { 
     669  # Removes slashes from a filesystem name, while ensuring every filesystem 
     670  # name results in a unique munged name (you can't have consecutive slashes 
     671  # in a filesystem name). This operation is not reversible. 
     672  my ($fs) = @_; 
     673  $fs =~ s/_/__/g; 
     674  $fs =~ s/\//_/g; 
     675  return $fs; 
     676} 
     677 
     678sub get_real_fs_name($) { 
     679  my ($fs) = @_; 
     680  # Get's a real fs name from a munged one - requires that the real fs name is 
     681  # stored as a user property 
     682  return ( 
     683    split(/\s+/,`__ZFS__ get -H com.omniti.labs.zetaback:fsname $fs`))[2]; 
    658684} 
    659685