btrbk: added command line option -r (resume only)

pull/30/head
Axel Burri 2015-05-15 20:24:14 +02:00
parent 09e214acf4
commit 84e41727b9
2 changed files with 100 additions and 78 deletions

View File

@ -4,6 +4,7 @@ btrbk-current
* Set PATH variable instead of using absolute "/sbin/btrfs" for * Set PATH variable instead of using absolute "/sbin/btrfs" for
compatibility with all linux distros out there, which all install compatibility with all linux distros out there, which all install
'btrfs' in different locations (closes: #20). 'btrfs' in different locations (closes: #20).
* Added command line option -r (resume only).
* Catch and display errors from "btrfs subvolume show". * Catch and display errors from "btrfs subvolume show".
* Include systemd service and timer unit for daily backups. * Include systemd service and timer unit for daily backups.

51
btrbk
View File

@ -47,7 +47,7 @@ use Date::Calc qw(Today Delta_Days Day_of_Week);
use Getopt::Std; use Getopt::Std;
use Data::Dumper; use Data::Dumper;
our $VERSION = "0.17.2-dev"; our $VERSION = "0.18.0-dev-resume_only";
our $AUTHOR = 'Axel Burri <axel@tty0.ch>'; our $AUTHOR = 'Axel Burri <axel@tty0.ch>';
our $PROJECT_HOME = '<http://www.digint.ch/btrbk/>'; our $PROJECT_HOME = '<http://www.digint.ch/btrbk/>';
@ -118,6 +118,7 @@ sub HELP_MESSAGE
print STDERR " --version display version information\n"; print STDERR " --version display version information\n";
print STDERR " -c FILE specify configuration file\n"; print STDERR " -c FILE specify configuration file\n";
print STDERR " -p preserve all backups (do not delete any old targets)\n"; print STDERR " -p preserve all backups (do not delete any old targets)\n";
print STDERR " -r resume only (no new snapshots, resume all missing backups)\n";
print STDERR " -v be verbose (set loglevel=info)\n"; print STDERR " -v be verbose (set loglevel=info)\n";
print STDERR " -q be quiet (do not print summary at end of \"run\" command)\n"; print STDERR " -q be quiet (do not print summary at end of \"run\" command)\n";
print STDERR " -l LEVEL set loglevel (warn, info, debug, trace)\n"; print STDERR " -l LEVEL set loglevel (warn, info, debug, trace)\n";
@ -1277,7 +1278,7 @@ MAIN:
my @today = Today(); my @today = Today();
my %opts; my %opts;
unless(getopts('hc:vql:p', \%opts)) { unless(getopts('hc:prvql:', \%opts)) {
VERSION_MESSAGE(); VERSION_MESSAGE();
HELP_MESSAGE(0); HELP_MESSAGE(0);
exit 1; exit 1;
@ -1297,6 +1298,7 @@ MAIN:
@config_src = ( $opts{c} ) if($opts{c}); @config_src = ( $opts{c} ) if($opts{c});
my $quiet = $opts{q}; my $quiet = $opts{q};
my $preserve_backups = $opts{p}; my $preserve_backups = $opts{p};
my $resume_only = $opts{r};
# check command line options # check command line options
if($opts{h} || (not $command)) { if($opts{h} || (not $command)) {
@ -1728,6 +1730,11 @@ MAIN:
if($action_run) if($action_run)
{
if($resume_only) {
INFO "Skipping snapshot creation (option \"-r\" present)";
}
else
{ {
# #
# create snapshots # create snapshots
@ -1791,6 +1798,7 @@ MAIN:
} }
} }
} }
}
# #
# create backups # create backups
@ -1818,7 +1826,9 @@ MAIN:
WARN "Ignoring deprecated option \"receive_log\" for target: $droot->{PRINT}" WARN "Ignoring deprecated option \"receive_log\" for target: $droot->{PRINT}"
} }
#
# resume missing backups (resume_missing) # resume missing backups (resume_missing)
#
if(config_key($config_target, "resume_missing")) if(config_key($config_target, "resume_missing"))
{ {
INFO "Checking for missing backups of subvolume \"$svol->{PRINT}\" in: $droot->{PRINT}/"; INFO "Checking for missing backups of subvolume \"$svol->{PRINT}\" in: $droot->{PRINT}/";
@ -1896,6 +1906,8 @@ MAIN:
} }
} }
unless($resume_only)
{
# skip creation if resume_missing failed # skip creation if resume_missing failed
next if($config_target->{ABORTED}); next if($config_target->{ABORTED});
die unless($config_subvol->{SNAPSHOT}); die unless($config_subvol->{SNAPSHOT});
@ -1909,6 +1921,7 @@ MAIN:
parent => $latest_common_src, # this is <undef> if no common found parent => $latest_common_src, # this is <undef> if no common found
); );
} }
}
else { else {
ERROR "Unknown target type \"$target_type\", skipping: $svol->{PRINT}"; ERROR "Unknown target type \"$target_type\", skipping: $svol->{PRINT}";
$config_target->{ABORTED} = "Unknown target type \"$target_type\""; $config_target->{ABORTED} = "Unknown target type \"$target_type\"";
@ -1921,8 +1934,8 @@ MAIN:
# #
# remove backups following a preserve daily/weekly/monthly scheme # remove backups following a preserve daily/weekly/monthly scheme
# #
if($preserve_backups) { if($preserve_backups || $resume_only) {
INFO "Preserving all backups (option \"-p\" present)"; INFO "Preserving all backups (option \"-p\" or \"-r\" present)";
} }
else else
{ {
@ -2033,19 +2046,19 @@ MAIN:
my $sroot = $config_vol->{sroot} || vinfo($config_vol->{url}, $config_vol); my $sroot = $config_vol->{sroot} || vinfo($config_vol->{url}, $config_vol);
foreach my $config_subvol (@{$config_vol->{SUBVOLUME}}) foreach my $config_subvol (@{$config_vol->{SUBVOLUME}})
{ {
my @subvol_out;
my $svol = $config_subvol->{svol} || vinfo_child($sroot, $config_subvol->{rel_path}); my $svol = $config_subvol->{svol} || vinfo_child($sroot, $config_subvol->{rel_path});
push @out, "$svol->{PRINT}";
if($config_vol->{ABORTED}) { if($config_vol->{ABORTED}) {
push @out, "!!! $sroot->{PRINT}: ABORTED: $config_vol->{ABORTED}"; push @subvol_out, "!!! $sroot->{PRINT}: ABORTED: $config_vol->{ABORTED}";
$err_count++ unless($config_vol->{ABORTED_NOERR}); $err_count++ unless($config_vol->{ABORTED_NOERR});
} }
if($config_subvol->{ABORTED}) { if($config_subvol->{ABORTED}) {
push @out, "!!! Subvolume \"$svol->{PRINT}\" aborted: $config_subvol->{ABORTED}"; push @subvol_out, "!!! Subvolume \"$svol->{PRINT}\" aborted: $config_subvol->{ABORTED}";
$err_count++ unless($config_subvol->{ABORTED_NOERR}); $err_count++ unless($config_subvol->{ABORTED_NOERR});
} }
push @out, "+++ $config_subvol->{SNAPSHOT}->{PRINT}" if($config_subvol->{SNAPSHOT}); push @subvol_out, "+++ $config_subvol->{SNAPSHOT}->{PRINT}" if($config_subvol->{SNAPSHOT});
if($config_subvol->{SUBVOL_DELETED}) { if($config_subvol->{SUBVOL_DELETED}) {
push @out, "--- $_->{PRINT}" foreach(sort { $b->{PATH} cmp $a->{PATH} } @{$config_subvol->{SUBVOL_DELETED}}); push @subvol_out, "--- $_->{PRINT}" foreach(sort { $b->{PATH} cmp $a->{PATH} } @{$config_subvol->{SUBVOL_DELETED}});
} }
foreach my $config_target (@{$config_subvol->{TARGET}}) foreach my $config_target (@{$config_subvol->{TARGET}})
{ {
@ -2055,21 +2068,26 @@ MAIN:
$create_mode = ">>>" if($_->{parent}); $create_mode = ">>>" if($_->{parent});
# substr($create_mode, 0, 1, '%') if($_->{resume}); # substr($create_mode, 0, 1, '%') if($_->{resume});
$create_mode = "!!!" if($_->{ERROR}); $create_mode = "!!!" if($_->{ERROR});
push @out, "$create_mode $_->{received_subvolume}->{PRINT}"; push @subvol_out, "$create_mode $_->{received_subvolume}->{PRINT}";
} }
if($config_target->{SUBVOL_DELETED}) { if($config_target->{SUBVOL_DELETED}) {
push @out, "--- $_->{PRINT}" foreach(sort { $b->{PATH} cmp $a->{PATH} } @{$config_target->{SUBVOL_DELETED}}); push @subvol_out, "--- $_->{PRINT}" foreach(sort { $b->{PATH} cmp $a->{PATH} } @{$config_target->{SUBVOL_DELETED}});
} }
if($config_target->{ABORTED}) { if($config_target->{ABORTED}) {
push @out, "!!! Target \"$droot->{PRINT}\" aborted: $config_target->{ABORTED}"; push @subvol_out, "!!! Target \"$droot->{PRINT}\" aborted: $config_target->{ABORTED}";
$err_count++ unless($config_target->{ABORTED_NOERR}); $err_count++ unless($config_target->{ABORTED_NOERR});
} }
push(@unrecoverable, $config_target->{UNRECOVERABLE}) if($config_target->{UNRECOVERABLE}); push(@unrecoverable, $config_target->{UNRECOVERABLE}) if($config_target->{UNRECOVERABLE});
} }
push @out, ""; if(@subvol_out) {
push @out, "$svol->{PRINT}", @subvol_out, "";
}
else {
push @out, "$svol->{PRINT}", "<no_action>", "";
}
} }
} }
@ -2087,8 +2105,11 @@ MAIN:
print join("\n", @out); print join("\n", @out);
if($preserve_backups) { if($resume_only) {
print "\nNOTE: Preserved all backups (option -p present)\n"; print "\nNOTE: No snapshots created (option -r present)\n";
}
if($preserve_backups || $resume_only) {
print "\nNOTE: Preserved all backups (option -p or -r present)\n";
} }
if($err_count) { if($err_count) {
print "\nNOTE: Some errors occurred, which may result in missing backups!\n"; print "\nNOTE: Some errors occurred, which may result in missing backups!\n";