备份昨天php CI框架日志

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

# !/usr/bin/bash
#
#     备份并压缩昨天php CI框架日志
#

back_log_dir="/my_disk/project_log"

yesterday=`date -d '-1 day' +%F`

function backup(){
        echo $1

        if [ ! -d ${back_log_dir}/${2} ]
        then
                mkdir ${back_log_dir}/$2
        fi

        yesterday_log=${1}/log-${yesterday}.php

        bzip2 $yesterday_log

        #如果备份目录有了昨天的备份文件,则加后缀数字防止覆盖

        has_count=`ls ${back_log_dir}/$2/${yesterday_log}.bz2* 2>/dev/zero | wc -l `

        if [ $has_count -eq 0 ]
        then
                mv ${yesterday_log}.bz2 ${back_log_dir}/$2/
        else
                mv ${yesterday_log}.bz2 ${back_log_dir}/$2/${yesterday_log}.bz2.$(( has_count + 1 ))
        fi
}

backup /home/wwwroot/project/src/application/logs project
backup /home/wwwroot/project/src_cron/application/logs project_cron
backup /home/wwwroot/project_mobile/src/application/logs project_mobile