Rsync and Its Usages
What is Rsync?
Rsync (Remote Sync) is a fast and versatile command-line tool for copying and synchronizing files and directories between locations. It efficiently transfers only the differences between the source and destination, making it ideal for backups and file synchronization.
Basic Rsync Syntax
rsync [options] source destination
Common Rsync Options
-a(archive mode): Preserves symbolic links, file permissions, timestamps, and directory structure.-v(verbose): Displays the progress and details of file transfers.-r(recursive): Copies directories and their contents.-u(update): Copies only files that are newer in the source.--progress: Shows progress during transfer.--ignore-existing: Skips files that already exist in the destination.--delete: Removes files in the destination that no longer exist in the source.-z(compress): Compresses file data during transfer to reduce bandwidth usage.
Example Usages
1. Copy missing files from source to destination
rsync -av --ignore-existing /source/directory/ /destination/directory/
This ensures that only new files (not present in the destination) are copied.
2. Sync files while preserving attributes
rsync -av /source/directory/ /destination/directory/
This maintains file permissions, symbolic links, and timestamps.
3. Sync and remove deleted files from the destination
rsync -av --delete /source/directory/ /destination/directory/
This ensures that the destination is an exact mirror of the source.
4. Copy files over SSH
rsync -av -e ssh /source/directory/ user@remote_host:/destination/directory/
This allows secure file transfers over an SSH connection.
5. Show file transfer progress
rsync -av --progress /source/directory/ /destination/directory/
Displays progress details for each file being transferred.
Conclusion
Rsync is a powerful tool for file synchronization, backups, and mirroring. It is widely used in system administration, scripting, and data management due to its efficiency and reliability.
Written by A.M. Rinas