How to Use rsync to Resume Interrupted File Transfers
Are you transferring a large file with scp
only to have your network connection drop? It's frustrating to start over from scratch. This article will show you how to use the powerful rsync
utility to resume the transfer right where it left off.
Quick Comparison: scp vs. rsync
Both are tools for transferring files over SSH, but they have a key difference:
Scenario: A File Transfer with scp
Fails
Let's say you are trying to copy the file large-backup.tar.gz
to a remote server with the command:
Halfway through the process, your network connection is lost. Instead of running the same scp
command again, we'll use rsync
to continue.
Solution: Using rsync
to Resume the Transfer
Open your terminal again and execute the following command:
rsync
will check the partially transferred file on the destination server and will only send the missing parts, saving you a significant amount of time.
Breaking Down the rsync Command
Let's analyze the important flags we used:
-a
(archive): Enables archive mode, which is equivalent to-rlptgoD
. It preserves file attributes like permissions, ownership, timestamps, etc.-v
(verbose): Shows detailed output of the process.-P
: This is a very useful flag, combining--progress
(shows a progress bar) and--partial
(keeps partially transferred files). This is the key flag that enables the resume capability.--rsh=ssh
: Specifies thatrsync
must use the SSH protocol for the connection, ensuring the transfer is encrypted and secure, just likescp
.
Bonus Tip: Create a Shell Alias for Quick Use
To avoid typing the long command every time, you can create a shortcut (alias) in your shell's configuration file (e.g., ~/.bashrc
or ~/.zshrc
).
Add the following line to the end of the file:
Save the file and run source ~/.bashrc
(or source ~/.zshrc
). From now on, you only need to type:
Conclusion
While scp
is an excellent choice for quick copies of small files, rsync
is the true professional tool for large transfers or for use over unstable connections. Its ability to resume failed transfers is a real lifesaver that saves time and effort.