0

In the remote directory I have a file 'checkpoint.tar', I also ended up transferring a file with the same name 'checkpoint.tar' from my home directory to the remote directory via scp. I then cancelled this transfer halfway through. Will the file be corrupted by this half-overwrite? Will it have reverted to the original state?

Somni
  • 3
  • What happens if you start a local cp, and cancel it half way through? I bet the same thing happens. – RonJohn Mar 31 '23 at 20:15
  • @RonJohn that's not actually inherently true, no. Sometimes it's similar, sometimes not. It depends on your version of cp and your libc, the filesystem on which you're copying (or whether you cross filesystems) and how larger your file is. – Marcus Müller Mar 31 '23 at 22:52
  • @RonJohn for a more nuanced discussion of that, I recommend forest's answer to this question as well as the discussion under my answer there (more than my answer itself), though I do believe that the current releases of the major Linux distros will now do copy_file_range by default, with copy sizes above what you usually get per read/write pair, so that larger files get copied atomically from cp's perspective. (Given filesystem support of course) – Marcus Müller Mar 31 '23 at 22:57

1 Answers1

2

scp does not do anything special with its target file(s). It uses a standard "truncate and write" approach, so the target file checkpoint.tar will now consist of a partial copy of your most recent source file.

You can verify this by looking at the file date and size, and also running tar tvf checkpoint.tar from the destination server to list the files the tarball contains.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287