Weblog entry #8 for lee
error: /etc/logrotate.d/local-apache-vhosts:8 unknown option 'dateext' -- ignoring line
Argh. I'd written a logrotate job to rotate example.com_access.log to example.com_access.log-20060115.gz. I need for the naming to be consistant since the directory gets rsynced onto another server, and the naming needs to be alphanumerically in order, so as not to confuse the web stats program. But stupidly, I now find the dateext option isn't supported by the logrotate in sarge (3.7-5) and the first version to support it (3.7.1-1) was uploaded two months later.
Attempting to replicate it using something like "extension `date --date='-1 day' +%Y%m%d`" doesn't work.
Does anyone know any sarge backport for logrotate before I build it myself? (noting that apt-build doesn't seem to work... sigh.)
Otherwise, one possible workaround is to use something like the following:
postrotate
EXT=`date --date='-1 day' +%Y%m%d`
for f in $1; do
mv $f.1 $f-$EXT; /bin/gzip -f $f-$EXT
done
endscript
Comments on this Entry
[ Send Message | View Steve's Scratchpad | View Weblogs ]
Try this local one I made:http://www.steve.org.uk/apt/local/
It isn't in my proper repository, but you should be able to rebuild it easily if you really wish.
[ Parent | Reply to this comment ]
Thanks Steve, that seems to be working.
I've now begun the task of renaming the existing access_log.5.gz logs to match this new naming scheme.
The following is a quick perl script that renumbers based on the mtime minus 24 hours.
#!/usr/bin/perl
use POSIX qw(strftime);
use File::stat;
while(<>) {
$file = $_;
chomp($file);
if ($file =~ /(.*).(\d+)\.gz/) {
$date = stat($file)->mtime;
$output = strftime "%Y%m%d", localtime($date - 86400) ;
printf "mv \"%s\" \"%s-%s.gz\"\n", $file, $1, $output;
} else {
printf "# %s not matched\n", $file;
}
}
[ Parent | Reply to this comment ]
Can't edit comments, but there's a backslash missing in the regexp...
if ($file =~ /(.*)\.(\d+)\.gz/) {
[ Parent | Reply to this comment ]
#!/usr/bin/perl
use POSIX qw(strftime);
use File::stat;
use Cwd;
my $working_dir = cwd;
opendir( DIR, $working_dir ) || die "can't open dir $working_dir";
my @files = readdir(DIR);
print @files;
closedir( DIR );
foreach ( @files ) {
if( $_ =~ /(.*)\.(\d+)\.gz/ ) {
$date = stat( $_)->mtime;
$output = strftime "%Y%m%d", localtime($date - 86400) ;
printf "mv \"%s\" \"%s-%s.gz\"\n", $_, $1, $output;
} else {
printf "# %s not matched\n", $_;
}
}
[ Parent | Reply to this comment ]