To adjust the log rotation settings on Debian 12 Bookworm to save space, you can modify the configuration in /etc/logrotate.conf or add specific configurations in the /etc/logrotate.d/ directory for individual log files. Here’s a general approach to help reduce disk usage:
- Reduce Retention Time: Lower the number of retained log files by changing the
rotateoption.
/var/log/*.log {
weekly
rotate 2 # Keeps only the last 2 rotations
compress # Compress old logs to save space
delaycompress # Delays compression for one rotation
missingok
notifempty
create 640 root adm
}Code language: JavaScript (javascript)
- Enable Compression: If not already enabled, ensure
compressis included to compress old logs, saving significant space. - Limit File Size: If logs grow quickly, you can rotate them based on size.
size 50M # Rotate logs when they reach 50 MBCode language: PHP (php)
- Remove Unnecessary Logs: If specific logs are not needed, you can disable rotation for those files.
After editing, apply the settings by running:
sudo logrotate -f /etc/logrotate.conf
To compress old logs on Debian 12, you can enable compression in the logrotate configuration. Here’s how to set it up:
- Edit the Main Logrotate Configuration:
Open/etc/logrotate.confin a text editor:
sudo nano /etc/logrotate.conf
- Enable Compression:
Ensure thecompressoption is included in the configuration to automatically compress old logs. You might also want to usedelaycompressso that the most recent rotated file remains uncompressed, in case it needs quick access.
compress # Compresses logs after rotation
delaycompress # Delays compression until the next rotationCode language: PHP (php)
- Configure Log Rotation in Specific Files (Optional):
If you want to set compression for specific log files, you can add these options within individual configuration files in/etc/logrotate.d/. For example:
/var/log/syslog {
weekly
rotate 4
compress
delaycompress
missingok
notifempty
create 640 root adm
}Code language: JavaScript (javascript)
- Test the Configuration:
After making these changes, test the configuration to make sure it works as expected:
sudo logrotate -f /etc/logrotate.conf
This will compress rotated log files, helping to save disk space on your Debian 12 system.