Changeset 27ca736257eadf7cced2fd99742d329f1cbe28d4

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

[5a3ecc112d3ac7b68e1badac3074f24cc6022fb3]

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

Archive support for datasets

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • zetaback.in

    r5a3ecc1 r27ca736  
    511511      my @F = split(' '); 
    512512      my ($rawfs, $snap) = split('@', $F[0]); 
    513       #$fs =~ s/$storefs\/?//; 
    514       my $fs = get_real_fs_name($rawfs); 
    515513      my ($whence) = ($snap =~ /(\d+)/); 
    516514      next unless $whence; 
     515      my $fs = get_real_fs_name($rawfs); 
    517516      # Treat a dataset backup as a full backup from the point of view of the 
    518517      # backup lists 
     
    845844    my ($mountpoint) = @_; 
    846845    my $fs; 
    847     my $rv = open(ZFSLIST, "__ZFS__ list -H |"); 
     846    my $rv = open(ZFSLIST, "__ZFS__ list -t filesystem -H |"); 
    848847    die "Unable to determine zfs filesystem for $mountpoint" unless $rv; 
    849848    while (<ZFSLIST>) { 
     
    10041003  my $backup_info = scan_for_backups($store); 
    10051004  my $tf = config_get($host, 'time_format'); 
    1006   my @files
     1005  my (@files, @datasets)
    10071006  foreach my $disk (sort keys %{$backup_info}) { 
    10081007    my $info = $backup_info->{$disk}; 
     
    10421041    foreach (@backup_points) { 
    10431042      pretty_print_backup($info, $host, $_); 
    1044       push @files, exists($info->{full}->{$_}) ? $info->{full}->{$_}->{file} : $info->{incremental}->{$_}->{file}; 
     1043      if(exists($info->{full}->{$_}->{file})) { 
     1044        push @files, $info->{full}->{$_}->{file}; 
     1045      } elsif(exists($info->{incremental}->{$_}->{file})) { 
     1046        push @files, $info->{incremental}->{$_}->{file}; 
     1047      } elsif(exists($info->{full}->{$_}->{dataset})) { 
     1048        push @datasets, $info->{full}->{$_}->{dataset} 
     1049      } 
    10451050    } 
    10461051    print "\n"; 
    10471052  } 
    1048   if($ARCHIVE && scalar(@files)) { 
    1049     my $archive = config_get($host, 'archive'); 
    1050     $archive =~ s/%h/$host/g; 
    1051     if(! -d $archive) { 
    1052       mkdir $archive || die "Cannot mkdir($archive)\n"; 
    1053     } 
    1054     print "\nAre you sure you would like to archive ".scalar(@files)." file(s)? "; 
     1053  if($ARCHIVE && (scalar(@files) || scalar(@datasets))) { 
     1054    print "\nAre you sure you would like to archive ".scalar(@files). 
     1055      " file(s) and ".scalar(@datasets)." dataset(s)? "; 
    10551056    while(($_ = <>) !~ /(?:y|n|yes|no)$/i) { 
    1056       print "Are you sure you would like to archive ".scalar(@files)." file(s)? "; 
     1057      print "\nAre you sure you would like to archive ".scalar(@files). 
     1058        " file(s) and ".scalar(@datasets)." dataset(s)? "; 
    10571059    } 
    10581060    if(/^y/i) { 
    1059       foreach my $file (@files) { 
    1060         (my $afile = $file) =~ s/^$store/$archive/; 
    1061         move($file, $afile) || print "Error archiving $file: $!\n"; 
     1061      if (@files) { 
     1062        my $archive = config_get($host, 'archive'); 
     1063        $archive =~ s/%h/$host/g; 
     1064        if(! -d $archive) { 
     1065          mkdir $archive || die "Cannot mkdir($archive)\n"; 
     1066        } 
     1067        foreach my $file (@files) { 
     1068          (my $afile = $file) =~ s/^$store/$archive/; 
     1069          move($file, $afile) || print "Error archiving $file: $!\n"; 
     1070        } 
     1071      } 
     1072      if (@datasets) { 
     1073        my $archive = config_get($host, 'archive'); 
     1074        my $storefs = get_fs_from_mountpoint($store); 
     1075        (my $basearchive = $archive) =~ s/\/?%h//g; 
     1076        my $basearchivefs; 
     1077        eval { 
     1078          $basearchivefs = get_fs_from_mountpoint($basearchive); 
     1079        }; 
     1080        die "Unable to find archive filesystem. The archive directory must be the root of a zfs filesystem to archive datasets." if $@; 
     1081        my $archivefs = "$basearchivefs/$host"; 
     1082        `__ZFS__ create $archivefs`; # We don't care if this fails 
     1083        my %seen = (); 
     1084        foreach my $dataset (@datasets) { 
     1085          $dataset =~ s/@.*$//; # Only rename filesystems, not snapshots 
     1086          next if $seen{$dataset}++; # Only rename a filesystem once 
     1087          (my $adataset = $dataset) =~ s/^$storefs/$archivefs/; 
     1088          `__ZFS__ rename $dataset $adataset`; 
     1089          if ($?) { 
     1090            print "Error archiving $dataset\n"; 
     1091          } 
     1092        } 
    10621093      } 
    10631094    }