You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
768 B
37 lines
768 B
要求:
|
|
打包压缩/var/log/nginx目录下所有内容,存放在/tmp/nginx目录里
|
|
压缩文件命名规范:yymmdd_logs.tar.gz,只保存七天内的文件,超过七天的文件会进行清理
|
|
|
|
#!bin/bash
|
|
date="$(date +%Y%m%d)"
|
|
dir='/tmp/nginx'
|
|
backupfile='yymmdd_logs.tar.gz'
|
|
|
|
#查看/tmp/nginx是否存在,不存在则创建
|
|
checkbak(){
|
|
if [ ! -e ${dir} ]
|
|
then
|
|
mkdir ${dir}
|
|
fi
|
|
}
|
|
|
|
#压缩文件
|
|
backup(){
|
|
tar -zcvf ${dir}/${backupfile} /var/log/nginx/ > /dev/null 2>&1
|
|
echo "${backupfile} Compressed and packaged successfully !"
|
|
}
|
|
|
|
#清除七天过期文件
|
|
cleanup(){
|
|
find ${dir} -type f -mtime +7 | xagrs rm -rf
|
|
if [ $? -eq 0 ]
|
|
then
|
|
echo "Cleaned up successfully!"
|
|
else
|
|
echo "data cleaning failed error, please pay attention in time"
|
|
fi
|
|
}
|
|
|
|
checkbak
|
|
backup
|