Understanding the difference — (Rsync and SCP)

Govind Kumar
axcess.io
Published in
3 min readAug 26, 2018

As a System Administrator, you come across the remote administration. Replication of file within the same node is a cake walk, at the same time mirroring or backing up the file at remote instance becomes dolorous. Understating the exact way to do so for the same will provide you the resilience in terms of achieving that in an embellished way without frittering your time. I witnessed umpteen admins struggling while selecting the correct tool and copying the contents from one node to the other remote node. When it comes to remote copying, there are various things that are needed to be taken into consideration(eg. speed, security, Bandwidth, data replication ). Copying humongous files and taking backup can be achieved with an ease after understanding the difference between the two utilities, i.e. rsync, and scp.

rsync(remote sync): A very flexible network enabled syncing tool, a copy that doesn’t send things that are already at the destination and in case of connection interruption, can pick up quickly by reissuing the same command. A great utility in terms of taking the backup or doing the incremental transfer.

scp(secure copy): A raw copy, its a dump copy that absolutely copies what you ask. A very good utility for copying the files that are of small size.

Some practical uses will make you understand these commands better.

rsync :

* It will copy the contents of the source folder into dest_folder

#rsync source_folder/ dest_folder/ 
  • It will copy the source folder itself in the destination folder. ( absence of / will make the difference):
#rsync source_folder dest_folder/
  • Want to copy the directory? Use -r along with the command
#rsync -r source_folder/ dest_folder/
  • To check which contents are to be copied inside the dest_folder (without — dry run option it will actually copy).
#rsync -av source_folder/ dest_folder/ -—dry-run (a for archiving and v for verbosity)
  • Want to delete the contents inside the dest_folder, which is not present in the source folder? Try this :).
#rsync -av —-delete source_folder/ dest_folder/
  • Want to compress the file before sending the file to the remote location?
#rsync -zaP source_folder 192.168.0.0:~/dest_folder (z for compression, P for showing progress bar and a for archiving).
  • The last one for all the Cloud guys who want to copy the file from the local machine to cloud instance and vice versa using the key file via ssh.(here key.pem is the private key for your remote instance).
#rsync -avzP -e “ssh -i ~/key.pem” file_to_be_transferred ec2-user@1.2.3.4:~/

SCP:

  • Copy one single local file to a remote destination:
#scp /path/to/source-file user@host:/path/to/destination-folder/
  • Want to copy one single file from a remote server to your current local server?
#scp user@host:/path/to/source-file /path/to/destination-folder
  • Copy one single file from a remote server to another remote server?
#scp user1@server1:/path/to/file user2@server2:/path/to/folder/
  • Want to copy multiple files with one command?
#scp file1.txt file2.txt file3.txt govind@host.example.com:/home/govind/
  • Want to copy all files in a folder recursively to a remote server?
#scp -r /home/user/html/* govind@host.example.com:/home/govind/backup/
  • Want to copy files from Linux to Windows?
#pscp user@remote-server:/path/to/remote-file c:\path\to\local-folder\
  • The last one for all the cloud guys:
#scp -i "key.pem" soure_file ec2-user@1.2.3.4:~/ 

There are various other options that you can make use of while copying the files and doing the remote administration.

The conclusion is, rsync is good for incremental transfers and for taking the backup while scp is good while securely pushing or pulling the small file from or to the remote nodes.

--

--

Govind Kumar
axcess.io

Technology Evangelist | AWS Golden Jacket | Practice Lead Cloud Migration @Axcess IO | Cloud Arch. | RHC(SA/E) | AWS (DevOps/Sol. Arch) — Pro. | CCNA