About Project log compression and deletion operations
Today, encountered a problem, that is, our online service log dozen more, a few days ago to deploy/templates/cron.erb the project, but do not know why, this does not take effect,
The original is not very understand this log matching rules, today we will look at this log matching rules, first of all, we have this cron.erb inside to take out
* * * * * work/usr/sbin/tmpwatch--nodirs-m <%= scope["Config::basedir"]%>/. /.. /log/exchange-bid-service/
* * * root/usr/bin/find <%= scope["Config::log_dir"]%>-type f-mtime +5-name "*.gz"-delete
* * * * root/usr/bin/find <%= scope["Config::log_dir"]%>-type f-mtime +1! -name "*.gz"-exec gzip-f {} \;
First of all we care about the timing of the task of the two, this time we need to Linux under the command of find
The Find command is used to search for files in a directory (and subdirectories), and you can specify matching criteria, such as file name, file type, user or even timestamp.
Find [path ...] [Expression]
The directory path that the Path:find command looks for. For example, use. Represents the current directory, using/representing the system root directory
-type to find a certain type of
B-Block device files
D-Directory
C-Character device files
P-Pipe File
F-Ordinary Documents
-mtime is modify time, which means that the contents of the file are not modified.
Find. Parameter N in-mtime
Find. N in-mtime n refers to 24*n, +n, N-N is represented by:
+n: Greater than n
-N: Less than n
N: Equal to n
Find. -mtime n The last modification occurs at a distance of n*24 (n+1) * 24 hours from the current time
Find. -mtime +n The last modification occurred before n+1 days, from the current time (n+1) * 24 hours to
Find. -mtime-n The last modification occurs within n days, from the current time of n*24 hours
-name find files by file name
-exec, the Find command executes the shell command given by the parameter to the matching file in the form of ' command ' {} \;
Find./Size 0-exec rm {} \; Delete files with a file size of 0
Based on the above understanding of the order of find, we can explain the following statement
* * * root/usr/bin/find <%= scope["Config::log_dir"]%>-type f-mtime +5-name "*.gz"-delete
1 minutes a Day 1 o'clock in the morning, will find a distance before today's (5+1) day suffix name is. GZ's file performs a delete operation
* * * * root/usr/bin/find <%= scope["Config::log_dir"]%>-type f-mtime +1! -name "*.gz"-exec gzip-f {} \;
Every day 1:30 A.M., will find a distance before today (1+1) the name is not suffix is the end of. gz file for gzip operation (for compression package operation)