SIGN IN / UP
    opened image

    Cleaning up old logs.

    To keep the system clean and perform optimally, it is necessary to periodically clean up old logs. Below are the actions that can be taken for this purpose.

    1. Cleaning up system logs:
    Only the old log archives should be deleted, while the logs themselves should not be deleted in order to avoid errors with the operation of some services. It is advisable to compress or clear the logs with the following commands:

    find /var/log \( -name "*.[0-9]" -o -name "*.*.[0-9]" -o -name "*.gz" \) -exec rm {} \;
    find /var/log/ -type f -name "*log" -exec cp /dev/null {} \;
    

     

    If your server accumulates a lot of logs every day, and there is not enough free disk space, you can clean up outdated log archives daily. For what you can add the following command to the crontab:

    0 0 * * * find /var/log \( -name "*.[0-9]" -o -name "*.*.[0-9]" -o -name "*.gz" \) -exec rm {} \; && find /var/log/ -type f -name "*log" -exec cp /dev/null {} \;

     

    2. Clearing the repository cache:
    It is recommended to use special commands to clear the cache of the local repository from the received package files, instead of manually deleting the cache in the /var/cache/ directory. Here are some of them:

    For yum-based CentOS/RedHat systems:

    yum clean all

    For Ubuntu/Debian systems based on apt-get:
     

    apt-get clean

     

    3. Deleting temporary files:
    When deleting temporary files using the following commands, you should be careful not to delete important data such as config, site or database backups that may be stored in temporary folders. First, check the contents of these folders using the `ls -la` command:

    ls -la /tmp/
    ls -la /var/tmp/

    If you have checked and there is nothing important there, you can use the following commands to delete temporary files:

    rm -rf /tmp/*
    rm -rf /var/tmp/*

     

    4. Additional steps for servers with different server control panels:

    ISPmanager:

     

    Clear (zero out) all ISP log files:

    find /usr/local/mgr5/var/logs -type f -exec sed -i 'd' "{}" \;

    Clear log archives in the /var/www/httpd-logs directory:

    find /var/www/httpd-logs \( -name "*.[0-9]" -o -name "*.*.[0-9]" -o -name "*.gz" \) -exec rm {} \; && find /var/www/httpd-logs/ -type f -name "*log" -exec cp /dev/null {} \;

    Folders with temporary files in ISPmanager:

    rm -rf /var/www/www-root/data/tmp/*

    Where www-root is the default user, or whatever is used on the server.

     

    VestaCP:

     

     

    Delete temporary files and unfinished archives in the VestaCP directory:

    rm -rf /home/admin/tmp*
    rm -rf /backup/tmp.*

    This deletes incomplete or failed archives for the admin user. For another user, specify it in the command.

    On VestaCP, you can also use the following command to remove outdated log archives:

    rm -rf /var/log/*-2023*.gz

    Where you specify instead of 2023 - the current year.

     

    Conclusions.

    These actions will help clean up the system of obsolete and unnecessary logs and temporary files, keeping it healthy and optimized.