1

I'm using Debian Stretch on my server. Here is the relevant portion of etc/logrotate.d/rsyslog:

/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
{
        rotate 4
        weekly
        missingok
        notifempty
        compress
        delaycompress
        sharedscripts
        postrotate
                invoke-rc.d rsyslog rotate > /dev/null
        endscript
}

After there are four logfiles for mail.log, the oldest file is deleted. This is fine, but I want to transfer the file via scp to a remote server before it's deleted.

How would I go about this?

Thanks!

1 Answer 1

2

A prerotate block can do this. The simplest form would be

prerotate
   scp mail.log.4.gz user@remotehost:
endscript
5
  • If the final goal is to have all the files on the other machine, copying *.log.1.gz right after it's created will work just as well (and fewer logs will be lost is the machine goes tits up).
    – xenoid
    Commented Dec 7, 2017 at 11:06
  • Thanks Chris & xenoid! I'll test this out and let you know how it goes. And you're right, xenoid, that would make more sense to export them right away.
    – pkSML
    Commented Dec 8, 2017 at 4:09
  • Another question... Since my logrotate block specifies multiple files, I assume this block will execute 4 times when logrotate is run. Does that mean the prerotate block will run four times (and thus try to upload the file four times)???
    – pkSML
    Commented Dec 8, 2017 at 5:10
  • @pkSML the sharedscripts directive means that the prerotate only executes once even if there are multiple files - see serverfault.com/questions/744062/… for some discussion (and logrotate man pages)
    – Chris Hill
    Commented Dec 8, 2017 at 11:54
  • @ChrisHill Thanks for the clarification! I read that link and I'll definitely check into the man pages. When next week begins, I expect I'll see the uploaded file sent to me!
    – pkSML
    Commented Dec 8, 2017 at 12:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .