Backing up windows share files for the most recent day
#! / 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 # the first file in chronological order
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
# executed at 1:00 on the 5th of every month
0 1 5 * * / sh/bak.sh 2 > > / log/ic.err