Thứ Năm, 14 tháng 3, 2013

[Shell] FTP theo filelist neu file co roi ko backup nua.

 filelist gom 3 cot: 1 ip server, cot 2 file name, cot 3 ip may minh
 minh vua viet ra voi qua nen chua debug, ban nao decode lai thi post wa facebook dum minh nha, cam on nhieu

Tắt firewall: setup
Disable SELinux: setenfore 0
Stop iptables: service iptables stop

Trên server cần cài FTP: yum install vsftpd, sau đó start dịch vụ.
Trên client, cài gói ftp: yum install ftp

#!/bin/bash
cat filelist | while read line
do
        ser=$(echo "$line" | awk '{print $1}')
        des=$(echo "$line" | awk '{print $3}')
        file=$(echo "$line" | awk '{print $2}')

        ssh $ser 'stat -c %z $file | sed 's/\..*$//g'' >logmoi$file
        x=$(cat logmoi$file)
        y=$(cat logcu$file)
        if [[ "$x" != "$y"  ]]
        then
                echo "  backup log1"
        ftp -n -v -i $ser<<END_FTP
        user hien 123456
        binary
        lcd /home/hien/Desktop/backup
        cd /home/hien/Desktop
        get $file
        bye
END_FTP
        else echo "backup roi ko can nua"
        fi
        ssh $ser 'stat -c %z $file' >logcu$file
done
~                        

Không có nhận xét nào:

Đăng nhận xét