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:

  1. Reduce Retention Time: Lower the number of retained log files by changing the rotate option.
   /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)
  1. Enable Compression: If not already enabled, ensure compress is included to compress old logs, saving significant space.
  2. 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)
  1. 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:

  1. Edit the Main Logrotate Configuration:
    Open /etc/logrotate.conf in a text editor:
   sudo nano /etc/logrotate.conf
  1. Enable Compression:
    Ensure the compress option is included in the configuration to automatically compress old logs. You might also want to use delaycompress so 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)
  1. 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)
  1. 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.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.