rsync
is a powerful and versatile command-line tool used for syncing and copying files and directories between different locations. It is commonly used for backups, mirroring directories, or transferring files over a network while minimizing data transfer by copying only the changes between the source and destination.
Rsync runs on every linux distribution. Installation is very simple and can be done in several ways. See our Setup Rsync section.
rsync [options] source destination
-a
: Archive mode (recursively copies and preserves permissions, symbolic links, timestamps, etc.).-v
: Verbose (shows the progress of the transfer).-z
: Compresses files during transfer.-P
: Shows progress and allows for partial transfers in case of interruptions.--delete
: Deletes files in the destination directory that no longer exist in the source directory.To sync files from a local directory to a remote server using SSH:
rsync -avz /path/to/local/dir user@remote:/path/to/remote/dir
This command will transfer all files from the local directory to the remote directory over SSH, preserving file permissions and using compression to speed up the transfer.
Backup with Hard Links: Create a backup with hard links to save space:
rsync -a --link-dest=/path/to/previous/backup /path/to/source /path/to/new/backup
Bandwidth Limiting: Limit the bandwidth used during transfer:
rsync -avz --bwlimit=1000 /path/to/source user@remote:/path/to/destination
Excluding Files: Exclude specific files or directories:
rsync -avz --exclude 'node_modules' /path/to/source user@remote:/path/to/destination
When using rsync
over SSH, ensure that your SSH keys are securely managed and that you follow best practices for securing your SSH server. Regularly update rsync
and SSH to the latest versions to benefit from security patches and improvements.