Removing Stale RRD Files

I’ve found that when dealing with rrdfiles, they can show the wrong lastmodified time.  This means if I go with the usual: delete all files that haven’t been modified within say 2 days, I could be deleting some GOOD rrd files…

Here’s my solution.  Use rrdtool lastupdated to spit out epoch time of last updated and anything that’s older than 2 days we’ll delete:

[cc escaped=”true” nowrap=”true” lang=”bash”]
for myfile in *.rrd
#rrdtool lastupdate $myfile | tail -1 | awk -F: ‘{if ($1 < systime()-172800) print strftime(“%c”,$1)}’;
RETURN=`rrdtool lastupdate $myfile | tail -1 | awk -F: ‘{if ($1 < systime()-172800) print 0}’`
if [ “$RETURN” == 0 ]; then
echo “Deleting $myfile”
# uncomment to really remove file
#/bin/rm -f $myfile
echo “Skipping File $myfile”