/[sysadmin-cookbook]/recepies/zfs/zfs-expire-snapshot.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /recepies/zfs/zfs-expire-snapshot.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 108 by dpavlin, Sat Jun 6 16:56:30 2009 UTC revision 118 by dpavlin, Thu Jul 9 10:14:40 2009 UTC
# Line 4  use warnings; Line 4  use warnings;
4  use strict;  use strict;
5    
6  use DateTime;  use DateTime;
7    use Data::Dump qw/dump/;
8    
9    my $debug = 0;
10    
11    my $config = {
12            'default' => {
13                    21 => 5,
14                    30 => 10,
15                    60 => 30,
16            },
17            '212052' => {   # koha-dev
18                    7 => 10,
19                    14 => 30,
20            },
21            '212056' => {   # webpac2
22                    7 => 5,
23            }
24    };
25    
26  my $now = DateTime->now();  my $now = DateTime->now();
27    
# Line 25  while(<$fs>) { Line 43  while(<$fs>) {
43          my $op = ' ';          my $op = ' ';
44          my $last = 0;          my $last = 0;
45    
46          if ( $age > 14 ) {          my $c = (grep { $host =~ m{\Q$_\E} } keys %$config)[0];
47            $c = 'default' unless defined $c;
48    
49            warn "# config: $c\n" if $debug;
50    
51            my $h = $host;
52            $h =~ s{,+/([^/]+)$}{}; # just hostname without path
53    
54            $c = $config->{$c} || die "can't find config for $c";
55    
56            warn "# c = ",dump($c) if $debug;
57    
58            my $keep_every_days;
59            my $older_than_days;
60            foreach ( sort keys %$c ) {
61                    $older_than_days = $_;
62                    $keep_every_days = $c->{$_};
63                    warn "## $host $age > $older_than_days" if $debug;
64                    last if $age > $older_than_days;
65            }
66    
67            my $config_applied = '';
68    
69            if ( $age > $older_than_days ) {
70    
71                    $config_applied = "> $older_than_days keep $keep_every_days";
72    
73                  $last_backup->{$host} ||= $date;                  $last_backup->{$host} ||= $date;
74                  $last = $last_backup->{$host}->delta_days( $date )->delta_days;                  $last = $last_backup->{$host}->delta_days( $date )->delta_days;
75    
76                  if ( $last && $last < 5 ) {                  if ( $last && $last < $keep_every_days ) {
77                          $op = '-';                          $op = 'D';
78                  } else {                  } else {
79                          $op = '+';                          $op = ' ';
80                          $last_backup->{$host} = $date;                          $last_backup->{$host} = $date;
81                  }                  }
82            } else {
83                    $config_applied = 'none';
84          }          }
85    
86          warn "$op $name\t$used\t$refer\t$age\t$last\n";          print "$op $name\t$used\t$refer\t$age\t$last\t$config_applied\n";
87    
88          system "zfs destroy $name" if $op eq '-' && @ARGV;          system "zfs destroy $name" if $op eq 'D' && @ARGV;
89  }  }

Legend:
Removed from v.108  
changed lines
  Added in v.118

  ViewVC Help
Powered by ViewVC 1.1.26