I already wrote about rsync 5 years ago in another blog post. But today I am going to write a separate article that will help you to become a master in using rsync. Rsync is one of the most useful tools for system administrator and others who are responsible to maintain DevOps tasks. So it’s worth bookmarking this article for you as a rsync reference.
I am not going to write lots of stuff about what it is and why it’s useful. Straight I am going to discuss about it’s usage. First, we need to know some basic command structure for rsync.
You need to understand the basics to formate a command for rsync.
rsync options source destination
Common options for rsync
Here are some common options for rsync those are most popular and requires for most of the use case.
- -q, –quiet suppress message output
- -h, –human-readable display the output numbers in a human-readable format
- -a, –archive archive files and directory while synchronizing ( -a equal to following options -rlptgoD)
- -v, –verbose Verbose output
- -b, –backup take the backup during synchronization
- -l, –links copy symlinks as symlinks during the sync
- -r, –recursive sync files and directories recursively
- -n, –dry-run perform a trial run without synchronization
- -e, –rsh=COMMAND mention the remote shell to use in rsync
- -u, –update don’t copy the files from source to destination if destination files are newer
- -z, –compress compress file data during the transfer
- –progress show the sync progress during transfer
Transfer file from local to remote (via SSH)
It’s one of the most common use-case for all. We need to transfer files from here to there and from there to here. Personally I need to do few times daily basis. But it saves my day.
Here is the simple commands to transfer your local file to any remote system via SSH with rsync.
rsync -avz local_directory/ ssh_username@ip_address_of_remote_server:/home/