#!/bin/bash

src=/root/server/ic/

dst=/var/server_data/ic/

dateTime=`date +%Y%m%d-%H:%M`

mount -t cifs -o username=everyone,password="" //192.168.1.2/bak $src


Backup () {

    newFile=`ls -At $src |head -n 1` > /tmp/ic.src  #按时间顺序排列的第一文件

    if [ -z "$newFile" ];

        then

        echo "Bak Null" |mail -s "Bak Null!" 111111@sina.com

    else

        \cp -a $src$newFile $dst

        File=`ls -At $dst |head -n 1` > /tmp/ic.dst

        diff /tmp/ic.src /tmp/ic.dst

        if [ $? -eq 0 ];

            then

            echo "$dateTime $File OK" >> /root/log/ic.log       

        else

            echo "$dateTime $File Fail" >> /root/log/ic.log

        fi

    fi

    rm -f /tmp/ic.*

}

Backup

umount $src


#每月5号1:00执行

0 1 5 * * /sh/bak.sh 2>>/log/ic.err