Skip to content
Snippets Groups Projects
Commit eebb4a10 authored by root's avatar root
Browse files

backup: Cleanup tweaks

parent 73987c99
No related branches found
No related tags found
No related merge requests found
......@@ -48,8 +48,6 @@ my $last_daily_stamp = timestamp_months_ago(1);
my $last_weekly_stamp = timestamp_months_ago(2);
my $last_full_stamp = timestamp_months_ago(4);
say "$last_full_stamp / $last_weekly_stamp / $last_daily_stamp";
my @summary = ();
for my $stamp ( @stamps ) {
my $backup_root = dirname($stamp);
......@@ -66,7 +64,15 @@ for my $stamp ( @stamps ) {
push( @{$backups{ $backup_path }->{ $type }}, $timestamp );
}
while (my ($path, $backups) = each %backups ) {
say "$backup_root -> $path";
my $info_printed = 0;
my $info = sub {
my ( $trigger, @msgs ) = @_;
if ( $trigger) {
say "\n$backup_root -> $path" unless $info_printed;
$info_printed = 1;
say join "\n", @msgs;
}
};
my @full = @{$backups->{full}};
my @weekly = @{$backups->{weekly}};
my @daily = @{$backups->{daily}};
......@@ -76,26 +82,28 @@ for my $stamp ( @stamps ) {
scalar @full, scalar @weekly, scalar @daily));
# drop daily backups older than the last weekly backup at least month old
# except for trailing daily backups
my @old_weekly = older_than( $last_daily_stamp, @weekly );
if (@old_weekly == 0) {
next
}
next if (@old_weekly == 0);
my $last_weekly_with_dailys = $old_weekly[-1];
drop_backups( $backup_root, $path, map { "$_.daily" } older_than( $last_weekly_with_dailys, @daily ) );
my @daily_to_delete = older_than( $last_weekly_with_dailys, @daily );
$info->( scalar @daily_to_delete );
drop_backups( $backup_root, $path, map { "$_.daily" } @daily_to_delete );
# drop weekly backups older than the last full backup at least two months old
my @old_full = older_than( $last_weekly_stamp, @full );
if (@old_full == 0) {
next
}
next if (@old_full == 0);
my $last_full_with_weeklys = $old_full[-1];
my @weekly_to_delete = older_than( $last_full_with_weeklys, @weekly );
say " weekly_to_delete = " . join " ", @weekly_to_delete;
# drop_backups( $backup_root, $path, map { "$_.weekly" } @weekly_to_delete );
$info->( scalar @weekly_to_delete ); #, " weekly_to_delete = " . join " ", @weekly_to_delete );
drop_backups( $backup_root, $path, map { "$_.weekly" } @weekly_to_delete );
my @full_to_delete = older_than( $last_full_stamp, @full );
say " full_to_delete = " . join " ", @full_to_delete;
# drop_backups( $backup_root, $path, map { "$_.full" }, @full_to_delete );
while ( @full_to_delete && (scalar @full_to_delete) > (scalar @full - 2) ) {
pop @full_to_delete;
}
$info->( scalar @full_to_delete, " full_to_delete = " . join " ", @full_to_delete );
drop_backups( $backup_root, $path, map { "$_.full" } @full_to_delete );
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment