During server maintenance, website access logs generated by the BT Panel accumulate over time, consuming significant disk space. Timely cleanup of these logs is not only an effective way to free up storage space but also improves server performance. This article introduces several methods for cleaning BT Panel website access logs to help you maintain efficient server operation.
BT Panel's website access logs are stored by default in the `/www/wwwlogs` directory. These log files typically end with `.log`, and each website has its own independent log file. Before performing any cleanup operations, it is recommended to assess disk space usage. You can use the `df -h` command to view overall disk usage or the `du -sh /www/wwwlogs` command to check the specific size of the log directory.
Important Note: Cleaning logs is a high-risk operation; always back up important log files before proceeding. If you are unsure whether certain logs are important, it is recommended to move them to another location and observe the website's performance before deciding whether to delete them.
For scenarios where temporary space needs to be freed up, manual cleanup is the most direct method. After entering the log directory, you can selectively delete specific log files.
cd /www/wwwlogs
Once inside the logs directory, you can delete all log files:
rm -rf *.log
Or, to more precisely delete logs for a specific website, such as the website named `example.com`:
rm -rf example.com.log
If you want to empty the log file contents without deleting the file itself (e.g., while a process is writing to the log), you can use redirection:
> /www/wwwlogs/example.com.log
This method preserves the file itself but empties all content, which may be safer for running web services.
For scenarios requiring periodic cleanup, batch deletion by date is the most reasonable approach. The `find` command in Linux is well-suited for this task.
To delete all log files older than 7 days, you can use:
find /www/wwwlogs -name "*.log" -mtime +7 -delete
This command will search the `/www/wwwlogs` directory for all files with the `.log` extension that were modified more than 7 days ago and delete them directly.
If you want to see which files will be affected before deleting, you can run the preview command first:
find /www/wwwlogs -name "*.log" -mtime +7
After confirming the file list is correct, then perform the deletion operation.
The parameter `-mtime +7` indicates that files modified more than 7 days ago will be matched. You can adjust this number as needed; for example, `+30` represents 30 days ago, and `+365` represents one year ago.
For production environments, setting up automated cleanup is best practice. You can easily achieve regular automatic cleanup using the scheduled task function built into the BT Panel.
Log in to the BT Panel, navigate to the "Scheduled Tasks" page, and add a new Shell script task. In the task script box, enter:
find /www/wwwlogs -name "*.log" -mtime +30 -delete
Then set the execution cycle, for example, every Monday at 3 AM. This way, the system will automatically clean up logs older than 30 days without manual intervention.
If you have specific needs, such as needing to retain logs from different time periods, you can set up multiple tasks:
# Retain detailed logs for the last 7 days and clean up earlier logs
find /www/wwwlogs -name "*.log" -mtime +7 -delete
# Retain summary logs for the last 30 days (if any)
find /www/wwwlogs -name "*.log" -mtime +30 -delete
For security auditing purposes, it is recommended to record the cleanup operation itself. You can create a simple script to achieve this:
#!/bin/
LOG_FILE="/var/log/clean_wwwlogs.log"
CLEAN_DATE=$(date +"%Y-%m-%d %H:%M:%S")
echo "[$CLEAN_DATE] Starting cleanup of /www/wwwlogs" >> $LOG_FILE
# Perform cleanup
find /www/wwwlogs -name "*.log" -mtime +30 -delete
echo "[$CLEAN_DATE] Cleanup completed" >> $LOG_FILE
After completing the cleanup, be sure to verify the results. You can run `df -h` and `du -sh /www/wwwlogs` again to confirm that disk space has been freed, or use `ls -la /www/wwwlogs` to check the actual status of the log files.
Cleansing the BT Panel website access logs is an important part of routine server maintenance. Manual log cleanup is suitable for emergencies, batch deletion by date is suitable for regular maintenance, while automated solutions are the best choice for long-term operation and maintenance. Regardless of the method used, caution should be exercised and operation logs should be kept.
It is important to note that overly frequent log cleanup can lead to difficulties in subsequent troubleshooting. It is recommended to consider a cleanup strategy based on business needs and storage space balance. For high-traffic websites, consider more complex log rotation schemes rather than simple deletion. If you are using the log analysis function of a control panel like BT Panel, log cleanup may affect the accuracy of statistical data; please assess this impact before cleanup.
Through a reasonable log management strategy, you can ensure that the server always has sufficient disk space while retaining necessary log data for troubleshooting and performance analysis.