Rsync Command in Linux to Copy Files to Remote Server with Examples

Rsync Command in Linux to Copy Files to Remote Server with Examples

rsync command is used to copy the files and directories to remote server and to copy the files and directories from remote server to local. rsync is an a open source linux command utility . rsync is faster than scp, since it uses incremental file transfer. that means it will copy the differences of files that have actually changed. in this blog post i will show you how to copy the files and directories with Linux rsync command.

install rsync linux command

to install rsync in redhat/rhel or debian/ubuntu use below commands.

yum install rsync

apt-get install rsync

send/copy/sync the files to remote server  by using rsync command

 

rsync -ahvz  --progress /local_machine_files_path  username@IP:/remote_machine_files_path

-a :      archive mode, by using archive mode we can  copy the files recursively and it preserves file permissions, user and group ownership's.

-v :     verbose

-h :     human-readable

-z :      in this mode it will compress the data

- -progress :     it will dispaly the progress of files remaining to complete the transfer

Ex:

rsync  -ahvz  --progress  /project/jboss     vidtem@192.168.12.7:/project/

it will prompt for password enter password, then it will copy the jboss directory from local machine to /project directory in remote machine.

download/copy/sync the directory from remote machine to local machine

rsync  -ahvz  username@IP:/remote_machine_path /local_machine_files_path

Ex:

rsync  -ahvz    vidtem@192.168.12.7:/project/rundeck    /project/

it will copy the rundeck directory from remote machine to local project directory

Encrypt rsync with SSH

By using SSH protocol with rsync we can transfer the data in a secured way. ssh will encrypt the data.  so that nobody can read your data while it is being transferred over the internet.So its better to use ssh with rsync while we are transferring the data. 

Copy/send/synch the files from local machine to remote server with ssh.  

rsync -ahvze ssh /local_machine_files_path  username@IP:/remote_machine_files_path

so when you are using ssh with rsync add -e  and ssh to previous coammnds.

rsync  -ahvze  ssh  /project/ojdbc.jar       vidtem@192.168.12.7:/project/

Here it will copy the ojdbc.jar from local to remote server project directory

download/copy/synch the files from remote server to local machine with ssh.

rsync  -ahvze ssh  username@IP:/remote_machine_path /local_machine_files_path

rsync  -ahvze   ssh    vidtem@192.168.12.7:/project/ojdbc.jar    /tmp/

here we are copying the ojdbc.jar file from remote server to local machine tmp directory with ssh encryption.

 

 

 

  • rsync command in linux
  • rsync examples ssh
  • rsync directory from one server to another
  • rsync directory linux
  • rsync copy directory

 

Leave a Reply

Your email address will not be published. Required fields are marked *