Backing up MRTG files using TAR

We use MRTG on a number of test servers and have a simple backup solution in place that uses tar to take a copy of the MRTG configuration files as well as the graph data files. However, of late we have noticed that tar has run into trouble when it coincides with a scheduled MRTG update.

In the main, one of two things happens:

  1. Some of the .tmp files generated by MRTG (during its update) are present when tar compiles its list of files to be archived, but are gone again when it goes to add them to the archive.
  2. Some of the .old files maintained by rateup are changed while tar is trying to add them to the archive, causing tar to fail with the error: file changed as we read it.

Our solution to the first point was to add a --exclude=*.tmp to the tar command. However, the second issue was more interesting because it is not clear whether the .old files in question are actually something worth backing up or not.

As it turns out, they are not. Although not very well documented, our testing showed that these files are simply copies of the previous .log files and can also be excluded from the tar command without issues.