Changeset 3327df0351e91e65aa1cfa7ff498ad932bb04725

Show
Ignore:
Timestamp:
11/06/09 22:17:30 (4 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1257545850 +0000
git-parent:

[9aa22ef2a7e50004cee738736a3eab0d47b19ef9]

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

Class support in backup listing and archiving

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • zetaback.in

    r9aa22ef r3327df0  
    467467  mkpath($store) if(! -d $store); 
    468468  return $store; 
     469} 
     470 
     471sub get_classes() { 
     472  my @classes = (""); # The default/blank class is always present 
     473  foreach my $key (keys %conf) { 
     474    if ($conf{$key}->{'type'} eq 'class') { 
     475      push @classes, $key; 
     476    } 
     477  } 
     478  return @classes; 
    469479} 
    470480 
     
    11201130} 
    11211131 
    1122 sub show_backups($$$) { 
    1123   my ($host, $store, $diskpat) = @_; 
    1124   my $backup_info = scan_for_backups($store); 
     1132sub show_backups($$) { 
     1133  my ($host, $diskpat) = @_; 
     1134  my (@files, @datasets, %classmap); 
    11251135  my $tf = config_get($host, 'time_format'); 
    1126   my (@files, @datasets); 
    1127   foreach my $disk (sort keys %{$backup_info}) { 
    1128     my $info = $backup_info->{$disk}; 
    1129     next unless(ref($info) eq 'HASH'); 
    1130     next 
    1131       if($diskpat &&      # if the pattern was specified it could 
    1132          !($disk eq $diskpat ||        # be a specific match or a 
    1133            ($diskpat =~ /^\/(.+)\/$/ && $disk =~ /$1/))); # regex 
    1134  
    1135     my @backup_points = (keys %{$info->{full}}, keys %{$info->{incremental}}); 
    1136     @backup_points = sort { $a <=> $b } @backup_points; 
    1137     @backup_points = (pop @backup_points) unless ($ARCHIVE || $SUMMARY_EXT || $SUMMARY_VIOLATORS); 
    1138  
    1139     # Quick short-circuit in the case of retention violation checks 
    1140     if($SUMMARY_VIOLATORS) { 
    1141       if(time() > $info->{last_full} + config_get($host, 'full_interval') || 
    1142          time() > $info->{last_backup} + config_get($host, 'backup_interval')) { 
    1143         print "$host:$disk\n"; 
    1144         pretty_print_backup($info, $host, $info->{last_full}); 
    1145         # Only print the last backup if it isn't the same as the last full 
    1146         if ($info->{last_full} != $info->{last_backup}) { 
    1147             pretty_print_backup($info, $host, $info->{last_backup}); 
    1148         } 
    1149       } 
    1150       next; 
    1151     } 
    1152  
    1153     # We want to see this one 
    1154     print "$host:$disk\n"; 
    1155     next unless($SUMMARY || $SUMMARY_EXT || $ARCHIVE); 
    1156     if($SUMMARY_EXT) { 
    1157       print "\tLast Full: ". ($info->{last_full} ? strftime($tf, localtime($info->{last_full})) : "Never") . "\n"; 
    1158       if($info->{last_full} < $info->{last_incremental}) { 
    1159         print "\tLast Incr: ". strftime($tf, localtime($info->{last_incremental})). "\n"; 
    1160       } 
    1161     } 
    1162     foreach (@backup_points) { 
    1163       pretty_print_backup($info, $host, $_); 
    1164       if(exists($info->{full}->{$_}->{file})) { 
    1165         push @files, $info->{full}->{$_}->{file}; 
    1166       } elsif(exists($info->{incremental}->{$_}->{file})) { 
    1167         push @files, $info->{incremental}->{$_}->{file}; 
    1168       } elsif(exists($info->{full}->{$_}->{dataset})) { 
    1169         push @datasets, $info->{full}->{$_}->{dataset} 
    1170       } 
    1171     } 
    1172     print "\n"; 
     1136  foreach my $class (get_classes()) { 
     1137    print "=> Class: $class\n" if $DEBUG; 
     1138    my $store = get_store($host, $class); 
     1139    my $backup_info = scan_for_backups($store); 
     1140    foreach my $disk (sort keys %{$backup_info}) { 
     1141      my $info = $backup_info->{$disk}; 
     1142      next unless(ref($info) eq 'HASH'); 
     1143      next 
     1144        if($diskpat &&      # if the pattern was specified it could 
     1145          !($disk eq $diskpat ||        # be a specific match or a 
     1146            ($diskpat =~ /^\/(.+)\/$/ && $disk =~ /$1/))); # regex 
     1147 
     1148      my @backup_points = (keys %{$info->{full}}, keys %{$info->{incremental}}); 
     1149      @backup_points = sort { $a <=> $b } @backup_points; 
     1150      @backup_points = (pop @backup_points) unless ($ARCHIVE || $SUMMARY_EXT || $SUMMARY_VIOLATORS); 
     1151 
     1152      # Quick short-circuit in the case of retention violation checks 
     1153      if($SUMMARY_VIOLATORS) { 
     1154        if(time() > $info->{last_full} + config_get($host, 'full_interval') || 
     1155          time() > $info->{last_backup} + config_get($host, 'backup_interval')) { 
     1156          print "$host:$disk\n"; 
     1157          pretty_print_backup($info, $host, $info->{last_full}); 
     1158          # Only print the last backup if it isn't the same as the last full 
     1159          if ($info->{last_full} != $info->{last_backup}) { 
     1160              pretty_print_backup($info, $host, $info->{last_backup}); 
     1161          } 
     1162        } 
     1163        next; 
     1164      } 
     1165 
     1166      # We want to see this one 
     1167      print "$host:$disk\n"; 
     1168      next unless($SUMMARY || $SUMMARY_EXT || $ARCHIVE); 
     1169      if($SUMMARY_EXT) { 
     1170        print "\tLast Full: ". ($info->{last_full} ? strftime($tf, localtime($info->{last_full})) : "Never") . "\n"; 
     1171        if($info->{last_full} < $info->{last_incremental}) { 
     1172          print "\tLast Incr: ". strftime($tf, localtime($info->{last_incremental})). "\n"; 
     1173        } 
     1174      } 
     1175      foreach (@backup_points) { 
     1176        pretty_print_backup($info, $host, $_); 
     1177        if(exists($info->{full}->{$_}->{file})) { 
     1178          push @files, $info->{full}->{$_}->{file}; 
     1179          $classmap{$info->{full}->{$_}->{file}} = $class; 
     1180        } elsif(exists($info->{incremental}->{$_}->{file})) { 
     1181          push @files, $info->{incremental}->{$_}->{file}; 
     1182          $classmap{$info->{incremental}->{$_}->{file}} = $class; 
     1183        } elsif(exists($info->{full}->{$_}->{dataset})) { 
     1184          push @datasets, $info->{full}->{$_}->{dataset}; 
     1185          $classmap{$info->{full}->{$_}->{dataset}} = $class; 
     1186        } 
     1187      } 
     1188      print "\n"; 
     1189    } 
    11731190  } 
    11741191  if($ARCHIVE && (scalar(@files) || scalar(@datasets))) { 
     
    11871204        } 
    11881205        foreach my $file (@files) { 
     1206          my $store = get_store($host, $classmap{$file}); 
    11891207          (my $afile = $file) =~ s/^$store/$archive/; 
    11901208          move($file, $afile) || print "Error archiving $file: $!\n"; 
     
    11931211      if (@datasets) { 
    11941212        my $archive = config_get($host, 'archive'); 
    1195         my $storefs = get_fs_from_mountpoint($store); 
    11961213        (my $basearchive = $archive) =~ s/\/?%h//g; 
    11971214        my $basearchivefs; 
     
    12041221        my %seen = (); 
    12051222        foreach my $dataset (@datasets) { 
     1223          my $store = get_store($host, $classmap{$dataset}); 
     1224          my $storefs = get_fs_from_mountpoint($store); 
    12061225          $dataset =~ s/@.*$//; # Only rename filesystems, not snapshots 
    12071226          next if $seen{$dataset}++; # Only rename a filesystem once 
     
    13891408   
    13901409    if($LIST || $SUMMARY || $SUMMARY_EXT || $SUMMARY_VIOLATORS || $ARCHIVE) { 
    1391       show_backups($host, $store, $ZFS); 
     1410      show_backups($host, $ZFS); 
    13921411    } 
    13931412    if($BACKUP) {