添加 'Shell-MD/归档备份'

main
diandian 2 years ago
parent d76c28dd6f
commit a02fa4eab4

@ -0,0 +1,37 @@
要求:
打包压缩/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
```
Loading…
Cancel
Save