2

On my servers I have log rotation and a backup script which, besides all, backs up the entire log directory.

For log rotation I use logroatate on Linux and newsyslog is used on BSD. For log backup I simply cp -Rf /var/log/ /backups/

From time to time the backup script fails because of a race condition occurring when log rotation renames a log file during the backup is running. So I get something like:

cp: /var/log/messages.0: No such file or directory

I believe my situation is not unique. Are there any best practices to overcome this race condition and make backup more reliable?

1 Answers1

3

It doesn't look like logrotate provides anything that you can hook into (e.g. a pid file) to solve this problem so you'll need to work around it.

I would look into using flock(1) which is available for Linux and BSD.

You can have the logrotate script create a lock and then have the backup script check for and wait on the lock.

user9517
  • 114,104
  • 20
  • 206
  • 289