7 use Data::Dump qw/dump/;
9 my $debug = $ENV{DEBUG} || 0;
17 '212052' => { # koha-dev
21 '212056' => { # webpac2
27 my $now = DateTime->now();
31 open(my $fs, '-|', 'zfs list -t snapshot -H');
34 my ( $name, $used, $avail, $refer, $mountpoint ) = split(/\t/,$_,6);
36 next unless $name =~ m{(.+)@(\d\d\d\d)-(\d\d)-(\d\d)};
40 my $date = DateTime->new( year => $2, month => $3, day => $4 );
42 my $age = $now->delta_days( $date )->delta_days;
47 my $c = (grep { $host =~ m{\Q$_\E} } keys %$config)[0];
48 $c = 'default' unless defined $c;
50 warn "# config: $c\n" if $debug;
53 $h =~ s{,+/([^/]+)$}{}; # just hostname without path
55 $c = $config->{$c} || die "can't find config for $c";
57 warn "# c = ",dump($c) if $debug;
61 foreach ( sort { $b <=> $a } keys %$c ) {
62 $older_than_days = $_;
63 $keep_every_days = $c->{$_};
64 warn "## $host $age > $older_than_days" if $debug;
65 last if $age > $older_than_days;
68 my $config_applied = '';
70 if ( $age > $older_than_days ) {
72 $config_applied = "> $older_than_days keep $keep_every_days";
74 $last_backup->{$host} ||= $date;
75 $last = $last_backup->{$host}->delta_days( $date )->delta_days;
77 if ( $last && $last < $keep_every_days ) {
81 $last_backup->{$host} = $date;
84 $config_applied = 'none';
87 print "$op $name\t$used\t$refer\t$age\t$last\t$config_applied\n";
89 system "zfs destroy $name" if $op eq 'D' && @ARGV;