Friday, April 5, 2013

Resuming a failed file copy

Let's say that you want to copy a very big file, in slow or faulty media like a cheap USB stick or disk, and the copy fails leaving you with an incomplete file:

olimpo:/Linux_minimal# ls -la
total 18739092
drwx------ 2 root root        4096 Apr  3 16:22 .
drwxr-xr-x 8 root root        4096 Apr  3 15:11 ..
-rw-r--r-- 1 root root 19170066432 Apr  3 16:46 Linux.dsk
-rw-r--r-- 1 root root         211 May  2  2010 create.txt
-rwxr-xr-x 1 root root         154 Apr  2 16:02 launch

olimpo:/Linux_minimal# ls -la ../Linux_test2
total 19417644
drwxr-xr-x 2 root root        4096 Mar 28 16:55 .
drwxr-xr-x 8 root root        4096 Apr  3 15:11 ..
-rw-r--r-- 1 root root 19864223744 Apr  2 15:47 Linux.dsk
-rw-r--r-- 1 root root         211 May  2  2010 create.txt
-rwxr-xr-x 1 root root         154 Apr  2 16:02 launch

What a frustration! No matter how many times you try to copy the file, the copy operation aborts before doing the task.

Fortunately you can resume the copy with rsync:

olimpo:/Linux_minimal# rsync --progress --partial --append ../Linux_test2/Linux.dsk Linux.dsk
Linux.dsk
 19864223744 100%   10.87MB/s    0:01:00 (xfer#1, to-check=0/1)

sent 694242119 bytes  received 31 bytes  11107874.40 bytes/sec
total size is 19864223744  speedup is 28.61

And just to be sure, you can check the files with diff (the slow way) or md5sum (the quick way):

olimpo:/Linux_minimal# md5sum Linux.dsk
eccc1436fe7a10acb44973449fd430bc  Linux.dsk

olimpo:/Linux_minimal# md5sum ../Linux_test2/Linux.dsk
eccc1436fe7a10acb44973449fd430bc  ../Linux_test2/Linux.dsk

More information:

How To Resume Failed copy ( cp command ) where it left off?