3

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.

mehturt
  • 91
  • 1
  • 9

2 Answers2

5

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.

Khaled
  • 36,533
  • 8
  • 72
  • 99
  • 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 04 '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 05 '12 at 06:40
  • @mehturt: If so, you can accept this answer! – Khaled Jan 05 '12 at 08: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 09 '12 at 14:16
0

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.

Bryan
  • 7,628
  • 15
  • 69
  • 94