Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to configure regular backup and deletion of nginx logs

Shulou Source: shulou.com Published: 2022-05-31 12:30:21 09月18日 Update

This article mainly introduces the nginx log regular backup and deletion of how to configure the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that after reading this nginx log regular backup and deletion how to configure the article will have a harvest, let's take a look.

Once the nginx log feature is enabled, nginx will generate log files of a certain size every day. If the system runs stably and there is no problem, then the log basically will not be checked. However, if these logs are not cleaned in time and accumulated day by day, it will be scary to occupy the disk space of the server. To solve this problem, use the shell script to back up and delete the nginx log files regularly, only for a period of time.

Figure 1:

#! / bin/bash#auth:lzq#desc: back up the current log by date and regenerate the next day's log file # date:2016-09-18date= `date +% y% m% d`nginx _ pid= `cat / var/run/ nginx.pid` # exit if ["$?"! = 0] then exit 1 if the current nginx is not running The path where fi#nginx logs are located: log_path='/usr/local/nginx/logs/'log_name='access.log'mv ${log_path} ${log_name} ${log_path} ${log_name} $date# delete the old backup file function deloldbak () {olddate= `date + "% y%m%d"-d "- $1 day" `if [- e "${log_path} ${log_name} $olddate"] Then rm-f ${log_path} ${log_name} $olddate echo "${log_path} ${log_name} $olddate del ok" fi} # reload nginx configuration Regenerate the nginx log file kill-usr1 $nginx_pidif ["$?" = = 0] then deloldbak 7 exit 0 This is the end of fi's article on "how to configure regular backup and deletion of nginx logs". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to configure regular backup and deletion of nginx logs". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Log backup configuration file knowledge generation content article question run terror value function size location easy to operate article date time easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info NVidia Linux Xiaomi