ASNMTAP
view release on metacpan or search on metacpan
applications/archive.pl view on Meta::CPAN
#!/usr/bin/env perl
# ---------------------------------------------------------------------------------------------------------
# © Copyright 2003-2011 Alex Peeters [alex.peeters@citap.be]
# ---------------------------------------------------------------------------------------------------------
# 2011/mm/dd, v3.002.003, archive.pl for ASNMTAP::Applications
# ---------------------------------------------------------------------------------------------------------
use strict;
use warnings; # Must be used in test mode only. This reduces a little process speed
#use diagnostics; # Must be used in test mode only. This reduces a lot of process speed
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BEGIN { if ( $ENV{ASNMTAP_PERL5LIB} ) { eval 'use lib ( "$ENV{ASNMTAP_PERL5LIB}" )'; } }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
use DBI;
use Time::Local;
use Getopt::Long;
use Date::Calc qw(Date_to_Time Monday_of_Week);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
use ASNMTAP::Time v3.002.003;
use ASNMTAP::Time qw(&get_epoch &get_wday &get_yearMonthDay &get_year &get_month &get_day &get_week);
use ASNMTAP::Asnmtap::Applications v3.002.003;
use ASNMTAP::Asnmtap::Applications qw(:APPLICATIONS :ARCHIVE :DBARCHIVE $SERVERTABLPLUGINS $SERVERTABLVIEWS $SERVERTABLDISPLAYDMNS $SERVERTABLCRONTABS $SERVERTABLCLLCTRDMNS $SERVERTABLSERVERS );
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
use vars qw($opt_A $opt_c $opt_r $opt_d $opt_y $opt_f $opt_D $opt_V $opt_h $PROGNAME);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$PROGNAME = "archive.pl";
my $prgtext = "Archiver for the '$APPLICATION'";
my $version = do { my @r = (q$Revision: 3.002.003$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; # must be all on one line or MakeMaker will get confused.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $doCgisess = 1; # default
my $doReports = 1; # default
my $doDatabase = 0; # default
my $doYearsAgo = -1; # default
my $doForce = 0; # default
my $debug = 0; # default
#------------------------------------------------------------------------
# Don't edit below here unless you know what you are doing. -------------
#------------------------------------------------------------------------
my $archivelist;
my $gzipDaysAgo = 8; # GZIP files older then n date
my $gzipDebugDaysAgo = 3; # GZIP files older then n days ago
my $removeGzipDaysAgo = 31; # Remove files older then n days ago
my $removeAllNokDaysAgo = 8; # Remove files older then n days ago
my $removeDebugDaysAgo = 31; # Remove files older then n days ago
my $removeGzipWeeksAgo = 53; # Remove files older then n weeks ago
my $removeCgisessDaysAgo = 2; # Remove files older then n days ago
my $removeReportWeeksAgo = 53; # Remove files older then n weeks ago
my $gzipEpoch = get_epoch ('-'. $gzipDaysAgo .' days'); # GZIP files older then n date
my $gzipDebugEpoch = get_epoch ('-'. $gzipDebugDaysAgo .' days'); # GZIP files older then n date
my $removeAllNokEpoch = get_epoch ('-'. $removeAllNokDaysAgo .' days'); # Remove files older then n days ago
my $removeGzipEpoch = get_epoch ('-'. $removeGzipDaysAgo .' days'); # Remove files older then n days ago
my $removeDebugEpoch = get_epoch ('-'. $removeDebugDaysAgo .' days'); # Remove files older then n days ago
my $removeWeeksEpoch = get_epoch ('-'. $removeGzipWeeksAgo .' weeks'); # Remove files older then n weeks ago
my $removeCgisessEpoch = get_epoch ('-'. $removeCgisessDaysAgo .' days'); # Remove files older then n days ago
my $removeReportsEpoch = get_epoch ('-'. $removeReportWeeksAgo .' weeks'); # Remove files older then n weeks ago
my ( $week, $year ) = get_week('yesterday');
( $year, my $month, my $day ) = Monday_of_Week($week, $year);
my $firstDayOfWeekEpoch = Date_to_Time ($year, $month, $day, 0, 0, 0); # First day current week epoch date
my $yesterdayEpoch = get_epoch ('yesterday'); # Yesterday epoch date
my $currentEpoch = get_epoch ('today'); # time() or Current epoch date
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions (
"A:s" => \$opt_A, "archivelist:s" => \$opt_A,
"c:s" => \$opt_c, "cgisess:s" => \$opt_c,
"r:s" => \$opt_r, "reports:s" => \$opt_r,
"d:s" => \$opt_d, "database:s" => \$opt_d,
"y:s" => \$opt_y, "yearsago:s" => \$opt_y,
"f:s" => \$opt_f, "force:s" => \$opt_f,
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"D:s" => \$opt_D, "debug:s" => \$opt_D,
"V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h
);
if ($opt_V) { print_revision($PROGNAME, $version); exit $ERRORS{OK}; }
if ($opt_h) { print_help(); exit $ERRORS{OK}; }
if ($opt_A) { $archivelist = $1 if ($opt_A =~ /([-.A-Za-z0-9]+)/); }
if ($opt_c) {
if ($opt_c eq 'F' || $opt_c eq 'T') {
$doCgisess = ($opt_c eq 'F') ? 0 : 1;
} else {
usage("Invalid cgisess: $opt_c\n");
}
( run in 0.620 second using v1.01-cache-2.11-cpan-13bb782fe5a )