Rsync is a useful utility for syncing files between two locations. It also provides option to sync files from a remote system. We can sync a file for directory of a remote system to our local system or vice a versa. This article will help you to sync files from remote server to local system and local system to remote system using rsync.
To sync files between two systems on network or two directories on local system. We need to define source and target location. Source and destination can be local directory or remote systems directory.
Local directories can be directly refer like file system ( eg: /opt/mydir , /var/www/html etc ).
to define remote directory we need ip address or hostname of remote system with user login details. We can define remote location like [email protected]:/opt/mydir. Remember that source and destination both can’t be remote locations.
$ rsync [OPTION] [SOURCE] [DESTINATION]
Sync Local to Remote:
For example to sync all local systems file under /opt/mydir to remote server 10.10.0.100 at /opt/remotedir directory.
$ rsync -a /opt/mydir [email protected]:/opt/remotedir
Sync Remote to Local:
For example to sync all on remote server 10.10.0.100 at /opt/remotedir directory to local system directory /opt/mydir
$ rsync -a [email protected]:/opt/remotedir /opt/mydir