+ #
+ # For an incremental backup, figure out which level we should
+ # do and the index of the reference backup, which is the most
+ # recent backup at any lower level.
+ #
+ @{$Conf{IncrLevels}} = [$Conf{IncrLevels}]
+ unless ref($Conf{IncrLevels}) eq "ARRAY";
+ @{$Conf{IncrLevels}} = [1] if ( !@{$Conf{IncrLevels}} );
+ $incrCntSinceFull = $incrCntSinceFull % @{$Conf{IncrLevels}};
+ $incrLevel = $Conf{IncrLevels}[$incrCntSinceFull];
+ for ( my $i = 0 ; $i < $incrLevel ; $i++ ) {
+ my $idx = $lastIdxByLevel[$i];
+ next if ( !defined($idx) );
+ if ( !defined($incrBaseTime)
+ || $Backups[$idx]{startTime} < $incrBaseTime ) {
+ $incrBaseBkupNum = $Backups[$idx]{num};
+ $incrBaseLevel = $Backups[$idx]{level};
+ $incrBaseTime = $Backups[$idx]{startTime};
+ }
+ }
+ #
+ # Can't find any earlier lower-level backup! Shouldn't
+ # happen - just do full instead
+ #
+ $type = "full" if ( !defined($incrBaseBkupNum) || $incrLevel < 1 );