Script for File Copy


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for File Copy
# 1  
Old 12-13-2016
Script for File Copy

Hello All,
This is my first post to unix.com.
I have requirement to copy multiple *.dmp files from one server to other server.
I have that other server NFS filesystem mapped to source server.
Dump[*.dmp] files are so huge almost 20TB. There are around 15-20 files each of 1.1TB.
I want to copy these files from one server to other server.
But I do not want to start copying all files at once.
Usually we do it manually copying 3 files at a time to reduce network bandwidth consumption.
Is there any way to write script to copy 3 file at one time and after 3 are done then new 3 files to be picked for file copy.
I have linux operating system.

Thanks
Amit Bansode
# 2  
Old 12-13-2016
Welcome to the forum.

Not sure I grasped your requirement (or problem) in its entirety. If you
Code:
cp *.dmp target

, there will always be just one single file on its way. And, increasing the count of copying processes will not necessarily improve the overall time consumed, as competition conditions on all types of resources will slow down the operation.
# 3  
Old 12-13-2016
Welcome Amit Bansode,

I'm sure we can help, but I have a few to questions pose in response first:-
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using? There are several producers of 'Linux', e.g. Red Hat, Debian, Mint, Centos, etc.
  • Are your certain that the files are idle? Copying mid-update would have unpredictable results.
  • What are your preferred tools? (C, shell, perl, awk, sftp, rsync etc.)
  • Are there three servers involved here or just two? Which one really has the data and where does it need to go?
  • What disk hardware does this sit on? Local disk, SAN supplied, shared SAN even?
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
  • Would copying each sequentially only one at a time be acceptable?
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.



Kind regards,
Robin
# 4  
Old 12-14-2016
I would have never considered to transfer all the files simultaneously, so I don't quite understand your problem.

If you want to transfer 3 files at the same time, a poor man's solution would be to run 3 cp commands in the background and then wait until all of them are done.

A more clever solution would be to monitor the child processes, and as soon one is finished, starts the next background process.

Without understanding your exact requirements, it is difficult to suggest a concrete solution.
# 5  
Old 12-14-2016
how would I copy 3 files at time ?
How to check the status of previous file copy
Is there any loop which copies first 3 files and then pickup next 3 files until last one.
You are right , I can not start all file copy simultenously it will choke up network.

Thank you for all your time and suggestion..

Thanks
Amit Bansode
# 6  
Old 12-14-2016
If you put a cp command in the background, you can get the process id as $! from which you can then watch the processes running. Perhaps some logic like this might help:-
  • Set count of current active copies to zero
  • Loop a list of all files to send
    • If the number of active copies is less than 3
      • Start a copy in the background
      • Store the process id
    • If the number of copies is 3
      • Check the saved process numbers are still running and reduce the active copies count if needed
  • End of loop

... or just ...
Code:
cd /source/directory
for source_file in *
do
   cp "$source_file" /target/direcory
done

... will do it sequentially and probably no slower overall.

The time taken for the copy will all be based on the contention between disk access and network access. Trying to squeeze multiple jobs through either of these constraints is even likely so be slower overall unless the bottlenecks are multi-pathed in some way so they can spread the load, e.g. your connection to the SAN is 8x1Gb fibre and they load balance (rather than just failover) or you have network throttling on a per-conversation basis, but that's probably more likely for an FTP rather than a cp.

Why do you believe sending 3 files at a time be beneficial?


Robin
# 7  
Old 12-14-2016
Quote:
Originally Posted by Amit Bansode
how would I copy 3 files at time ?
As I said, you do this by copying in the background. From a shell (bash, zsh, ksh,...), you do it by appending an ampersand to the statement, for example:

Code:
cp source target &

The variable $! holds the process ID of the background process. You will use it to monitor this process.

Quote:
Originally Posted by Amit Bansode
How to check the status of previous file copy
If you want to wait, until all of the jobs are finished, have a look at the wait command in the bash man page.

If you want to check, whether a job is alive (without waiting), send it the signal 0 and evaluate the return code:

Code:
kill -0 $process_id_of_your_background_job


Last edited by rbatte1; 12-14-2016 at 12:39 PM.. Reason: Added CODE tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with file copy script

Hello, I am still pretty new at writing shell scripts and may have bitten off more than I can chew. I am trying to write a script that figures out if a file exists (a known name) in directory a, then copy it to my selected destination, otherwise, look in directory b and check there. If it is in... (14 Replies)
Discussion started by: r34lj4k3
14 Replies

2. Shell Programming and Scripting

File copy script

Looking for help on a script that does the following. Reads a text file with ~5000 lines that look something like this: /folder/path/path2/pathX/file.lua,d/1.2699.gz /folder/path/path4/pathX/file2.lua,d/1.2699.gz /folder/path/path2/pathX/data/file3.lua,d/1.2699.gz And copies the file from... (8 Replies)
Discussion started by: kwalan
8 Replies

3. Shell Programming and Scripting

Shell script to copy file

Dear all, I have a database with thousands of files with the structure of name is: Filename_hour_year.abc Filename_hour_year_1.abc .............. So what I need is how to write a script that all file with contain the character "_1" will copy to "_2" For example: file name:... (7 Replies)
Discussion started by: hainguyen1402
7 Replies

4. UNIX for Dummies Questions & Answers

Script to copy file small interval file

HI Guys whenever i post a transaction , abcd.in file is stored in the temp and vanishes when the transaction is compleated . the abcd.in file stays for 1 sec in temp is der any solution to capture the abcd.in file to another directory cp -r /tmp/abcd.in /tmp/smith.in when i used the... (1 Reply)
Discussion started by: kalyankalyan
1 Replies

5. Shell Programming and Scripting

Match File and Copy File Script (Homework, Closed)

Can you please help on this? I am looking for the shell script which does following:- step 1: It should open the file /u/manish/input/FileIndex.dat and read line by line step 2: Once first line is read (for ex: File1), we have to find a file, that contains this matching... (4 Replies)
Discussion started by: teteguru1
4 Replies

6. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

7. Shell Programming and Scripting

copy file from script file to remote computer

hi, i want copy one or group of file from a computer to others, but i have some problem that do not allow me to do this. i do this by scp command like this : scp <file name> root@cpName:destinationAddress but the problem is that it do not it automatically. it means when it is connecting to... (4 Replies)
Discussion started by: MShirzadi
4 Replies

8. Shell Programming and Scripting

Script to capture new lines in a file and copy it to new file

Hi All, I have a file that gives me new line/output every 5 minutes. I need to create a script that capture new line/output besides "IN CRON_STATUS", in this case the new output is "begin ------ cron_status.sh - -----------". I want this script to capture the line starting from "begin ------... (0 Replies)
Discussion started by: fara_aris
0 Replies

9. Shell Programming and Scripting

Script look for file ,sort and copy to other direcotry

Hi I am in a situation to write a shell script that looks for the flat files continuosly and if files exists in that directory sort on the files and get the latest file(File comes with timestamp at the end) and copy the latest file to the other directory and again copy the next one to the same... (0 Replies)
Discussion started by: reddi22
0 Replies

10. Shell Programming and Scripting

Help:Copy file from one to other using script

Hi Frineds, Through my DTS process I am generating one file at one directory like, /sqlsrvr_demo/dts/put/transaction_fact.csv now I want to copy this files(only when the files size is greater than 0 kb) to some other directory like /sqlsrvr_demo/dts/get/transaction_fact.csv Can... (2 Replies)
Discussion started by: sunnysunny
2 Replies
Login or Register to Ask a Question