I'm working on an apache logs analyser, it requires the apache log files to be imported into a directory for processing. I cannot simply point it to the apache logs directory as it imports each file before deleting it. It also has no concept of duplicate records, so I cannot set up a cron to copy /var/log/apache2/*
into the folder.
I assume logrotate is the best place to do this, but I don't have a clue where to start to configure it. So my question is:
How can I configure logrotate to SSH rotated apache log files to a remote host automatically?
The alternative is to copy locally and run scp
& rm
via cron, but a one-step SSH process would be nice.
Look at the
prerotate
andpostrotate
configuration options (examples inman logrotate
). You could for instance have a prerotate that scps the file (make sure you configure SSH keys properly; your root user should be able to ssh to the target system without needing a password). This would copy the access.log file before rotating (renaming, compressing, etc) it.Note that in this case you would lose any accesses that happen between the copying of the file and the rotation step, so you could also put this in the postrotate section but copy access.log.1 instead.
in /etc/logrotate/apache2 (this may be different, I only have access to a Debian system) you can add the prerotate section so the contents of the file look like this: