X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/aabbf4d8f3be25ce4e2253074a6c49ab7573ac03..5fde77fb90280da2c008bb5e8e83f6635b999715:/cookbooks/backup/files/default/expire-backups diff --git a/cookbooks/backup/files/default/expire-backups b/cookbooks/backup/files/default/expire-backups index 0cd75a502..9d82c384a 100644 --- a/cookbooks/backup/files/default/expire-backups +++ b/cookbooks/backup/files/default/expire-backups @@ -43,19 +43,23 @@ for my $month (0 .. $months - 1) } my $dates = join("|", @dates); -my $match = qr/^${prefix}\d{4}-\d{2}-\d{2}\./; -my $keep = qr/^${prefix}(?:${dates})\./; +my $match = qr/^\Q${prefix}\E\d{4}-\d{2}-\d{2}\./; +my $keep = qr/^\Q${prefix}\E(?:${dates})\./; opendir(DIR, "$dir") || die "Can't open ${dir}: $!"; -while (my $file = readdir(DIR)) -{ -# print "Expiring $file\n" if $file =~ $match && $file !~ $keep; - unlink("${dir}/${file}") if $file =~ $match && $file !~ $keep; -} +my @files = sort(grep(/$match/, readdir(DIR))); closedir(DIR); +pop @files; + +for my $file (@files) +{ +# print "Expiring $file\n" if $file !~ $keep; + unlink("${dir}/${file}") if $file !~ $keep; +} + exit 0; sub Monday