NAME

XAS::Apps::Rotate - Rotate files based on a config file

SYNOPSIS

 use XAS::Apps::Rotate;

 my $app = XAS::Apps::Rotate->new(
    -throws   => 'rotate',
    -facility => 'systems',
    -priority => 'warn',
 );

 exit $app->run;

DESCRIPTION

This module is used to rotate files.

CONFIGURATION

The configuration file uses the standard windows .ini file. It has the following format.

 [settings]
 compressor = zip         - default file compressor
 zip-command              - zip command defaults to 'c:\bin\zip.exe'
 gzip-command             - gzip command defaults to 'c:\bin\gzip.exe'
 bzip2-command            - bzip2 command defaults to 'c:\bin\bzip2.exe'
 compress-command         - compress command defaults to 'c:\bin\compress.exe'
 tail-command             - tail command defaults to 'c:\bin\tail.exe'

 [log\test.log]           - file to process, may have DOS wildcards
 compress = true          - wither to compress the file
 method = move            - how to handle the file
 missingok = false        - whither a missing file is OK
 lines-or-files = files   - 
 create-new = false       - create a new file after rotation
 modify-age               - process based on last modification
 create-age               - process based in creation time
 file-size                - process based on file size
 ifempty                  - process if file is empty
 file-count               - number of rotated files kept
 line-count               - how many line to transfer to new file
 prolog                   - command to process before rotation
 epilog                   - command to process after rotation
 pause                    - number of seconds to pause after prolog and epilog

METHODS

main

Process the configuration file.

run_cmd($cmd)

Run a command and capture the output to the log file.

$cmd

The command to run.

get_extension

Return the file extension base on compressor type.

is_true($param)

Return TRUE or FALSE based on $param. If $param is 'true', or 1 then TRUE.

is_false($param)

Return TRUE or FALSE based on $param. If $param is 'false' or 0 then TRUE.

is_older($age_diff, $age)

Parses $age_diff and checks to see if the $age is newer than the current time minus $age_diff. That is we return TRUE if a file is too new based on the criteria $age_diff and $age and the implicit parameter: the current time.

is_bigger($size_spec, $size)

Parses $size_spec and checks to see if the $size is bigger than that. We return TRUE if a file is too big.

compress_file($filename)

Compress the file based on chosen compression type.

$filename

The file to compress

recreate_file($filename)

Recreate the file if needed. This checks the file-or-line config item. If it is 'file' then a new file is created, if it is 'lines' then the config item 'line-count' is used to copy that number of lines from the end of the file into the beginning of the new file.

$filename

The file to recreate.

rotate_file($filename)

Perform the basic file rotation.

$filename

The file to rotate.

process_files

Process the selected files. It preforms the following actions:

1 Process the prolog command.
2 Rotate the file.
3 Recreate the new file.
4 Compress the rotated file
5 Process the epilog command.

find_files

Scan the local directory looking for files to rotate.

SEE ALSO

Rotate

AUTHOR

Kevin L. Esteb, <kevin@kesteb.us>

COPYRIGHT AND LICENSE

Copyright (C) 2014 Kevin L. Esteb

TThis is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.