count drives by type, ignoring serial number
[sysadmin-cookbook] / recepies / btrfs / btrfs-snap-expire.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use DateTime;
7
8 my $to = DateTime->now->subtract( days => 3 )->truncate( to => 'day' );
9
10 foreach my $snap ( glob '/mnt/*/.snap/*' ) {
11         if ( $snap =~ m{^(.+)/((\d\d\d\d)-(\d\d)-(\d\d)T(\d\d))$} ) {
12                 my $path = $1;
13                 my $name = $2;
14                 next if $6 == 0; # keep daily snapshot
15                 my $dt = DateTime->new( year => $3, month => $4, day => $5, hour => $6 );
16                 next if $dt > $to;
17                 warn "remove $snap\n";
18                 system "btrfsctl -D $name $path";
19         } else {
20                 warn "SKIP $snap\n";
21         }
22 }