LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-05-2010, 08:31 AM   #1
mdfakkeer
Member
 
Registered: Jul 2009
Location: India
Distribution: Fedora,ubuntu
Posts: 35

Rep: Reputation: Disabled
Wink copy files from one source to multiple destination simultaneously


i want to copy one or more files or directory from one drive to multiple drive simultaneously. It like a cloning a disk. But i dont like clone entire disk. i want to copy/clone only certine files or folder. if any one can know how to copy one source to multiple destination simultaneously. Is any tools available? how i can implement in perl?
 
Old 08-05-2010, 08:44 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679
To send to more than one directory simultaneously, you will need to use tee, and fifos.

mkfifo destdir1.fifo
tar -C sourcebasedir -cf - dir1 dir2 dir3 | tee destdir1.fifo | tar -C destdir2 -xf - &
tar -C destdir1 -xf destdir1.fifo

Last edited by jschiwal; 08-05-2010 at 09:08 PM.
 
Old 08-05-2010, 08:50 AM   #3
mdfakkeer
Member
 
Registered: Jul 2009
Location: India
Distribution: Fedora,ubuntu
Posts: 35

Original Poster
Rep: Reputation: Disabled
can you explian the same with example?. I am not understand. if i want to copy dir1 to destdir1, destdir2 and destdir3. how to implement
 
Old 08-05-2010, 08:53 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by mdfakkeer View Post
can you explian the same with example?. ...
You need to know how 'bash' (the interactive shell you are most likely using) works, especially, what is a job in background.

So, enter into your favorite WEB search engine

bash tutorial
.

You also need to understand how 'tar' works - for that read

man tar
.
 
Old 08-05-2010, 08:58 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679
I already gave an example.

For three destination directories, you would create another fifo pipe and have to consecutive tee commands.
... | tee dir1.fifo | tee dir2.fifo | ...

And two tar commands extracting from the fifo pipes, the first one running in the background.

It would be better to use a loop and copy to one destination directory at a time. Otherwise, an error in one would cause all to fail.
Also, if the destination directories are on the same filesystem, you will cause disk thrashing. The end resullt is that it will take much longer to accomplish.

Here is something I have used in the past:
tar -C basedir -czf - . | tee /mnt/backup/backup.tar.gz | ssh user@host 'tar -C destdir -xzvf -'

It saved a tar backup to an external drive, and replicated the files to a second computer.

An example of using tar to copy directories of files is explained in Section 4.6 of the tar info manual.

Last edited by jschiwal; 08-05-2010 at 09:01 AM.
 
Old 08-05-2010, 12:37 PM   #6
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,960

Rep: Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703
Quote:
Originally Posted by jschiwal View Post
mkfifo destdir1
tar -C sourcebasedir -cf - dir1 dir2 dir3 | tee destdir1 | tar -C destdir2 -xf - &
tar -C destdir1 -xf -
Hi jschiwal,

I tried your solution and it did not work for me. Note, that I have not used named pipes before - haven't had a need for them.
So I did some very basic reading on this concept and experimented a bit.
Here is my directory structure:
Code:
./sourcebasedir/
./sourcebasedir/dir1/
./sourcebasedir/dir2/
./sourcebasedir/dir3/
./destdir1/
./destdir2/
When I executed your code I first got an error that destdir1 is a directory. So I renamed the pipe to 'pipe1'. And finally this slightly altered code worked:
Code:
mkfifo pipe1
tar -C sourcebasedir -cf - dir1  dir2 dir3 | tee pipe1 | tar -C destdir2 -xf - &
tar -C destdir1 -xf pipe1
Did I miss something?

Last edited by crts; 08-05-2010 at 12:38 PM.
 
Old 08-05-2010, 09:14 PM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679
I must have cut and pasted the wrong text from the terminal, because I remember naming the fifo differently when I tested it out. I just did this example:
Code:
mkfifo bin1.fifo
tar -C bin -cf - . | tee bin1.fifo | tar -C bin2 -xf - &
tar -C bin1 -xf bin1.fifo
It copied my ~/bin/ directory contents to both ~/bin1 and ~/bin2.
 
Old 08-06-2010, 08:05 AM   #8
mdfakkeer
Member
 
Registered: Jul 2009
Location: India
Distribution: Fedora,ubuntu
Posts: 35

Original Poster
Rep: Reputation: Disabled
Thanks jschiwal. one source to muliple destination working fine.
 
  


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
[SOLVED] Files seem to take up more space in destination after rsync copy Karderio Linux - Newbie 6 09-22-2014 08:41 PM
copy files from one source to multiple destination simultaneously mdfakkeer Linux - Software 3 08-10-2010 04:25 PM
copying and simultaneously renaming multiple files in present working dir vijay_babu1981 Linux - Newbie 11 04-09-2010 11:07 AM
Copy files from various locations to a single destination folder deostroll Linux - Newbie 5 05-13-2009 07:52 AM
Konqueror - Renaming multiple files simultaneously RodWC Linux - General 9 11-29-2006 10:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:42 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
Open Source Consulting | Domain Registration