File::Maintenance - Maintain files based on their age.
Version 0.02
This module allows you to purge files from a directory based on age
use File::Maintenance; my $fm = File::Maintenance->new({ directory => '/tmp', pattern => '*.sess', age => '5d', #older than five days }); $fm->test(1); # don't execute the purge $fm->purge; # prints the action to STDOUT but doesn't purge files $fm->test(0); # It's all for real $fm->purge; # Will delete old *.sess files from /tmp $fm->recurse(1); $fm->purge; # Will delete old *.sess files from /tmp and sub-directories
You can also archive files (move to another directory) based on age as well
use File::Maintenance; my $fm = File::Maintenance->new({ directory => '/my/data/files', archive_directory => '/my/archive/files' pattern => '*', recurse => 1, # subdirectories too age => '30m' # older than 30 minutes }); $fm->archive;
Each value passed to the constructor has a corresponding method for setting the value, so the archive above could have been written as:
use File::Maintenance; my $fm = File::Maintenance->new(); $fm->directory('/my/data/files'); $fm->archive_directory('/my/archive/files); $fm->pattern('*'); $fm->recurse(1); $fm->age('30m); $fm->archive;
Instead of purging, files can be compressed with either zip, gzip or bzip2 formats:
$fm->zip;
or
$fm->gzip;
$fm->bzip2;
The root directory for purging
$fm->directory('/tmp');
The pattern mask for files to process
$fm->pattern('backup*.tar.gz');
By default, the pattern is a glob. To use a regular expression, it must be quoted with the qr operator:
$fm->pattern(qr/^(foo|bar)\d\d\.jpg$/);
The directory that files will be archived to. If the recurse attribute is set, the archive directory hierarchy will match the source directory hierarchy
Files older than the age will either be archived or purged, depending on the requested action. The age can be specified by s, m, h or d - (seconds, minutes, hours or days)
$fm->age('1d'); # Files older than 1 day $fm->age('4h'); # Files older than 4 hours
Whether to traverse subdirectories
Delete files older than age
Compresses files older than age using the gzip format
Compresses files older than age using the zip format
Compresses files older than age using the bzip2 format
Archive files older than age
Return an array of files that match the filter criteria. This method is used internally, but is useful enough to be offered externally
Dan Horne, <dhorne at cpan.org>
<dhorne at cpan.org>
Please report any bugs or feature requests to bug-file-purge at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Maintenance. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-file-purge at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc File::Maintenance
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/File-Maintenance
CPAN Ratings
http://cpanratings.perl.org/d/File-Maintenance
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-Maintenance
Search CPAN
http://search.cpan.org/dist/File-Maintenance
Copyright 2008 Dan Horne, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install File::Maintenance, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Maintenance
CPAN shell
perl -MCPAN -e shell install File::Maintenance
For more information on module installation, please visit the detailed CPAN module installation guide.