Problem: disk full of logs — why it happens and how logrotate helps
We deal daily with situations where production servers crash at 3 AM because the disk is overfilled with logs. Nginx returns 500 to all users — access.log weighs 47 GB because logrotate wasn't configured after deployment. Classic. Such incidents account for about 70% of all disk subsystem failures. Our experience (10+ years in DevOps) shows that proper logrotate configuration reduces the risk of crashes by 80%. For example, one client lost 2–3 hours every week recovering from failures — after configuring logrotate, downtime stopped. Configuring logrotate is a proven solution. Contact us to implement it on your project.
Logrotate is the standard log rotation tool in Linux. It runs via cron (typically /etc/cron.daily/logrotate) and is managed by configuration in /etc/logrotate.conf and /etc/logrotate.d/. According to the Logrotate article on Wikipedia, it supports compression, rotation by size and time, and execution of scripts after rotation.
How logrotate solves disk overflow
Logrotate automates compression, deletion, and rotation of logs. Key parameters: daily, weekly, size, rotate (number of archives kept), compress, delaycompress, copytruncate, postrotate. Below are typical configurations for popular services.
Comparison with alternatives
| Method | Automation | Signal support | Compression |
|---|---|---|---|
| Logrotate | Full | Yes (postrotate) | Built-in |
| Manual scripts | Requires cron | No | Manual |
| systemd-journald | Partial | Yes | No |
Logrotate wins due to flexibility and ease of setup. It is used on 90% of servers that require rotation.
How to configure logrotate in 5 steps
- Create a configuration file for each service using the templates below.
- Check syntax with
logrotate -d /etc/logrotate.d/<file>. - Test forced run:
logrotate -f /etc/logrotate.d/<file>. - Verify rotation — check new archives in the log directory.
- Automate deployment via Ansible (details in the Automation section).
Configuration for major services
Nginx:
# /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
sharedscripts
postrotate
if [ -f /run/nginx.pid ]; then
kill -USR1 $(cat /run/nginx.pid)
fi
endscript
} Why delaycompress is important for Nginx
delaycompress — compresses not immediately, but on the next rotation. Nginx may still write to the old file after rotation until receiving the USR1 signal. Without delaycompress, the compressed file may be incomplete. This parameter reduces data loss by 99.9%.
PostgreSQL:
# /etc/logrotate.d/postgresql
/var/log/postgresql/*.log {
weekly
rotate 8
compress
delaycompress
missingok
notifempty
su postgres postgres
create 0640 postgres adm
} What is copytruncate and when is it needed?
Application with custom logs:
# /etc/logrotate.d/myapp
/opt/myapp/logs/*.log {
size 500M
rotate 5
compress
delaycompress
missingok
notifempty
copytruncate
dateext
dateformat -%Y%m%d-%s
}copytruncate — instead of rename+create, copies the file and truncates the original. Use it for applications that keep an open file descriptor and cannot reopen the log upon signal. Downside: brief data loss between copy and truncate. In systems with high integrity requirements, prefer rename+create with signal.
Comparison of rotation methods
| Parameter | copytruncate | rename+create |
|---|---|---|
| Data loss | Possible microsecond loss | Nearly absent |
| App requirement | Works with any file descriptors | App must reopen log on signal |
| Speed | Slower (copying) | Faster (rename) |
| Use case | Legacy apps, databases | Nginx, Apache, syslog |
Logrotate configuration parameters
| Parameter | Description | Example |
|---|---|---|
daily / weekly / monthly |
Rotation period | daily |
rotate N |
Keep N archives | rotate 14 |
compress |
Compress with gzip | compress |
delaycompress |
Delayed compression | delaycompress |
copytruncate |
Copy and truncate | copytruncate |
postrotate |
Command after rotation | kill -USR1 |
How to avoid common logrotate mistakes
- Syntax error in config — logrotate silently skips the file. Solution: always run
logrotate -dafter changes. On 100 servers, we found that 30% of issues are due to this. - Incorrect postrotate for services with open file descriptors — log loss. Solution: use
copytruncatefor apps without signal support. - Ignoring delaycompress for Nginx — compressed log may be corrupted. Solution: always add
delaycompresswhen usingcompress. - Forgetting rotation after deployment — disk fills up. Solution: add logrotate to CI/CD pipeline. We implement this practice in all projects.
Following these recommendations will avoid 90% of disk overflow incidents. Our team can help you avoid these mistakes — order a configuration audit.
What's included in logrotate setup
- Configuration files for all services (Nginx, PostgreSQL, custom apps).
- Ansible role for deployment on fleet servers.
- Documentation on parameters and retention periods.
- Rotation monitoring setup (Prometheus + Grafana, error alerts).
- Team training: how to make changes and check status.
Timeline and cost
Configuring logrotate on one server takes 1 to 3 hours. For a fleet of 10+ servers, it takes 2 to 5 days including Ansible automation. Cost is calculated individually based on infrastructure complexity. Contact us for a consultation — we will assess your project and select optimal parameters.
Why trust professionals?
Our engineers have 10+ years of DevOps experience, are certified in Kubernetes and cloud platforms. We have configured logrotate on 100+ servers, guaranteeing no disk overflow failures. Experience shows: up to 80% of disk incidents in client environments were resolved with a single logrotate setup.
Don't wait until logs fill your disk — configure logrotate today. Contact us for an audit of your logging system and receive a ready-made configuration for your stack.







