When puppet leaves an un-tidy mess

A while back, I had written a quick and dirty shell script to take a simple tarball of the /etc directory of my linux machines and copy it to an FTP server. Then, to make sure that the FTP directory didn’t get out of hand, I had written the following in my puppet config for that server that would clean everything up with the use of the tidy resource type. The code looked like this:

  tidy { "/srv/ftp/mrbackup":
    path    => "/srv/ftp/mrbackup/",
    age     => "30d",
    recurse => true,
  }

Nothing really fancy there and I put this in day 1 so I figured everything would run and the tidy command is pretty straight forward.

Unfortunately, when I checked the machine after it had been recieving the backup files for several months, I found something a bit disturbing…Thousands of files!!! WTF!

The documentation seemed pretty straight forward and I was using this command in other parts of my manifests that worked as expected.

The fix!

The key was at the very end of the documention in the type section.

type

Set the mechanism for determining age. Default: atime.

Valid values are atime, mtime, ctime.

As you will note, the default is atime. Because the files are being FTP’d in, they are never being read by the system, simply written. So if you ran a command like find . -type f -atime +30, you would get zero results. My fix is pretty simple, change this to mtime and suddenly I have a lot less files on the system. The new code now looks like this:

  tidy { "/srv/ftp/mrbackup":
    path    => "/srv/ftp/mrbackup/",
    age     => "30d",
    backup  => false,
    recurse => true,
    type    => "mtime",
  }

Comments are closed.