shell_mysql.md/Shell-MD/归档备份
2023-04-22 22:33:42 +08:00

37 lines
788 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

要求:
打包压缩/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
```