Copy new files from source to target and skip files if it already exist in target
rsync --dry-run -avzurh --stats --delete --progress /tmp/source/ /tmp/target/
-a-> Archive mode, preserve the file system properties-v-> Verbose output-vv-> Higher Verbose output-vvv-> Even Higher Verbose output-vvvv-> Highest Verbose output-z-> Use compression mode for data transfer, speeds up for transfer over network-h-> Output in human readable format-u-> Skip if a file already exist in target directory, makes it efficient to copy only the missing files in target directory. Without this flag, it will overwrite the file in the target directory-r-> recursive mode, copies subdirectory--delete-> delete the additional files or directories which are present in target directory which are not present in source directory--dry-run-> do a dry run without making any changes to the file system--stats-> give the stats at the end of the process--progress-> show progress while copying the files
Copy the source directory itself into the target directory (missing trailing slash at the end)
rsync -v -azurh /tmp/source /tmp/target
Copy from local source directory to remote directory
rsync -vv -azurh /tmp/source/ remote_user@example.com:/tmp/remote-target/
Copy from remote source directory to local target directory
rsync -vvv -azurh remote_user@example.com:/tmp/remote-source/ /tmp/target/
Copy from remote source directory to remote target directory
rsync -vvvv -azurh remote_user@server1.example.com:/tmp/remote-source/ remote_user@server2.example.com:/tmp/remote-target/
Copies all files except logs
rsync -v -azurh --exclude '*.log' /tmp/source/ /tmp/target/
Copies only log files, text files and excludes all other files
rsync -v -azurh --include '*.log' --include '*.txt' --exclude '*' /tmp/source/ /tmp/target/
Copies only important logs file and excludes all other log files
rsync -v -azurh --include '*sensitive*.log' --include '*important*.log' --exclude '*.log' /tmp/source/ /tmp/target/