How to Use rsync for Data Synchronization
`rsync` is a powerful utility for synchronizing files and directories between two locations, either locally or over a network.
Common Syntax
rsync [options] [source] [destination]
CopyUseful Options
- -a (archive): A quick way to say you want to recurse into directories and preserve permissions, times, etc.
- -v (verbose): Shows more output.
- -h (human-readable): Outputs numbers in a human-readable format.
- -P: Combines `--progress` (shows transfer progress) and `--partial` (allows resuming interrupted transfers).
Examples
# Sync a local directory to a remote server
rsync -avh /local/path/ user@remote_host:/remote/path/
# Sync a remote directory to a local directory
rsync -avh user@remote_host:/remote/path/ /local/path/
# Use the --delete flag to make the destination an exact mirror of the source
rsync -avh --delete /local/path/ user@remote_host:/remote/path/
Copy