Linux automatically packages non-current date tomcat logs to the backup directory

Requires gzip command support:

 

#!/bin/sh

tomcat_backup_dir="/package backup directory"

tomcat_dir_list = $ (ps -ef | grep -oP '(? <= - Dcatalina \ .base =) [^ \ s] *')
#netty_dir_list=$(ps -ef | grep com.mapbar.mserver.netty \
#netty_dir_list = $ (ps -ef | grep com.mapbar \
 # | grep -oP '[^:] * (? = / lib / netty- \ d. \ d. \ d.Final.jar)')

today=$(date +%Y%m%d)

function do_backup()
{
  proj=$(basename $1)
  src_dir = $ 1 / logs
  dst_dir=$2/$proj

  echo $ proj
  for log_file in $src_dir/*; do
    log_date=$(basename $log_file | grep -oP '\d{4}(-\d{2}){2}')
echo $log_date
    if [ -n "$log_date" ] && [ ${log_date//-/} -lt $today ]; then
      echo $log_file
      backup_dir="$dst_dir/${log_date:0:4}/${log_date:5:2}"
      if [ "${log_file##*.}" != "gz" ]; then
        nice -10 gzip $log_file
        log_file=$log_file.gz
      be
      mkdir -p $ backup_dir
      mv $ log_file $ backup_dir
    be
  done
}

for tomcat_dir in $tomcat_dir_list; do
  do_backup $tomcat_dir $tomcat_backup_dir
done

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326412488&siteId=291194637