2 ##--------------------------------------------------------------------------##
4 ## $Id: compress-files,v 1.8 2002/09/15 03:33:08 ehood Exp $
6 ## Gzip files matching a specified pattern and older then specified
8 ##--------------------------------------------------------------------------##
9 ## Copyright (C) 2001-2002 Earl Hood <earl@earlhood.com>
11 ## This program is free software; you can redistribute it and/or modify
12 ## it under the terms of the GNU General Public License as published by
13 ## the Free Software Foundation; either version 2 of the License, or
14 ## (at your option) any later version.
16 ## This program is distributed in the hope that it will be useful,
17 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ## GNU General Public License for more details.
21 ## You should have received a copy of the GNU General Public License
22 ## along with this program; if not, write to the Free Software
23 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ##--------------------------------------------------------------------------##
27 package MHArc
::compress_files
;
29 ##--------------------------------------------------------------------------##
31 BEGIN { die qq/CGI use FORBIDDEN!\n/ if (defined($ENV{'GATEWAY_INTERFACE'})); }
32 my $Dir; BEGIN { $Dir = `dirname $0`; chomp $Dir; }
33 use lib
"$Dir/../lib"; # Add relative lib to search path
35 ##--------------------------------------------------------------------------##
40 use MHArc
::Util
qw( usage );
42 # Amount of seconds in a year
43 my $year_secs = 31536000;
46 my $clstatus = GetOptions
(\
%opt,
56 usage
(0) unless $clstatus;
57 usage
(1) if $opt{'help'};
58 usage
(2) if $opt{'man'};
60 my $debug = $opt{'debug'};
61 my $mbox_mode = $opt{'mbox-mode'};
62 my $pattern = $opt{'pattern'} || ($mbox_mode ?
'^\d+(?:-\d+)?$' : '^[^.]');
63 my $compress_time = $opt{'mtime'} || 31;
64 my $noact = $opt{'n'};
67 $compress_time *= 24 * 3600; # convert to seconds
73 print qq/Ignoring "$File::Find::name"\n/ if $debug;
77 my $mtime = (stat($_))[9];
78 print qq/$File::Find::name (/, scalar(localtime($mtime)), qq/)\n/ if $debug;
80 if ($mbox_mode && (/^\d+$/)) {
81 if ($time-$mtime < ($compress_time+$year_secs)) {
82 print qq/Skipping "$File::Find::name"\n/ if $debug;
85 } elsif ($time-$mtime < $compress_time) {
86 print qq/Skipping "$File::Find::name"\n/ if $debug;
90 print qq/Compressing "$File::Find::name"\n/ if $debug;
92 print qq/gzip $File::Find::name\n/;
94 if (system('gzip', $_)) {
95 die qq/gzip $File::Find::name failed: $?\n/;
101 die qq/No directories, or files, specified\n/;
103 find
(\
&wanted
, @ARGV);
105 ##---------------------------------------------------------------------------##
110 compress-files - Gzip files not modified over a given period of time
114 compress-files [options] <directory> [<directory> ...]
118 This program is part of mharc. This program is used to compress
119 files that have not been modified over a given period of time.
127 Print out alot of status information.
131 Print out usage information.
135 Print the commands that would be executed, but do not execute them.
139 A hack for compress mailbox files. When this option is specified,
140 the default C<-pattern> is C<^\d+(?:-\d+)?$>. This pattern basically
141 searches for files with names in YYYY and YYYY-MM format. Files with
142 names in YYYY format are handled slightly different. When checking
143 if the file can be compressed, a year is added to C<-mtime>.
149 =item C<-mtime> I<days>
151 Modification time in days a file has to be older than to get compressed.
152 If this option is not specified, 31 days is used.
154 =item C<-pattern> I<regex>
156 Perl regular expression that represents files that should be
157 checked. If not specifed, the following regex is used:
164 L<compress-mboxes|compress-mboxes>
168 $Id: compress-files,v 1.8 2002/09/15 03:33:08 ehood Exp $
172 Earl Hood, earl@earlhood.com
174 This program is part of the mharc archiving system and comes with
175 ABSOLUTELY NO WARRANTY and may be copied only under the terms of
176 the GNU General Public License, which may be found in the mharc