copy files from one source to multiple destination simultaneously
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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:
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.