The savelogs program rotates logs, optionally saving the old ones elsewhere and signalling the programs that created the logfiles.
/etc/savelogs.conf
tells savelogs which logs to rotate, when to rotate
them, whether to back them up, and what to do after a log is rotated.
The format of the configuration file is a filename, followed by a list
of commands, with punctuation and case ignored:
every
{day
|week
|year
}
Rotate the log at this time. If you tell it WEEK (YEAR),
the rotation will happen on a sunday (the last sunday of the year).
save
n in
directory
Save n old logs in the named directory as o.
logfile.
Any existing o.
file will
be renamed to oo.
file to accomodate the
new file (so the old o.log
becomes
oo.log
, and so on), up to the number of files you want to save.
touch
mode
After rotating the old log, create a
new (empty) log with the given mode.
size
size
Rotate the log if it gets larger than this size. If you suffix
the size with K, the size is in kilobytes, and a M
suffix means megabytes.
signal
action
After rotating a log and touch
ing it,
run this command. savelogs
attempts to batch signal
, so that if multiple logs
are rotated the actions will only be executed once.
For example, the following configuration file
/var/adm/syslog EVERY WEEK
SAVE 2 IN /var/adm/OLD
TOUCH 644
SIGNAL "killall -HUP syslogd"
Rotates /var/adm/syslog
every sunday, creating a
new empty file with mode 644, saving two of the old logs in
/var/adm/OLD
, and sending a HUP signal
to syslogd
after it’s finished.
Many many many feature changes
In addition, the code has been ported to more systems, from recent versions of freebsd (macos, to be precise) to modern commercial linuxes.
SIGNAL
s per file, so I can
do something like rotate many syslogs, hup syslogd,
then hup a cwatch process if and
only if /var/log/messages
was one of those syslogs. I also
made the code more portable by fitting it out with my
autoconfiguration scripts.
Savelogs now properly builds on pell, which is an SLS
Linux system, egypt, which is my primary
Mastodon
build box, and downbelow, which runs an elderly version
of FreeBSD.