LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-06-2013, 12:34 AM   #1
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
rsync question


is it possible to use rsync to copy files from one directory into multiple directories at once without having to chain rsync together?

ex:

Code:
rsync -aviS /source /backup1 /backup2 /backup3 ...
Thanks.
 
Old 01-06-2013, 07:26 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
I don't believe it is... The think best you'll get is

Code:
for dest in /backup1 /backup2 /backup3; do
    rsync -aviS /source $dest
done
Regards,
 
Old 01-06-2013, 09:01 PM   #3
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Original Poster
Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
ok thanks. that is what i thought, but i was hoping there was a way to send the files to multiple destinations at once. oh well.
 
Old 01-06-2013, 09:41 PM   #4
soupmagnet
LQ Newbie
 
Registered: Sep 2012
Posts: 27

Rep: Reputation: Disabled
Quote:
Originally Posted by lleb View Post
ok thanks. that is what i thought, but i was hoping there was a way to send the files to multiple destinations at once. oh well.
Just pipe your commands together:
Code:
rsync -aviS /source /destination1 | rsync -aviS /source /destination2 | rsync -aviS /source /destination3
Or pipe functions together in a shell script:

Code:
dest1(){
rsync -aviS /source /destination1
}

dest2(){
rsync -aviS /source /destination2
}

dest3(){
rsync -aviS /source /destination3
}

dest1 | dest2 | dest3
 
Old 01-07-2013, 05:56 AM   #5
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
@soupmagnet: I'm not sure that does what you think it does... You use piping to pass output from one command to another. If you just want to run them in sequence, regardless of the return status of the previous command, separate them with semicolons, or just put them on separate lines.
 
Old 01-07-2013, 06:04 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,122

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
by default, based on rsync internals rsync can only handle one destination (because it is compared to the sources)
 
1 members found this post helpful.
Old 01-07-2013, 07:39 AM   #7
alieblice
Member
 
Registered: Jul 2011
Posts: 80

Rep: Reputation: Disabled
if it going to send source file it should sync source to all destination separately. so it will be same as running it more than 1 time for different destination.
if you always use 1 repetitive command for all those destination it might be good idea to make alias of those command.
 
Old 01-07-2013, 05:06 PM   #8
soupmagnet
LQ Newbie
 
Registered: Sep 2012
Posts: 27

Rep: Reputation: Disabled
Quote:
Originally Posted by Snark1994 View Post
@soupmagnet: I'm not sure that does what you think it does... You use piping to pass output from one command to another. If you just want to run them in sequence, regardless of the return status of the previous command, separate them with semicolons, or just put them on separate lines.
I understand piping, at least at the surface. But I have been able to (seemingly) run commands simultaneously with it (i.e. using wget to download seperate files). If I pipe two wget functions together to download large files and have each function check for the other file before continuing, or have a loop to check that all files are downloaded before continuing, the files will download simulatneously (again, seemingly), rather than waiting for one to download before starting on the next.

In this case, it tested out to be functional. I used three destinations for a fairly large source directory and the resulting directories, using 'diff', match the source directory and the other destination directories. Obvoiusly, I'm still learning, so what exactly is wrong with piping commands together for the purpose of simply running them simultaneously?

And thank you for your input.

Last edited by soupmagnet; 01-07-2013 at 05:11 PM.
 
Old 01-07-2013, 08:05 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
As per post #5; piping is for sending the output of the first cmd to the input of the 2nd cmd and so on.
In this case its redundant (even though it would still 'work'), because there is no dependency between the cmds/fns.
If you wanted them to run concurrently you could background them all
Code:
dest1 &
dest2 &
dest3 &
If there's no output/input dependency, but you want to only run subsequent cmds if prev ones succeed, use '&&'
Code:
dest1 && dest2

These are worth bookmarking/reading
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

Last edited by chrism01; 01-07-2013 at 08:06 PM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rsync question mokku Linux - Newbie 1 05-31-2008 09:56 AM
rsync question mahmoud Linux - Software 5 04-25-2008 06:13 AM
rsync question hepburnenthorpe Linux - General 1 11-19-2006 06:19 PM
rsync question nazs Linux - Software 1 10-23-2006 08:31 PM
Rsync Question stefaandk Linux - General 2 05-13-2006 12:12 AM


All times are GMT -5. The time now is 12:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration