问题
I use scp shell command to copy huge folder of files.
But at some point of time I had to kill the running command (by Ctrl+C or kill).
To my understanding scp copied files sequentially, so there should be only one partially copied file.
How can same scp command be resumed to not overwrite successfully copied files and to properly handle partially copied files?
P.S. I know I can do this kind of stuff in rsync, but scp is faster for me for some reason and I use it instead.
回答1:
You should use rsync
over ssh
rsync -P -e ssh remoteuser@remotehost:/remote/path /local/path
The key option is -P
, which is the same as --partial --progress
Other options, such -a
(for archive mode), and -z
(to enable compression) can also be used.
The manual: https://download.samba.org/pub/rsync/rsync.html
回答2:
An alternative to rsync:
Use sftp
with option -r
(recursively copy entire directories) and option -a
of sftp
's get
command to resume partial transfers of existing files.
Prerequisite: Your sftp
implementation has already a get
with -a
option.
Example:
Copy directory /foo/bar
from remote server to your local current directory. Directory bar
will be created in your local
current directory.
echo "get -a /foo/bar" | sftp -r server
回答3:
Since OpenSSH 6.3, you can use reget command in sftp
.
It has the same syntax as the get
, except that it starts a transfer from the end of an existing local file.
回答4:
Another possibility is to try to salvage the scp you've already started when it stalls.
ctrl+z to background and stop it, then ssh over to the receiving server and login, then exit. Now fg the scp process and watch it resume from 'stalled'!
回答5:
When rsync stalls as well after couple of seconds when initially running fine I ended up with the following brute force solution:
cat run_me.sh
#!/bin/bash
while [ 1 ]
do
rsync --partial --progress --rsh=ssh user@host:/path/file.tgz file.tgz &
TASK_PID=$!
sleep 60
kill $TASK_PID
sleep 2
done
回答6:
You can make use of the -rsh
and -P
options of rsync
. -P
is for partial download and -rsh
indicates transfer is over ssh procotol.
The complete command would be :
rsync -P -rsh remoteuser@remotehost:/remote/path /local/path
回答7:
I got the same issue yesterday, transfering a huge sql dump over via scp, I got lucky with wget --continue the_url
That blog post explains it quite well http://www.cyberciti.biz/tips/wget-resume-broken-download.html
来源:https://stackoverflow.com/questions/26411225/how-to-resume-scp-with-partially-copied-files