怎樣利用linux rsync 同步不同Server上的兩個目錄下的檔案

tolywang發表於2010-03-04

we will configure script. to rsync archive log file from production db to standby db 


1. How to Rsync over SSH without a password.

 

a. Log into the TARGET host (standby db), and generate an RSA (public and private) key pair:

target$ ssh-keygen  -t   rsa

* Accept the default location for the key files (press [ENTER]).
* Enter and confirm a pass phrase. (empty for no passphrase) (it is not a requirement)


b. Log into the SOURCE host (production db), and confirm the existence of this file
   "/home/oracle/.ssh./authorized_keys" ,   create this file

source$ touch  ~/.ssh/authorized_keys

 

c.  Log into the SOURCE host, and get public key from TARGET:

source$ ssh target  cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

 

d.  Log into the TARGET host (here is Standby), and try to rsync:

target$ rsync -e ssh -av   /ocfs_data/mxdell/arch/  

 

 

------------------------------------------------------------------ 

 

 

改良的指令碼,可以判斷, 一個linux crontab job在執行,同樣的一個如果再次執行會被終止。


#!/bin/bash


pid=`/sbin/pidof rsync`
if [ "$pid" ]
then
    echo "Rsync is already running...."
else
    echo "Starting rsync `date`"
    rsync -e ssh -av /ocfs_data/mxdell/arch/
    echo "Completed rsync `date`"
fi
exit 0

 

-----------------------------------------------------------------

 

#!/bin/bash


pid=`/sbin/pidof rsync`
if [ "$pid" ]
then
    echo "Rsync is already running...."
else
    echo "Starting rsync `date`"
    rsync -e ssh -av /ocfs_data/mxdell/arch/
    echo "Completed rsync `date`"
fi

 

 

 

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-628557/,如需轉載,請註明出處,否則將追究法律責任。

相關文章