关于我们
技术分享
技术分享
Linux备份脚本
Linux备份脚本
2021-06-11
#!/bin/bash
#Linux 文件或目录备份脚本,执行脚本后加要备份的目录或文件名
if [ -z $1 ];then
echo "Please usage $0 Directory or file"
else
{
if [ -d /root/backup ]; then
# echo "The \"backup\" Directory is exsit!"
:;
else
mkdir /root/backup
fi
if [ -d /root/log ]; then
# echo "The \"log\" Directory is exsit!"
:;
else
mkdir /root/log
fi
echo "----------------------`date`----------------------">>/root/log/bak.log
cp -a $1 /root/backup/$(basename $1)-$[$(date +%y%m%d)-1] 2>>/root/log/bak.log
if [ $? = 0 ]; then
echo "The $1 is backup Sucessful!" >>/root/log/bak.log
else
echo "The $1 is backup Faild!" >>/root/log/bak.log
fi
echo -e "--------------------End------------------------\n" >>/root/log/bak.log
}
fi
- 标签:
-
行业资讯
您可能感兴趣的新闻 换一批
热门文章
现在下载,可享30天免费试用