data copy on linux

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 file if all the data is already at the remote locations. Let’s see, how to copy data using rsync and scp command.

SCP command is also used to transfer the data on Linux machine but it copies all the data again if data already exist on 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 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 192.168.1.3:destinationlocation

Rsync on 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 192.168.1.3:destinationlocation

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

rsync -avzfh --remove-source-files /currentpathlocation –progress 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 server.

scp -r folder_location folder_destination

And you can also use scp command for remote location,

scp -P port folder_location folder_destination

You’re done

LEAVE A REPLY

Please enter your comment!
Please enter your name here

six + 1 =