#!/usr/bin/perl

use warnings;
use strict;

use DateTime;

my $to = DateTime->now->subtract( days => 3 )->truncate( to => 'day' );

foreach my $snap ( glob '/mnt/*/.snap/*' ) {
	if ( $snap =~ m{^(.+)/((\d\d\d\d)-(\d\d)-(\d\d)T(\d\d))$} ) {
		my $path = $1;
		my $name = $2;
		next if $6 == 0; # keep daily snapshot
		my $dt = DateTime->new( year => $3, month => $4, day => $5, hour => $6 );
		next if $dt > $to;
		warn "remove $snap\n";
		system "btrfsctl -D $name $path";
	} else {
		warn "SKIP $snap\n";
	}
}
