Copy Data Using Rsync And SCP Command On Linux 7

Rsync is a very flexible network-enabled tool for transferring the data from Linux to Linux machine. It copies only changed files if all the data is already at the remote locations. Let’s see, how to copy data using rsync and scp command.

Copy Data Using Rsync And SCP Command On Linux 7:

SCP the command is also used to transfer the data on the Linux machine but it copies all the data again if data already exists in the remote locations.

Check Out: How To Access Linux Server Using PPK Key From Winscp

Suppose you have folder name file1 and the same folder exist on the remote location and you just want to add only changed file. So rsync is the solution for this.

rsync -avzfh /currentpathlocation user@192.168.1.3:/destinationlocation

The above command will work if you have allowed ssh on 22 port. If ssh port changed to some other ports. So you need to run the below command.

rsync -avzfh -e ‘ssh -p 4000’ /currentpathlocation –progress user@192.168.1.3:/destinationlocation

Rsync on a local server, just simply run the below command

rsync -avzfh folder_location folder_destination

Check Out: SSH Password-less Login Using SSH Keygen In Linux

you can also use –-include and –-exclude command to match the pattern.

rsync -avzfh –-include “a* –-exlude “*.txt”f older_location folder_destination

Support if file or directory doesn’t exist at the source but exist at the destination and you want to delete it while syncing then use –delete

rsync -avzfh --delete /currentpathlocation 192.168.1.3:destinationlocation

Check Out: How To Install NFS Server For File Sharing On Linux

you can also set the max file size to be sent over the network using rsync.

rsync -avzfh ssh --max-size=”100MB” /currentpathlocation user@192.168.1.3:/destinationlocation

let’s suppose we need to delete the source files automatically,

rsync -avzfh --remove-source-files /currentpathlocation –progress user@192.168.1.3:/destinationlocation

Set bandwidth limit and transfer files with “–bwlimit=100”.

Check Out: How To Delete File And Logs Older Than 30 Days In Linux

Step 2: SCP Commands

you can use scp command to copy the files on both remote and local servers.

scp -r folder_location folder_destination

And you can also use scp command for a remote location,

scp -P port folder_location folder_destination

You’re done

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment