Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- use Time::Local qw/timelocal/;
- my @dirs = glob "/home/minecraft/server/world-backup/20*";
- my $now = time;
- for my $dir (sort @dirs) {
- my ($year, $month, $day, $hour, $min) = $dir =~ m/(\d+)-(\d+)-(\d+)_(\d{2})(\d{2})/;
- my $time = timelocal(0,$min+0,$hour+0,$day+0,$month-1,$year-1900);
- my $diff = $now - $time;
- ### Last 2 hours; keep
- if ($diff < 2*60*60) {
- print "KEEP(<2 HOUR): $dir\n";
- next;
- }
- ### Older than 2 hours, keep hourly only
- unless ($min == 0) {
- print "DELETE(>2 HOUR & !HOUR): $dir\n";
- next;
- }
- ### Last 1.5 days, keep all hours
- if ($diff < 1.5*24*60*60) {
- print "KEEP(<1.5 DAY & HOUR): $dir\n";
- next;
- }
- ### Older dan 1.5 days, keep midnight only
- unless ($hour == 0) {
- print "DELETE(>1.5 DAY & !DAY): $dir\n";
- next;
- }
- ### Last 30 days, keep all midnights
- if ($diff < 30*24*60*60) {
- print "KEEP(<30 DAY & DAY): $dir\n"
- next;
- }
- ### Kill anything older
- print "DELETE(>30 DAY): $dir\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement