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 the local system or vice a Versa. This article will help you to sync files from a 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 the source and target location. Source and destination can be a local directory or remote systems directory.
rsync [OPTION] [SOURCE] [DESTINATION]
- The SOURCE can be directly referred to the local filesystem like /opt/backup etc or to remote file system like [email protected]:/opt/remotedir/
- The DESTINATION can be directly referred to the local filesystem like /opt/mydir or /var/www/html etc or to remote file system like [email protected]:/opt/remotedir/
- Both SOURCE and DESTINATION can refer to the local filesystem.
- One SOURCE or DESTINATION can refer to the remote filesystem. You can’t use both as a remote location.
Sync Files Local to Remote
For example to sync all files available on local system under /opt/mydir directory to remote server 22.214.171.124 at /opt/remotedir directory.
rsync -a /opt/mydir [email protected]:/opt/remotedir
Sync Files Remote To Local
For example to sync all files from remote server 126.96.36.199 at /opt/remotedir directory to local system directory /opt/mydir
rsync -a [email protected]:/opt/remotedir /opt/mydir