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.
| 0 1 2 3 4 5 6 7 8 9 |    /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    } | 
- 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.
| 0 1 |    size 50M          # Rotate logs when they reach 50 MB | 
- Remove Unnecessary Logs: If specific logs are not needed, you can disable rotation for those files.
After editing, apply the settings by running:
| 0 1 | 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:
| 0 1 |    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.
| 0 1 2 |    compress        # Compresses logs after rotation    delaycompress   # Delays compression until the next rotation | 
- 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:
| 0 1 2 3 4 5 6 7 8 9 |    /var/log/syslog {        weekly        rotate 4        compress        delaycompress        missingok        notifempty        create 640 root adm    } | 
- Test the Configuration:
 After making these changes, test the configuration to make sure it works as expected:
| 0 1 |    sudo logrotate -f /etc/logrotate.conf | 
This will compress rotated log files, helping to save disk space on your Debian 12 system.
