Error check for copying growing directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error check for copying growing directories
# 8  
Old 05-31-2013
As another wild guess here, it sounds to me like ningy is starting to copy files while they are being written and then removes them at the source (while they are still being written). I think the code needs to be modified to be sure the file is complete before the move starts.
# 9  
Old 06-03-2013
Thanks for the inputs everyone.

Yes, I was doing :

Code:
cp -rp source destination
ln -s  dest source
rm -rf source

But failed while some new files getting written to.

I have just started exploring find command with -newer option to check if new files are added by creating a file just before copy and checking before removing source. Not sure if thats the best thing to do but a start atleast
# 10  
Old 06-03-2013
Yes much better.
The goal is to make a check as close as possible.
I would even go for
Code:
find -type f -cmin +1 ... cp ...

if you have GNU find.
The maybe best approach is like your suggestion, but twice:
Code:
cd /path/to/source || exit
# create an empty file for a time comparison
 > findstart
find . -type f -print |
while IFS= read -r file
do
 # don't copy file if newer
 find "$file" -newer findstart | grep . >/dev/null && continue
 # another reference file
  > copystart
 cp -rp "$file" /path/to/destination/ || continue
 # don't delete file if newer
 find "$file" -newer copystart | grep . >/dev/null && continue
 rm -f "$file"
done
rm -f findstart copystart


Last edited by MadeInGermany; 06-03-2013 at 09:18 AM.. Reason: /dev/null was misplaced
# 11  
Old 06-03-2013
Quote:
Originally Posted by ningy
Thanks for the inputs everyone.

Yes, I was doing :

Code:
cp -rp source destination
ln -s  dest source
rm -rf source

But failed while some new files getting written to.

I have just started exploring find command with -newer option to check if new files are added by creating a file just before copy and checking before removing source. Not sure if thats the best thing to do but a start atleast
If I understand what you're saying, it won't solve your problem. You don't need to know if a file is new before you remove it; you need to know that a file is complete before you start copying it. You can only do that by having the server provide some indication that the data in the new file is complete. The client can't reliably know that the source file on the server is complete unless the server provides some unambiguous way to determine that.

What MadeInGermany recently proposed is a big step in the right direction, but there is still no guarantee that the process loading the file being copied will not have been sleeping or "swapped out" while the copy to the client was being processed.
# 12  
Old 06-03-2013
Quote:
Originally Posted by ningy
Thanks for the inputs everyone.

Code:
cp -rp source destination
ln -s  dest source
rm -rf source

But failed while some new files getting written to.

I have just started exploring find command with -newer option to check if new files are added by creating a file just before copy and checking before removing source. Not sure if thats the best thing to do but a start atleast
You could easily eliminate all of your headaches if you had a directory on the same filesystem as "source" that was dedicated to files in flight. Since it knows when it's done with a file, the script writing the file should be in charge of mv'ing from the in-flight directory to "source". This way, every file in "source" is guaranteed to be complete.

In my opinion, this is the simplest and most robust solution. Anything else will be either more complicated or less dependable or both.

Regards,
Alister
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