The rdiff-backup utility is used to create an incremental mirror of a directory tree. I'd like to find out the number of increments currently saved, and save just this number into a variable value. I'm doing this from within a bash script, and need to still have access to the return code of the rdiff-backup command when it completes.
The command can be run to output some statistics:
rdiff-backup --print-statistics $source_dir $mirror_dir
Which gives:
--------------[ Session statistics ]--------------
StartTime 1478018786.00 (Tue Nov 1 16:46:26 2016)
EndTime 1478018802.13 (Tue Nov 1 16:46:42 2016)
ElapsedTime 16.13 (16.13 seconds)
SourceFiles 41812
SourceFileSize 16462964041 (15.3 GB)
MirrorFiles 41812
MirrorFileSize 16462964041 (15.3 GB)
NewFiles 1
NewFileSize 0 (0 bytes)
DeletedFiles 1
DeletedFileSize 0 (0 bytes)
ChangedFiles 2
ChangedSourceSize 0 (0 bytes)
ChangedMirrorSize 0 (0 bytes)
IncrementFiles 4
IncrementFileSize 64 (64 bytes)
TotalDestinationSizeChange 64 (64 bytes)
Errors 0
--------------------------------------------------
The same information can be found in a time stamped statistics file within a special rdiff-backup-data directory within the mirror directory, with the following filename as an example:
/mirror_dir/rdiff-backup-data/session_statistics.2016-11-01T16:46:26Z.data
Alternatively increments can be listed in a different format using a separate command:
rdiff-backup --list-increments mirror_dir
Which outputs:
Found 43 increments:
increments.2016-10-27T20:57:01+01:00.dir Thu Oct 27 20:57:01 2016
increments.2016-10-27T23:57:01+01:00.dir Thu Oct 27 23:57:01 2016
increments.2016-10-28T02:57:01+01:00.dir Fri Oct 28 02:57:01 2016
increments.2016-10-28T05:57:01+01:00.dir Fri Oct 28 05:57:01 2016
increments.2016-10-28T08:57:01+01:00.dir Fri Oct 28 08:57:01 2016
increments.2016-10-28T11:57:01+01:00.dir Fri Oct 28 11:57:01 2016
...
increments.2016-11-01T16:00:14Z.dir Tue Nov 1 16:00:14 2016
Current mirror: Tue Nov 1 16:46:26 2016
I can't figure out whether I should be finding the latest session statistics file and grepping it for the value of the IncrementFiles field, or to divert the output of the original command with the --print-statistics option, or whether separately filtering out the number from the first line of the --list-increments version is more sensible.