]> git.openstreetmap.org Git - chef.git/commitdiff
Always keep the most recent backup
authorTom Hughes <tom@compton.nu>
Sun, 31 Jul 2022 18:12:59 +0000 (19:12 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 31 Jul 2022 18:12:59 +0000 (19:12 +0100)
cookbooks/backup/files/default/expire-backups

index 0cd75a5029dba6cbafceb5effec5f58f4be775ab..81834d43711197c1a129044b68b25f379d98ef96 100644 (file)
@@ -48,14 +48,18 @@ my $keep = qr/^${prefix}(?:${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