What happens if a file is modified while you’re copying it

cpfile-copy

What is the effect of copying a file say fileA.big (900mb) from location B to locationC. If during that cp operation, say 35% through the process, fileA.big is appended with new information and grows from 900mb to 930mb.

What is the result of the end copy (i.e. fileA.big at locationC)?

What if the copy is about 70% through, and the original file is updated but this time truncated to 400mb (i.e. the progress of the copy is beyond the truncation point), what is the result of the end copy?

Referring to a linux OS on an ext3/ext4 filesystem. No volume shadow magic etc.. Just plain old cp. Curiousity sparked by copying live couchdb files for backup, but more interested in general scenarios rather than specific use case.

Best Answer

If fileA.big is grown during the copy, the copy will include the data that was appended.

If the file is truncated shorter than where the copy is currently at, the copy will abort right where its at and the destination file will contain what was copied up to the time it aborted.

Related Question