I have to manage a directory that many people can create subdirectories and files.
Let's say the directory is "/srv/data". I would like to remove any other directories created (recursively) that are older than 7 days and not is a predefined list. I can't quite get there.
bundle agent main
{
vars:
linux::
"keep_dirs" slist => { "project1", "project2", "etc" };
files:
linux:
"/srv/data"
delete => tidy,
file_select => exclude_name_age_dir("@(keep_dirs)", "7");
depth_search => recurse("inf");
}
body file_select exclude_name_age_dir(name,days)
{
leaf_name => { "$(name)" };
mtime => irange(0,ago(0,0,"$(days)",0,0,0));
file_types => { "dir" };
file_result => "file_types.mtime.!leaf_name";
}
This will delete any folders that are empty, but doesn't quite do what I need.
I appreciate any suggestions.