Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there any way to copy directory from one filesystem to another but remove the partial file in case we run out of disk space on target filesystem?
I searched cp and rsync manuals but did not find anything; I could do this in a shell script but wanted to avoid it if possible.
At present I do:

cp -r /source /dest

or

rsync -avr /source /dest

m.

share|improve this question
    
Does rsync really leave partial files? –  jkj Jan 19 '12 at 8:14
add comment

2 Answers

If you look at the rsync manual, you can read:

--partial
     By default, rsync will delete any partially transferred file if the transfer is
     interrupted. In some circumstances it is more desirable to keep partially 
     transferred files. Using the --partial option tells rsync to keep the partial file
     which should make a subsequent transfer of the rest of the file much faster.

This means that you don't need to worry about partial transfer.

You can make sure of the --partial-dir=DIR option. Then, you can remove all files under this directory if you want to eliminate partially transferred files.

share|improve this answer
1  
Actually, I looked at this switch already and even thought I'm not using it, the partial file is present on dest filesystem but with a different name (dot prefix and a few chars suffix). –  mehturt Jan 4 '12 at 13:50
    
I looked at this more closely and see this behavior, which seems strange to me: when using --partial-dir the partial file is not present on filesystem full even if --partial is specified as well; but this would achieve what I needed. –  mehturt Jan 5 '12 at 6:40
    
@mehturt: If so, you can accept this answer! –  Khaled Jan 5 '12 at 8:03
    
not really, because it does not say what is going on. The answer I was looking for is to use --partial and --partial-dir and in that case the partial file is not present in partial-dir when running out of disk space, just like I described in my comment. –  mehturt Jan 9 '12 at 14:16
add comment

Best way would be to check for free space before the copy is started (with a little space in excess).

The normal behaviour of cp is to drop the incomplete file.

share|improve this answer
    
This is not what I see (using cp on RHEL) - the incomplete file is present on dest filesystem. –  mehturt Jan 4 '12 at 13:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.