我正在通过 rsync 从生产服务器同步我的备份服务器,但现在我想实现失败通知。当我尝试获取 rsync 命令的状态时,它不会在成功时给我 status =0。请让我知道我将如何实现此功能。
failureMailFlag=0
rsync --timeout=600 -e ssh -avzr --delete $sourcePath/weblayout/ $destination:$destinationPath/weblayout/ --stats -i > $fileCreationPath/$tempfile 2>&1
rStatus=$?
if [ $rStatus == "0" ]
then
echo -e "$startdate\t\tweblayout\t\t$starttime\t\t$(date +"%m-%d-%Y %r")\t\tSuccess\t\t" >> $fileCreationPath/RsyncLog.txt
else
echo -e "$startdate\t\tweblayout\t\t$starttime\t\t$(date +"%m-%d-%Y %r")\t\tError\t\t">> $fileCreationPath/RsyncLog.txt
failureMailFlag="1"
cat $failureMail $tempfile >> $fileCreationPath/finalFailureMail.mai
wablayout=weblayout
varFailureMail=${varFailureMail}${wablayout}
fi
if [ $failureMailFlag == "1" ]
then
cat $fileCreationPath/*.mail finalFailureMail.mai $fileCreationPath/$varFailureMail $fileCreationPath/$tempfile | mailx -s "Failure Mail notification for RSYNC" $EmailSent
else
echo "successfully run"
fi