How to use Rsync for push to remote or pull from remote server

Rsync (Remote Sync) is a most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems. With the help of rsync command you can copy and synchronize your data remotely and locally across directories, across disks and networks, perform data backups and mirroring between two Linux machines.

Using rsync is the best way copy large size files from/to remote servers.

Since scp command won’t support sync/continue option it’s better to use rsync.

Instead of downloading whole file again after our network got disconnected rsync will download only missing part.

Pull with rsync (copying from remote server):

$ rsync -av –partial –progress –rsh=”ssh” user@hostname:<remote_directory/file> <destionation_path>

Push with rsync (copying to remote server):

$ rsync -av –partial –progress –rsh=”ssh” <source file/directory> user@hostname:<destionation_path>

or

$ rsync -v -e ssh <source file/directory> user@hostname:<destionation_path>

If you are using any other port for ssh use –rsh=”ssh -p <port_number>”

Eg: –rsh=”ssh -p 12345″ where 12345 is port number.

Source