6000609a394e41346.png_fo742.png
先做免密登录
样式有问题 变量取值不见了

#!/bin/bash
LOCAL_DIR=/data/bakup/mysql
REMOTE_DIR=/data/bakup/mysql
RIP="123.124.125.126"
RPORT=22
REXE="ssh -p $RPORT $RIP"

for file in `$REXE ls $REMOTE_DIR`;do
    if [ -f $LOCAL_DIR/$file ];then
        md5_local=`md5sum  $LOCAL_DIR/$file  |awk '{print $1}'`
        md5_remote=`$REXE md5sum  $REMOTE_DIR/$file  |awk '{print $1}'`
        if [ $md5_local == $md5_remote ];then
            echo "$file on local already,skip"
        else
            echo "$file broken,clean..."
            rm -rf $LOCAL_DIR/$file
        fi
    else
        echo "Starting bak $file"
        scp -P $RPORT $RIP:$REMOTE_DIR/$file $LOCAL_DIR
        if [ "0" -eq $? ];then
            echo "Delete  $file"
            $REXE rm -rf $REMOTE_DIR/$file
        fi
    fi
done

发表评论

您的电子邮箱地址不会被公开。

Captcha Code