目的:通过Shell脚本运行一键备份压缩到指定文件夹
cd /tmp/backup/ touch test0622.sh
如下:
#!/bin/bash dir="/www/wwwroot/mefj.com.cn" backup="/tmp/backup" filename="wordpress.tar.gz" date=`date +%Y%m%d` [ ! -e "$dir" ] && echo "请联系管理员" && exit [ ! -e "$backup" ] && mkdir $backup /bin/mkdir $backup/$date /bin/tar jcvf $backup/$date/$filename $dir/ find "$backup" -type d -mtime +20 -exec rm {} ; #备份文件保留20天后自动删除
运行脚本
/bin/sh /tmp/backup/test0622.sh
![](https://oss-wp-picture.oss-cn-shanghai.aliyuncs.com/2020/06/image-29.png)