Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

scp or rsync multiple files in parallel from a remote host

Tags
korn shell scripting, rsync, scp, shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 08-06-2012
scp or rsync multiple files in parallel from a remote host

Hi.

I'm trying to speed up an rsync command by running it in parallel. There's no real option for this other than if the files are in multiple directories (which they're not). And even then there's no way of knowing if rsync has succeeded as the process is running in the background .. and there's no return code from the process id. Any ideas?

I thought about just using scp but scripting it is proving trickier than I thought and I'm getting errors on the for loop when I try to introduce variables into the ssh part:

E.g.
Code:
RHOST=srv245005
CCMD="ls /db/remote_backup_area"
 
for BackupFile in 'ssh -q oracle@${RHOST} ${CCMD}'; do
        echo "attempting to copy file: " $BackupFile
 
        scp -p $hostname:/db/remote_backup_area/$file /db/local_dump_area
 
        # or use rsync
        #rsync -av -e ssh oracle@${RHOST}:/db/remote_backup_area/${BackupFile} /db/local_dump_area"

done
exit

Any help much appreciated.
Moderator's Comments:
scp or rsync multiple files in parallel from a remote host code tags please

Last edited by jim mcnamara; 08-06-2012 at 01:47 PM..
# 2  
Old 08-06-2012
This will try to send all of the files:
Code:
RHOST=srv245005
CCMD="ls /db/remote_backup_area"
 
for BackupFile in 'ssh -q oracle@${RHOST} ${CCMD}'; do
        echo "attempting to copy file: " $BackupFile
 
        scp -pq $hostname:/db/remote_backup_area/$file /db/local_dump_area &
 
        # or use rsync

done
wait
exit

which can swamp the connection. This sends 10 files at a go

Code:

cnt=1
RHOST=srv245005
CCMD="ls /db/remote_backup_area"
 
for BackupFile in 'ssh -q oracle@${RHOST} ${CCMD}'; do
        echo "attempting to copy file: " $BackupFile
         
        scp -pq $hostname:/db/remote_backup_area/$file /db/local_dump_area &
        cnt=$(( $cnt + 1 ))
        if [ cnt -eq 10 ] then
           wait
           cnt=1
        fi

done
wait
exit

Change the "10" to something that is reasonable

If you want some kind of TTY ouput you cannot do the above, you have to write to a file on the scp command line.
Code:
( 
  echo "starting $file `date`" >/tmp/${file}.log
  scp -pq $hostname:/db/remote_backup_area/$file /db/local_dump_area 2>>/tmp/${file}.log
  echo "done $file `date`" >>/tmp/${file}.log
) &

This mess replaces the one line scp command in the earlier examples. And creates lots of logfiles.

Last edited by jim mcnamara; 08-06-2012 at 01:57 PM..
The Following User Says Thank You to jim mcnamara For This Useful Post:
Big_Jeffrey (08-07-2012)
# 3  
Old 08-06-2012
Hi Jim. Thanks for the reply. Did the above code work for you? I get an 'issue' in the first line of the for loop. It wont read the value of the $RHOST and $CCMD variables that are part of the loop condition .. so it does nothing unfortunately. If I hard code them in then it works .. I'm missing something from my code.
# 4  
Old 08-06-2012
Shouldn't you have backticks in the for-line?
Code:
 for BackupFile in `ssh -q oracle@${RHOST} ${CCMD}`; do

The Following User Says Thank You to 244an For This Useful Post:
Big_Jeffrey (08-07-2012)
# 5  
Old 08-06-2012
I find it hard to believe that even 1 rsync will not swamp your bandwidth as disk I/O should be WAY faster than the network.

If you want more speed try the -z (or --compress) rsync option and compress the data transfered.

Funny thing is I usually find that rsync swamps my network and even web service requests from/to the boxes concerned tend to timeout a lot. More often than not, I find myself using --bwlimit to slow things down!
The Following User Says Thank You to Chubler_XL For This Useful Post:
Big_Jeffrey (08-07-2012)
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Pause processes in remote host and resume execution in another remote host Saeya Darsan Shell Programming and Scripting 3 10-21-2013 04:28 PM
rsync multiple directories into single directory on remote wreckedred Shell Programming and Scripting 1 01-31-2011 04:58 PM
Help! How to find the local host after few ssh hops to remote host??? gomes1333 UNIX for Advanced & Expert Users 3 03-27-2010 10:49 PM
rsync transferring multiple files issue sardare Emergency UNIX and Linux Support 9 03-19-2010 09:40 AM
rsync multiple remote directories one connection sardare Shell Programming and Scripting 0 03-11-2010 12:44 AM
running commands to remote host from centralized host anjum.suri Shell Programming and Scripting 6 08-18-2009 10:55 AM
Run a shell script from one host which connext to remote host and run the commands SN2009 Shell Programming and Scripting 6 04-13-2009 04:39 AM
How to delete the files from local host to remote host krishna176 Solaris 3 03-24-2007 04:48 PM
Tar files, transfer to remote host and delelte source Dago Solaris 0 02-28-2006 04:35 PM
Backing up files to a remote host question. WeNdeL UNIX for Dummies Questions & Answers 3 10-02-2002 11:14 AM


All times are GMT -4. The time now is 10:53 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password