How does one manually rotate log without logrotate on open/live file

logginglogrotatesyslog

My Google-Fu is getting me so close but just not quite there, and I guess I'm too green in Linux to put the pieces together.

I have a very large >200GB log file, still being written to. Logrotate wont get to it in time before disk space could be a concern. Also, I don't want to fire off another round of logrotate, because I don't want it to effect all the other targets in its config. I have added the new stanza in my logrotate.conf file as such:

/log/myDevice/myDevice.log {
  compress
  daily
  rotate 360
  maxage 360
  missingok
  compresscmd /usr/bin/xz
  dateext
  compressext .xz
  copytruncate
  olddir /log/archive/myDevice
}

I would like to do these things manually:

  1. copytruncate : to grab off the current log file, but allow syslog-ng to keep chugging along on the current open/live file
  2. (not above in the logrotate.conf) split : to break up the current log roll into smaller chunks
  3. xz : compress over to archive folder

I can split(1) and xz(1) just fine, but when I try to grab off the target file, no dice.

I tried sudo mv myDevice.log ZmyDevice.log && touch myDevice.log, but syslog-ng just moves with the original file (and its new name) and keeps writes merrily away. Which made a bit of since when I thought about how the file is being referenced by syslog-ng.

So I'm trying to figure out how to do some sort of a manual copytruncate in order to cut the file to another one "in place" as it were, and let syslog-ng keep chugging away at what it wants.

Best Answer

Move the file, then send a SIGHUP to the syslog-ng process:

kill -HUP

which will cause it to re-open all it's open files, thus releasing the file you just moved/renamed and allowing you to carry on. It'll then open /log/myDevice/myDevice.log fresh and start writing to that.