From 81aef9e5b51a355c050c6fc5d862716d586386af Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Tue, 31 Mar 2015 16:20:45 +0200 Subject: [PATCH] btrbk: added function get_date_tag() --- btrbk | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/btrbk b/btrbk index 805f616..10954ef 100755 --- a/btrbk +++ b/btrbk @@ -836,6 +836,19 @@ sub btrfs_send_receive($$$$;$) } +sub get_date_tag($) +{ + my $name = shift; + $name =~ s/_([0-9]+)$//; + my $postfix_counter = $1; + my $date = undef; + if($name =~ /\.([0-9]{4})([0-9]{2})([0-9]{2})$/) { + $date = [ $1, $2, $3 ]; + } + return ($date, $postfix_counter); +} + + sub get_snapshot_children($$) { my $sroot = shift || die; @@ -1628,9 +1641,9 @@ MAIN: INFO "Cleaning backups of subvolume \"$sroot/$svol\": $droot/$svol.*"; my @schedule; foreach my $vol (keys %{$vol_info{$droot}}) { - if($vol =~ /^$svol\.([0-9]{4})([0-9]{2})([0-9]{2})/) { - push(@schedule, { name => "$droot/$vol", sort => $vol, date => [ $1, $2, $3 ] }); - } + my ($date, undef) = get_date_tag($vol); + next unless($date && ($vol =~ /^svol\./)); + push(@schedule, { name => "$droot/$vol", sort => $vol, date => $date }); } my @delete = schedule_deletion( schedule => \@schedule, @@ -1662,9 +1675,9 @@ MAIN: INFO "Cleaning snapshots: $sroot/$snapdir$svol.*"; my @schedule; foreach my $vol (keys %{$vol_info{$sroot}}) { - if($vol =~ /^$snapdir$svol\.([0-9]{4})([0-9]{2})([0-9]{2})/) { - push(@schedule, { name => "$sroot/$vol", sort => $vol, date => [ $1, $2, $3 ] }); - } + my ($date, undef) = get_date_tag($vol); + next unless($date && ($vol =~ /^$snapdir$svol\./)); + push(@schedule, { name => "$sroot/$vol", sort => $vol, date => $date }); } my @delete = schedule_deletion( schedule => \@schedule,