Linux备份脚本

#!/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


你可能感兴趣的:(linux,备份,脚本)