Operating System - HP-UX
1832654 Members
3888 Online
110043 Solutions
New Discussion

Syncing the Folders Between the servers

 
SOLVED
Go to solution
susee_sundar
Regular Advisor

Syncing the Folders Between the servers


Hi Team..

My Objective of this thread is I want to sync up the Folder "ABC" in server1 with the Folder "XYZ" on the Server2.

Current Scenario:
I created a user with auto key authentication hence he can access the server2 without password from server1 and vice versa.

There is a Cronjob scheduled on the server2 which will run once in 5 minutes and copy the folder ABC from server1 to server2 using SCP.

Now the issue is:

I don't want to copy the files from server1 to server2 when they are being created.

I mean in realtime if the file is being created on server1 the SCP operation should not copy the file to the server2.

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

And we are having a felt that the user with key authentication is somewhat unsafe on a production env..

I want to know we are on the right direction or ant other way to achieve the Objective


Regards
Suseendran .A

4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: Syncing the Folders Between the servers

Hi:

One approach is to see if your file is in-use. If so, skip your copy. I've used this approach:

...
PIDS=`fuser ${FILE} 2> /dev/null` #...look for any process using file...
if [ ! -z "${PIDS}" ]; then
print -u2 "Error: '${FILE}' is inuse by process(es): ${PIDS}"
...

Regards!

...JRF....
Patrick Wallek
Honored Contributor
Solution

Re: Syncing the Folders Between the servers

There's really no way to tell SCP not to copy a file as it is being created. To do that you would have to test all files in the directory using lsof or fuser, verify they are not in use, and then copy them.

An alternative to copying everything every time is to use rsync.

http://hpux.connect.org.uk/hppd/hpux/Networking/Admin/rsync-2.6.8/

rsync is designed to keep things in sync between servers. Once you have sync'ed them the first time, rsync can then look at the files and directories and copy only the things that have changed to keep server2 in sync with server1.

Geoff Wild
Honored Contributor

Re: Syncing the Folders Between the servers

Why not use rdist?

With rdist, you need to setup some files and cron:

# Copy myadm across to the DR site.
05 01 * * * /app/admin/drp/update-binaries.sh


# cat /app/admin/drp/update-binaries.sh
#! /bin/sh

# Keep the DRP copy of the oracle up-to-date.
# Currently the files are in:
#
# /oracle
#
# See the rdist(1M) distfile for a list of exclusions.

DRPDIR=/app/admin/drp
DRPHOST=svr0031

HOST=`/usr/bin/uname -n`
( su - oracle -c "rdist -f $DRPDIR/distfile oracle"; ) 2>&1 |\
tee $DRPDIR/drp.log 2>&1 |\
mailx -s "oracle rdist output" sysadm


# cat distfile
ORACLEDR = ( svr0031 )

#
# File systems to be copied over to the DR host.
# Don't use -R in install - so as not to remove files on destination host
ORACLE = /oracle

oracle: ( ${ORACLE} ) -> ( ${ORACLEDR} )
install -w ;


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
susee_sundar
Regular Advisor

Re: Syncing the Folders Between the servers

Hi Team..

I set up the rsync command to do this operation ., Since I found that the SCP is copying the realtime files.

Regards
Suseendran ,A