Error check for copying growing directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error check for copying growing directories
# 1  
Old 05-31-2013
Error check for copying growing directories

I have a simple script which copies directory from one place to another and deleting the source .
I am facing a situation when new files gets added when the script has started running. Its resulting in data loss

Please suggest a way to avoid data loss. I googled a lot but most are perl solutions . I am looking for something is shell script.
# 2  
Old 05-31-2013
what ratio of files is being seen when you do 'ls -ltr' as changed. whats the frequency of change and what's the phenomena how often these file are updated

cyclic check on files being transferred would be a better idea. Do you expect the files changing every 1 sec, 1 minute or what. calculate that time's mean value and then start transferring them.

2ndly, you may try some register file, where you can write down the files being transferred so far and then in the next run of the script, avoid them.
# 3  
Old 05-31-2013
the files are posted at random intervals . So I would not be sure.

Requirement here is to clean up the source after proper copy .
# 4  
Old 05-31-2013
Don't cp, use mv instead. mv is an atomic command, deleting the source only if copy succeeded.
# 5  
Old 05-31-2013
mv is safe if source and destination are in the same file system.
On different file systems, it must copy the data like cp.
--
It might help to only copy files with ctime greater than 1 hour.
# 6  
Old 05-31-2013
Quote:
Originally Posted by MadeInGermany
mv is safe if source and destination are in the same file system.
On different file systems, it must copy the data like cp.
Agreed. But wouldn't it delete the source only if the copy across file systems succeeded?
# 7  
Old 05-31-2013
Quote:
Originally Posted by ningy
Please suggest a way to avoid data loss.
No offense intended (just honesty), but you're problem statement is useless. Given its utter lack of specificity, I'm surprised anyone invested any of their time in responding to it.

Accurate answers to the following questions will probably lead to a quick resolution:

* What operating system you are using?
* What are the exact commands used to add files to the current directory?
* What are the exact commands used to copy the files to their new location?
* Are these two directories part of the same filesystem?
* What are the exact commands (if any) that are run as part of any subsequent clean up.
* What exactly do you mean by data loss? Are entire files missing? Are you seeing partially complete files? Something else?

For all we know, your problem may be as simple as misusing 'rm -fr' when 'rmdir' is required.

In the future, if you would like accurate, focused assistance, save everyone (yourself included) time and be specific from the start.

Regards,
Alister

Last edited by alister; 05-31-2013 at 05:25 PM..
This User Gave Thanks to alister 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

Copying files to directories based on first 6 character

guys, i did create a script but its too long, though it function the same. # cat nightlyscan.sh #!/usr/ksh deyt=`date +"%Y-%m-%d"` for i in `ls -lrt|grep $deyt|awk '{print $9}'` do cp -f $i /S1/Sophos/logger/ done # but i did not paste it all. this is the desired. (9 Replies)
Discussion started by: kenshinhimura
9 Replies

2. UNIX for Dummies Questions & Answers

Copying Directories from one server to another

Hi, I have a requirement where I have to connect to another server and copy directories from one server to another Directories on the Source server look like below (YYYY-MM-DD- 1 to 23) drwxr-xr-x 2 test_user dmfmart 422 Sep 1 23:45 2014-09-01-18 drwxr-xr-x 2 test_user dmfmart ... (3 Replies)
Discussion started by: arunkesi
3 Replies

3. UNIX for Dummies Questions & Answers

How to check if my log file is growing properly?

Hi All, I want to check if one my log file is updating properly, how can I achieve it. The approach I am trying is to get the file size at two different interval and than comparing it eg : $ ls -ltr | tail -1 | awk '{print $5}' 20480 (7 Replies)
Discussion started by: mukulverma2408
7 Replies

4. Shell Programming and Scripting

Copying data from files to directories

I have the following that I'd like to do: 1. I have split a file into separate files that I placed into the /tmp directory. These files are named F1 F2 F3 F4. 2. In addition, I have several directories which are alphabetized as dira dirb dirc dird. 3. I'd like to be able to copy F1 F2 F3 F4... (2 Replies)
Discussion started by: newbie2010
2 Replies

5. Shell Programming and Scripting

Copying all directories while ignoring certain filetypes

I want to write a script that copys over a complete folder including the dirs to another location. However in the process I want to ignore several filetypse that SHOULD NOT get copied over. I know Global Ignore is capable of make the copy command ignore one file type, however I don't know how... (8 Replies)
Discussion started by: pasc
8 Replies

6. UNIX for Dummies Questions & Answers

Using find -d and copying to the found directories

Hi again All :) After posting my first thread just a few eeks ago and having such a great response (Thank You once again :) ), I thought I'd perhaps ask the experts again. In short I'm trying to achieve a "find" and "copy" where the find needs to find directories: find -d -name outbox and... (6 Replies)
Discussion started by: Dean Rotherham
6 Replies

7. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

8. UNIX for Dummies Questions & Answers

copying to multiple directories using wildcard

Can we copy a file to multiple directories using a single command line , i tried with * didnt work for me cp /tmp/a.kool /tmp/folder/*/keys/ I am tryn to copy a.kool file to all keys folder in /tmp folder. is something i am missing ? (4 Replies)
Discussion started by: logic0
4 Replies

9. UNIX for Dummies Questions & Answers

Copying multiple directories at the same time using Unix

Another Unix question. How would I copy multiple directories at the same time? Right now I do: cp -r -f /directory1/ ../backup/directory1/ I do that for each directory one at a time. But there are multiple directories I'd like to copy. So instead of sitting there and doing one at a time, is... (9 Replies)
Discussion started by: JPigford
9 Replies

10. UNIX for Advanced & Expert Users

How to check a file in UNIX is closed or growing?

We have a third party tool in UNIX to kick off a 'file copy' job based on a file existance. If a specific file exists in an UNIX directory, another process should start copy the file into another system for further processing. The issue is, the copy job is starting as soon as the file exists in... (6 Replies)
Discussion started by: kslakshm
6 Replies
Login or Register to Ask a Question