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

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

  ViewVC Help
Powered by ViewVC 1.1.26