rsync
utility in Linux
Usage of the Some useful constructs that make rsync
powerful
Accessing the help manual
man rsync
rsync
Common constructs used with Syncing the contents from one directory to another recursively
rsync -r dir1/ dir2
Syncing recursively and maintaining source file metadata in destination
rsync -a dir1/ dir2
rsync
with a dry run
Testing rsync -an dir1/ dir2
Add the verbose flag to make the command effective by displaying the files/directories that will be synced
rsync -anv dir1/ dir2
Pushing files from local machine to a remote server
rsync -a dir1/ username@host:destination_directory_on_server
Pulling files from a remote server to a local machine
rsync -a username@host:source_directory_on_server directory_on_local_machine
Compress files during transfer
rsync -az source destination
Adding a progress bar and syncing only changed files
rsync -aP dir1/ dir2
Delete file from the destination directory if it was removed from the source directory
rsync -a --delete dir1/ dir2
Excluding files or directories during sync
rsync -a --exclude=pattern_to_exclude dir1/ dir2
Overriding exclusion for files that include a specific pattern
rsync -a --exclude=pattern_to_exclude --include=pattern_to_include dir1/ dir2
Creating backups
rsync -a --delete --backup --backup-dir=~/backup ~/dir1/ ~/dir2
The above command will:
- Look for any files changed in
dir1
ordir2
and move the previous version of the file to thebackup
folder - Look for files deleted in
dir1
and move the corresponding file fromdir2
to thebackup
folder before deleting it fromdir2