scp or rsync multiple files in parallel from a remote host


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scp or rsync multiple files in parallel from a remote host
# 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:
Mod Comment code tags please

Last edited by jim mcnamara; 08-06-2012 at 02: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 02:57 PM..
This User Gave Thanks to jim mcnamara For This Post:
# 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

This User Gave Thanks to 244an For This Post:
# 5  
Old 08-07-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!
This User Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy local files to single remote host but multiple folders using rsync

I'm trying to copy a file myfile.scr from my local Linux server to multiple folders on remote AiX server using single rsync command. Below command helps me copy the file "myfile.scr" from my localhost to a remote host folder "/app/deployment/tmpfiles" rsync --delay-updates -F --compress... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. UNIX for Beginners Questions & Answers

How to paste multiple files in parallel?

Hi all, I am trying to paste thousands of files together into a matrix. Each file has only 1 column and all the files have the same number of rows (~27k rows). I tried paste * > output as well as some other for loops but the output only contains the columns from the 1st and last files. The... (8 Replies)
Discussion started by: notimenocall
8 Replies

3. UNIX for Beginners Questions & Answers

scp of multiple files to remote server

Hello, I would like to scp multiple files to a remote server that requires a password for the process to be completed. I have 30 folders (x_1, x_2 ... x_30), each containing 25 files. What I want to do is scp 1 out of the 25 files (file called bvals) for all my folders to a remote server and... (3 Replies)
Discussion started by: nasia.m
3 Replies

4. Shell Programming and Scripting

How can we overcome Broken pipe error during scp,SFTP,Rsync while transferring big files.?

Hello All, Hope all are doing well. We use scp (some times sftp and rsync also) for transferring big files (around 2GB each ) from 1 Network to another Network. The Issues which we face :- During transfer some times( Once in 1 week (or twice)) , the speed of transfer gets down to 30 kb/s,... (2 Replies)
Discussion started by: Upendra Bhushan
2 Replies

5. Shell Programming and Scripting

Pause processes in remote host and resume execution in another remote host

Hi, Given addresses of 2 remote machines, using a shell script is it possible to get the state of running processes in "src" stop all the processes in "src" exit out of "src" ssh into "dest" resume the state of executing processes captured in step 1 in "dest" Assumption: "src" is... (3 Replies)
Discussion started by: Saeya Darsan
3 Replies

6. Shell Programming and Scripting

scp files that are 3 days older from remote server-

hello, i am trying to get a list of files to be scped from the remote server by running the below in my local unix server ( note - there is a passwordless connectivity setup made between the local and remote server) and, we use KSH. --- ssh $scp_host "find /a/b/c/*/ -iname "$remote_file"" >... (4 Replies)
Discussion started by: billpeter3010
4 Replies

7. Shell Programming and Scripting

rsync multiple directories into single directory on remote

I would like to find and backup all *.mp4 files from /Pictures and its sub-directories and move them to a single directory on a remote. I can find and move the files but I don't want the directory structure...just the files to be placed in a single remote directory. To find my files I use ... (1 Reply)
Discussion started by: wreckedred
1 Replies

8. Shell Programming and Scripting

rsync multiple remote directories one connection

Hi, I want to specify multiple remote directories but want to transfer them in a single command with one connection with remote server. e.g. rsync -vrt --size-only --delete user@host:/home/user1/dir1 user@host:/home/user1/dir2 user@host:/home/user1/dir3 .... local_dir/ I want to... (0 Replies)
Discussion started by: sardare
0 Replies

9. Solaris

How to delete the files from local host to remote host

Hi all, i am copying .gz files from production server to development server using "scp" command.my requirement is after copying .gz files i want to delete old .gz files(two days back) in development server from production server. like this way i need to delelte .log ,.z and .dmp files... (3 Replies)
Discussion started by: krishna176
3 Replies

10. UNIX for Dummies Questions & Answers

Backing up files to a remote host question.

I need to know how to successfully back up(and compress) files from a local machine to a remote host. Will this work? tar -cvf backup.tar -C /user/somedir | gzip backup.tar | rsh some.domain.com/user/somedir thanks in advance! (3 Replies)
Discussion started by: WeNdeL
3 Replies
Login or Register to Ask a Question