shell脚本-备份上个月的文件

版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/liyyzz33/article/details/84775376

前提文件包含日期

#!/bin/bash

#输出上个月的日期
last_month=$(date -d "$(date +%Y%m)01 last month" +%Y%m)
echo $last_month

cd /log/
#查找所有上个月日期的文件
file=$(ls -d $last_month*)
#执行压缩到备份目录
zip -qrv /log/bak/$last_month.zip $file

crontab自动任务每月1号执行

** 1 * * /root/linan/bak_log.sh > /dev/null 2>&1 &

猜你喜欢

转载自blog.csdn.net/liyyzz33/article/details/84775376