Rsync is a useful utility for syncing files between two locations. It also provides an option to sync files from a remote system. You can sync a file or a directory from the remote system to local system or vice a versa. This article will help you to sync files from remote server to a local system and local system to a remote system using rsync command.
To sync files between two systems on network or two directories on the local system. We need to define source and target location. Source and destination can be a 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 you need IP address or hostname of the remote system with user login details. You 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