From 3e829f6cff1765e913df654f961fca5c5bb71c38 Mon Sep 17 00:00:00 2001 From: Axel Burri Date: Tue, 13 Jan 2015 13:35:58 +0100 Subject: [PATCH] btrbk: removed action "clean", moving this to productive after each action "execute" --- btrbk | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/btrbk b/btrbk index 01a7ac0..fe72deb 100755 --- a/btrbk +++ b/btrbk @@ -75,6 +75,7 @@ my %config_options = ( target_preserve_daily => { default => "all", accept => [ "all" ], accept_numeric => 1 }, target_preserve_weekly => { default => 0, accept => [ "all" ], accept_numeric => 1 }, target_preserve_monthly => { default => "all", accept => [ "all" ], accept_numeric => 1 }, + # TODO: btrfs_commit_delete config option, setting --commit-after or --commit-each option to "btrfs subvolume delete" command ); my @config_target_types = qw(send-receive); @@ -98,8 +99,7 @@ sub HELP_MESSAGE print STDERR "\n"; print STDERR "commands:\n"; print STDERR " tree shows backup tree\n"; - print STDERR " execute perform all backups\n"; - print STDERR " clean delete old backups\n"; + print STDERR " execute perform all backups, and delete old snapshots based on configured backup scheme\n"; print STDERR " dryrun don't run btrfs commands, just show what would be executed\n"; print STDERR " diff shows new files for subvolume , against subvolume \n"; print STDERR "\n"; @@ -205,12 +205,12 @@ sub config_key($$) { my $node = shift; my $key = shift; - TRACE "config_key: $node->{CONTEXT}"; + TRACE "config_key: context=$node->{CONTEXT}, key=$key"; while(not exists($node->{$key})) { return undef unless($node->{PARENT}); $node = $node->{PARENT}; } - TRACE "config_key: returning " . ($node->{$key} // ""); + TRACE "config_key: found value=" . ($node->{$key} // ""); return $node->{$key}; } @@ -787,16 +787,12 @@ MAIN: } my $action_execute; - my $action_clean; my $action_tree; my $action_diff; if(($command eq "execute") || ($command eq "dryrun")) { $action_execute = 1; $dryrun = 1 if($command eq "dryrun"); } - elsif ($command eq "clean") { - $action_clean = 1; - } elsif ($command eq "tree") { $action_tree = 1; } @@ -979,6 +975,7 @@ MAIN: next unless $vol_info{$droot}; my $match = "$droot/$snapshot"; foreach (sort { $a->{FS_PATH} cmp $b->{FS_PATH} } (values $vol_info{$droot})) { + # TODO: also print the backups which do not have corresponding snapshot anymore print "| | |== $_->{FS_PATH}\n" if($_->{FS_PATH} eq $match); } } @@ -1127,24 +1124,8 @@ MAIN: } } } - } - if($action_clean) - { - $dryrun = 1; - # TODO: gather all information first, then delete all backups/snapshots at the end - # TODO: always preserve first/last - - my @last_sunday; - if(Day_of_Week(@today) == 7) { # today is sunday - @last_sunday = @today; - } - else { - @last_sunday = Add_Delta_Days(Monday_of_Week(Week_of_Year(@today)), -1); - } - DEBUG "last sunday: " . join('-', @last_sunday); - # # remove backups following a preserve daily/weekly/monthly scheme # @@ -1157,7 +1138,6 @@ MAIN: next if($config_subvol->{ABORTED}); my $svol = $config_subvol->{svol} || die; my $snapdir = config_key($config_subvol, "snapshot_dir") || die; - INFO "Cleaning subvolume backups for: $sroot/$svol"; foreach my $config_target (@{$config_subvol->{TARGET}}) { next if($config_target->{ABORTED}); @@ -1166,7 +1146,7 @@ MAIN: # # delete backups # - INFO "Cleaning backups: $droot/$svol.*"; + INFO "Cleaning backups of subvolume \"$sroot/$svol\": $droot/$svol.*"; my @check; foreach my $vol (keys %{$vol_info{$droot}}) { if($vol =~ /^$svol\.([0-9]{4})([0-9]{2})([0-9]{2})/) {