btrbk: bugfix: crash if "snapshot_create onchange" is set and no snapshots are present

pull/30/head
Axel Burri 2015-05-26 18:09:36 +02:00
parent 7b9021d5c8
commit 005e5c63be
1 changed files with 10 additions and 5 deletions

7
btrbk
View File

@ -1825,13 +1825,18 @@ MAIN:
elsif($snapshot_create eq "onchange") { elsif($snapshot_create eq "onchange") {
# check if latest snapshot is up-to-date with source subvolume (by generation) # check if latest snapshot is up-to-date with source subvolume (by generation)
my $latest = get_latest_snapshot_child($sroot, $svol); my $latest = get_latest_snapshot_child($sroot, $svol);
if($latest && ($latest->{gen} == $svol->{gen})) { if($latest) {
if($latest->{gen} == $svol->{gen}) {
INFO "Snapshot creation skipped: snapshot_create=onchange, snapshot is up-to-date: $latest->{PRINT}"; INFO "Snapshot creation skipped: snapshot_create=onchange, snapshot is up-to-date: $latest->{PRINT}";
$config_subvol->{SNAPSHOT_UP_TO_DATE} = $latest; $config_subvol->{SNAPSHOT_UP_TO_DATE} = $latest;
next; next;
} }
DEBUG "Snapshot creation enabled: snapshot_create=onchange, gen=$svol->{gen} > snapshot_gen=$latest->{gen}"; DEBUG "Snapshot creation enabled: snapshot_create=onchange, gen=$svol->{gen} > snapshot_gen=$latest->{gen}";
} }
else {
DEBUG "Snapshot creation enabled: snapshot_create=onchange, no snapshots found";
}
}
elsif($snapshot_create eq "ondemand") { elsif($snapshot_create eq "ondemand") {
# check if at least one target is present # check if at least one target is present
if(scalar grep { not $_->{ABORTED} } @{$config_subvol->{TARGET}}) { if(scalar grep { not $_->{ABORTED} } @{$config_subvol->{TARGET}}) {