FileMgmt A platform independent
file management utility
from R.K.Raja (rajkanna_hcl@yahoo.com)
FileMgmt is a platform independent file management utility. The goal is to ease the life of the system administrator in managing the files on the system and for high system availability. It has been designed and developed from the scratch keeping the characteristics like lightweight, maintainability and extensibility in mind. Its design was originally inspired from the linux logrotate file rotation utility.
Features:
FileMgmt provides almost all the features that logrotate provides. In addition to that it also has the following capabilities:
Setting up FileMgmt:
Configuration file
format:
<!-- Root element ΰ
<filemgmt>
<!-- Define all
global directives here ΰ
<!
List all the files to be managed here.
Multiple filenames should be delimited with comma
ΰ
<file names="">
<!-- Define all file specific directives here ΰ
</file>
</filemgmt>
Supported directives:
1. Directive to instruct
FileMgmt to send email notification with attachment
<email server= port= from=
to= subject= body= attachfile=/>
No version:
<noemail/>
2. Directive to
instruct FileMgmt to compress the rotated file
<compress/>
No version:
<nocompress/>
3. Directive to
instruct FileMgmt to just take a copy of the original
file.
<copy/>
No version:
<nocopy/>
4. Directive to
instruct FileMgmt to first copy the original file and
then truncate it.
<copytruncate
length=/>
No version:
<nocopytruncate/>
5. Directive to
instruct FileMgmt to keep this much number of backup
copies
<old count=/>
No version:
<noold/>
6. Directive to
instruct FileMgmt to include the file specified.
<include name=""/>
7. Directive to
instruct FileMgmt to do pre/post operation only once
for the entire
list of files specified in 'names' attribute in 'file' element.
<sharedscript/>
No version:
<nosharedscript/>
8. Directive to
instruct FileMgmt to run the commands during pre
operation.
<prescript>
<! List of
commands to be executed ΰ
</prescript>
No version:
<noprescript/>
9. Directive to
instruct FileMgmt to run the commands during post operation.
<postscript>
<!List
of commands to be executed ΰ
</postscript>
No version:
<nopostscript/>
11. Directive to
instruct FileMgmt to manage file based on the file
size.
<size value=""/>
Where:
value : File size in bytes
No version:
<nosize/>
Configuration
examples:
1. FileMgmtConfig.xml
<filemgmt>
<file names="d:\\temp\\test.pdf">
<email server="smtp-server" port="25"
to="rajkanna_hcl@yahoo.com"
from="rajkanna_hcl@yahoo.com"
subject="test
subject" body="test body"
attachfile="true"/>
<size
value="204800"/>
</file>
</filemgmt>
The above configuration file instructs FileMgmt to send an email notification with attachment when the size of d:\temp\test.pdf exceeds 200K at the time FileMgmt runs.
Sample run:
D:\> java -classpath ".;./lib/xercesImpl.jar;./lib/xml-apis.jar" FileMgmt -v -c FileMgmtConfig.xml
INFO: Platform: Windows
INFO: Temp directory: D:\DOCUME~1\rajkanna\LOCALS~1\Temp\
INFO: Parsing 'FileMgmtConfig.xml'
INFO: Total number of config file(s) parsed and validated: 1
INFO: Total number of file(s) to process: 1
INFO: Number of jobs: 1, jobs per thread: 1 (Max threads: 5)
INFO: Threads started: 1
INFO: Processing file 'd:\\temp\\test.pdf'
INFO: File 'd:\\temp\\test.pdf' needs to be rotated (size exceeded).
INFO: Compressing 'd:\\temp\\test.pdf'.
INFO: Sending email to 'rajkanna_hcl@yahoo.com' (attachment: true).
INFO: Attachment enclosed.
INFO: Executing postscript for 'd:\\temp\\test.pdf'.
D:\>
2. FileMgmtConfig.xml
<filemgmt>
<compress/>
<sharedscript/>
<file names="d:\\temp\\test.pdf, d:\\temp\\test1.pdf">
<copy/>
<size
value="204800"/>
<postscript>
uname -a
</postscript>
</file>
</filemgmt>
The above configuration file instructs FileMgmt to just copy d:\temp\test.pdf and d:\temp\test1.pdf if their size exceeds 200K when the time FileMgmt runs. It also instruct FileMgmt to compress the backup copy and the postscript to be executed only once (sharedscript).
Sample run:
D:\> java -classpath ".;./lib/xercesImpl.jar;./lib/xml-apis.jar" FileMgmt -v -c FileMgmtConfig.xml
INFO: Platform: Windows
INFO: Temp directory: D:\DOCUME~1\rajkanna\LOCALS~1\Temp\
INFO: Parsing 'FileMgmtConfig.xml'
INFO: Total number of config file(s) parsed and validated: 1
INFO: Total number of file(s) to process: 2
INFO: Number of jobs: 1, jobs per thread: 1 (Max threads: 5)
INFO: Threads started: 1
INFO: Processing file 'd:\\temp\\test.pdf'
INFO: File 'd:\\temp\\test.pdf' needs to be rotated (size exceeded).
INFO: Copying 'd:\\temp\\test.pdf' to 'd:\\temp\\test.pdf.zip.1'.
INFO: Backup copy compressed.
INFO: Processing file 'd:\\temp\\test1.pdf'
INFO: File 'd:\\temp\\test1.pdf' needs to be rotated (size exceeded).
INFO: Copying 'd:\\temp\\test1.pdf' to 'd:\\temp\\test1.pdf.zip.1'.
INFO: Backup copy compressed.
INFO: Executing postscript for 'd:\\temp\\test1.pdf'.
D:\>
Send your comments to: R.K.Raja (rajkanna_hcl@yahoo.com, rajark_hcl@yahoo.co.in)