Squid Rotate
13.7 Rotating the Log Files – eTutorials.org
Squid always appends new entries to its log
files. If your cache is busy, some of these files can become very
large after a few days. Some operating systems even place limits on
the size of a file (e. g., 2 GB) and return an error for writes beyond
that size. To keep your log files manageable, and Squid happy, you
must regularly rotate them.
Squid has a built-in feature for rotating log files. You can invoke
it with the squid -k rotate command. You then tell
Squid how many old copies of each file to keep with the
logfile_rotate directive. For example, if you
set it to 7, you’ll have eight versions of each log
file: the current file and seven old ones.
Old log files are renamed with numeric extensions. For example, when
you execute a rotation, Squid renames log. 6 to
log. 7, then log. 5 to
log. 6, and so on. The current
log becomes log. 0, and
Squid creates a new, empty file named log.
Each time you execute squid -k rotate, Squid
rotates the following files:,,,
(if enabled), and
(if enabled). Squid also creates
up-to-date versions of the files.
Note, however, that
isn’t archived with numeric extensions.
Squid doesn’t rotate the log files automatically.
The best way to make it happen is with a daily
cron job. For example:
0 0 * * * /usr/local/squid/sbin/squid -k rotate
If you’d rather write your own scripts to manage the
log files, Squid has a special mode that you’ll find
useful. Simply set the logfile_rotate directive
to 0. Then, when you run squid -k
rotate, Squid simply closes the current log files and opens
new ones. This is very useful when the operating system allows you to
rename files opened by another process. The following shell script
illustrates the idea:
#! /bin/sh
set -e
yesterday_secs=`perl -e ‘print time -43200’`
yesterday_date=`date -r $yesterday_secs +%Y%m%d`
cd /usr/local/squid/var/logs
# rename the current log file without interrupting the logging process
mv $yesterday_date
# tell Squid to close the current logs and open new ones
/usr/local/squid/sbin/squid -k rotate
# give Squid some time to finish writing files
sleep 60
mv $yesterday_date /archive/location/
gzip -9 /archive/location/$yesterday_date
logfile_rotate configuration directive – Squid-cache.org
Squid configuration directive logfile_rotate
Available in: v6 v5 v4 3. 5 3. 4 3. 3 3. 2 2. 7 3. 1 3. 0 2. 6
For older versions than 3. 5 see the linked pages aboveConfiguration Details:
Option Name:logfile_rotate
Replaces:
Requires:
Default Value:logfile_rotate 10
Suggested Config:
Specifies the default number of logfile rotations to make when you
type ‘squid -k rotate’. The default is 10, which will rotate
with extensions 0 through 9. Setting logfile_rotate to 0 will
disable the file name rotation, but the logfiles are still closed
and re-opened. This will enable you to rename the logfiles
yourself just before sending the rotate signal.
Note, from Squid-3. 1 this option is only a default for,
that log can be rotated separately by using debug_options.
Note, from Squid-4 this option is only a default for
recorded by stdio: module. Those logs can be rotated separately by
using the rotate=N option on their access_log directive.
Note, the ‘squid -k rotate’ command normally sends a USR1
signal to the running squid process. In certain situations
(e. g. on Linux with Async I/O), USR1 is used for other
purposes, so -k rotate uses another signal. It is best to get
in the habit of using ‘squid -k rotate’ instead of ‘kill -USR1
Back
Introduction
About Squid
Why Squid?
Squid Developers
How to Donate
How to Help Out
Getting Squid
Squid Source Packages
Squid Deployment Case-Studies
Squid Software Foundation
Documentation
Configuration:
Reference
Examples
FAQ and Wiki
Guide Books:
Beginners
Definitive
Non-English
More…
Support
Security Advisories
Bugzilla Database
Mailing lists
Contacting us
Commercial services
Project Sponsors
Squid-based products
Miscellaneous
Developer Resources
Related Writings
Related Software:
AuthenticatorsEcapIcapIdentLog AnalysisMonitorProxiesRedirectors General
Squid Artwork
Web Site Translations
Japanese
Mirrors
Website:
gr
il
jp
pl… full list
FTP Package Archive
5.10 Rotating the Log Files :: Chapter 5. Running Squid
Squid writes to a number of log files unless you disable them in
You must periodically
rotate the log files to prevent them from
consuming too much disk space. Squid places a lot of importance on
log files and exits with an error message when it
can’t write to them. To keep disk space consumption
under control, use the following command in a
cron job:% squid -k rotate
For example, this crontab entry rotates the logs
every 24 hours, at 4 A. M. :
0 4 * * * /usr/local/squid/sbin/squid -k rotate
This command does two things. First, it closes the currently open log
files. Then, it renames the,, and
files by appending a numeric extension. For example,
becomes,
becomes, and so on, up to the value
of the logfile_rotate option.
Squid keeps only the last logfile_rotate
versions of each log file. The older versions are simply removed
during the renaming process. If you want to keep more copies, you
need to increase the logfile_rotate limit or
write some custom scripts that move the log files to a different
location.
See Section 13. 7 for additional information about
rotating log files.