Linux Logrotate Configuration Generator (Retention & Compression)
SysAdmin & DevOps

Linux Logrotate Configuration Generator (Retention & Compression)

Generate /etc/logrotate.d/ configuration files with daily/weekly rotation, gzip compression, dateext, size limits, and postrotate scripts.

100% Client-Side Privacy
Zero Server Transmission
Presets:
Logrotate Directives & Parameters
Target File & Location/etc/logrotate.d/nginx
Rotation Frequency & Retention LimitsKeeps 14 rotated files
Compression & Timestamping (dateext)~85% space reduction
File Permissions & Process Safetycopytruncate vs create
Reload Signals & Scripts (postrotate)
Runs after rotation
Runs before rotation
/var/log/nginx/*.log {
    daily
    rotate 14
    maxage 30
    missingok
    notifempty
    compress
    delaycompress
    dateext
    dateformat -%Y%m%d
    dateyesterday
    create 0640 www-data adm
    sharedscripts
    postrotate
        [ -f /var/run/nginx.pid ] && kill -USR1 $(cat /var/run/nginx.pid)
    endscript
}
Rotation & Frequency
DAILY (14 copies)

Retains up to specified generations before automated eviction.

Compression & Storage
Gzip (delaycompress)

Estimated ~85% disk storage savings with background gzip.

Permissions & Lifecycle
create 0640 www-data

Atomic file rotation with new file recreation and custom permissions.

100% Client-Side Generation

Zero server uploads. Your file paths, custom postrotate scripts, and server credentials stay strictly inside your local browser memory.

Full Logrotate Directives Spec

Full support for copytruncate, delaycompress, dateext timestamping, size thresholds, sharedscripts, and su user isolation.

Production Ready & Syntax Tested

Instant generation of /etc/logrotate.d/ configs, logrotate -d dry-run verification commands, and automated installation scripts.

Technical Reference & Architecture Guide

Linux Logrotate Configuration Generator (Retention & Compression) — Reference Guide

Generate /etc/logrotate.d/ configuration files with daily/weekly rotation, gzip compression, dateext, size limits, and postrotate scripts.

Key Parameters & Controls

rotateDirective

Defines the number of rotated archive generations to retain before purging the oldest logs.

Default: 4
frequencyDirective

Specifies the time-based rotation schedule: daily, weekly, monthly, or yearly.

Default: weekly
compressDirective

Enables gzip compression for rotated logs to save disk space; companion to delaycompress.

Default: compress
delaycompressDirective

Postpones compression of the most recently rotated log file until the next rotation cycle, avoiding write-lock conflicts.

Default: delaycompress
createDirective

Specifies file permissions (octal mode), owner, and group when recreating the active log file immediately after rotation.

Default: 0640 root adm
copytruncateDirective

Truncates the active log file in-place after creating a backup copy, designed for daemons that cannot close open file handles.

Default: disabled
postrotateBlock

Shell commands executed once or per-log after rotation completes, commonly used to signal daemons (e.g. systemctl reload).

Default: optional

Pro Tips & Best Practices

When rotating logs for services like

When rotating logs for services like Nginx or PostgreSQL, processes hold open file descriptors until signaled. Using delaycompress prevents compressing files while background workers are still writing.

When matching multiple log files

When matching multiple log files using wildcards (such as /var/log/nginx/*.log), omitting sharedscripts causes postrotate scripts to execute once for every single file, leading to service reload storms.

Perform Safe Dry-Runs with Debug Mode

Always test new configurations using 'logrotate -d /etc/logrotate.d/myapp' before deploying. The -d flag performs syntax analysis and displays planned operations without modifying files on disk.

Mind the copytruncate Log Loss Window

copytruncate briefly leaves open a tiny time window between copying and truncating where inbound log lines can be lost. Use signal-based reloads (USR1/SIGHUP) whenever supported by the daemon.

Common Gotchas & Troubleshooting

Logrotate fails with 'error: skipping ... parent directory has insecure permissions'

Logrotate refuses execution if configuration files or parent directories have write permissions for group or others. Execute 'chmod 0644 /etc/logrotate.d/myapp' and ensure the parent directory is set to 0755 or 0750.

Application continues writing to rotated .1 or dated archive file instead of the new active log

Linux filesystems write to open inodes rather than file paths. Add a postrotate block sending a reload signal (e.g. 'systemctl reload <service>' or 'kill -USR1 <pid>') to reopen file descriptors, or enable copytruncate.

Log rotation triggers multiple times or appears to rotate out of schedule

Verify if 'size' or 'maxsize' directives are configured alongside daily/weekly intervals, and inspect the state tracking file at /var/lib/logrotate/status to diagnose last execution timestamps.

Frequently Asked Questions

Where should custom logrotate configuration files be placed on Linux?▼

Custom service configurations should be placed inside /etc/logrotate.d/ (e.g. /etc/logrotate.d/nginx). The master configuration /etc/logrotate.conf automatically includes all files in this directory.

What is the technical difference between create and copytruncate?▼

The 'create' directive renames the active log file and immediately creates a new empty file at the original path, requiring a daemon signal to reload the file descriptor. The 'copytruncate' directive copies the file contents to an archive and truncates the original file to zero bytes in-place, which requires no daemon restart but carries a minor race condition risk.

How does the dateext directive improve log archiving compared to numerical indexing?▼

Enabling 'dateext' appends a date stamp (YYYYMMDD by default) instead of sequential numbers like .1 and .2.gz. This keeps archive file names constant across successive rotations, preventing filename shifts that complicate log ingestion pipelines like Fluentd or Datadog.

How do I force-run logrotate immediately for testing or urgent disk cleanup?▼

Run 'logrotate -vf /etc/logrotate.d/myapp'. The -v flag provides verbose output detailing each action, while -f (force) bypasses schedule and size constraints to rotate all targeted files immediately.

Why is the su directive necessary on modern Linux distributions?▼

If a log directory is owned by a non-root system user (such as www-data or mysql), logrotate requires 'su <user> <group>' to drop root privileges before performing operations in that directory, mitigating potential symlink vulnerabilities.

Related Tools & Utilities

All Tools →