Configurable Recursive Purge and Retain Data Tool
In this article we'll discuss and demonstrate a very helpful tool for doing a recursive search through directories from a given root directory and all of its children. In this case, the application will decide whether a file should be deleted or retained. It can, through a property file, have different retention policies (i.e. number of days old for a given a path). At the end of this article, there is a link from which you can clone the repository and freely use and modify.
Configurable HIerachrical Retention and Purge Data Tool (chirpd)
This tool consists of:
- A Bash script - This executes the java jar: chirp-data-tool.jar
- Three Java Classes - The java classes are the main part of this tool
The three Java Classes include:
- ChirpData - This class is the main class and handles the major processing
- ChirpDataLogger - Handles logging messages
- ChirpDataException - The throwable Exception class
Now will explain the flow of this tool:
The chirpd command (bash script) validates the passed arguments and if valiation passes, it calls the chirp-data-tool.jar. If it fails it echos a message as to why it failed. When it succeeds, it executes thejavacommand as:
java -jar /usr/local/bin/chirp-data-tool.jar "$command" "$rootpath" "$daysold" "$excludedfilenames" "$considerweekends" "$propertyfile" "$logfile" "$talkativeness"
The biggest part of this application with only one line of code! is:
Collection files = FileUtils.listFiles(rootPathFile, null, true);
FileUtilsis a part of the
org.apache.commons.io.FileUtilspackage. Two other way the command runs is help mode
chirpd -hwhich prints the help and
chirpd -vwhich prints the command version.
For more information regarding this tool and to use it, download the code.
Hope you find this useful!
Cheers!
Comments
Post a Comment