Top 10 features of Rsync+ 50 Most Use Cases


Top 10 Features of Rsync:

  1. Efficient File Transfer:
    • Rsync only transfers the differences between source and destination files, minimizing data transfer and speeding up synchronization.
  2. Delta Transfer Algorithm:
    • Rsync uses a delta algorithm to detect and transfer only the changed parts of files, reducing bandwidth usage significantly.
  3. Support for Local and Remote Sync:
    • Rsync can synchronize files locally (between directories on the same system) or remotely (between different systems over SSH or direct connections).
  4. Preservation of File Attributes:
    • Rsync can preserve file permissions, ownerships, timestamps, symbolic links, and other metadata, ensuring data integrity during transfers.
  5. Compression:
    • It supports data compression during transfers, reducing bandwidth requirements and speeding up file synchronization.
  6. Resume Interrupted Transfers:
    • Rsync can resume interrupted transfers without restarting from scratch, making it ideal for large file synchronizations.
  7. Exclude/Include Patterns:
    • It allows you to include or exclude specific files or directories from synchronization using flexible pattern matching rules.
  8. Backup Support:
    • Rsync can create backups by appending timestamps to files or directories, enabling incremental backups with minimal storage overhead.
  9. SSH Integration:
    • Rsync seamlessly integrates with SSH for secure file transfers, ensuring data is encrypted during remote synchronizations.
  10. Cross-Platform Compatibility:
    • Rsync works on various platforms, including Linux, macOS, and Windows (using tools like Cygwin or WSL), making it a versatile tool for synchronization tasks.

These features make Rsync an invaluable utility for efficient and reliable file synchronization, backup, and data replication tasks.

Here are the top 50 most commonly used rsync commands and options, categorized for better understanding:

Basic Commands

  1. rsync source/ destination/
    • Basic directory synchronization.
  2. rsync file1 destination/
    • Transfer a single file to the destination.
  3. rsync -r source/ destination/
    • Recursively copy directories.
  4. rsync -a source/ destination/
    • Archive mode for preserving metadata.
  5. rsync -v source/ destination/
    • Enable verbose output.

Common Options

  1. rsync -z source/ destination/
    • Compress file data during transfer.
  2. rsync -P source/ destination/
    • Show progress and allow resuming of partial transfers.
  3. rsync -h source/ destination/
    • Human-readable file sizes.
  4. rsync -q source/ destination/
    • Suppress non-error messages.
  5. rsync -i source/ destination/
  • Output changes made during synchronization.

Advanced File Attributes

  1. rsync -t source/ destination/
  • Preserve modification times.
  1. rsync -o source/ destination/
  • Preserve ownership.
  1. rsync -g source/ destination/
  • Preserve group ownership.
  1. rsync -p source/ destination/
  • Preserve permissions.
  1. rsync -l source/ destination/
  • Copy symbolic links as is.
  1. rsync -H source/ destination/
  • Preserve hard links.
  1. rsync -D source/ destination/
  • Preserve device and special files.

Deletion Options

  1. rsync --delete source/ destination/
  • Delete files in the destination not present in the source.
  1. rsync --delete-before source/ destination/
  • Delete files in the destination before transferring new files.
  1. rsync --delete-during source/ destination/
  • Delete files in the destination during the transfer process.
  1. rsync --delete-delay source/ destination/
  • Delete files in the destination after the transfer is complete.

SSH Integration

  1. rsync -e ssh source/ user@remote:/destination/
  • Use SSH for secure remote transfers.
  1. rsync -e "ssh -p 2222" source/ user@remote:/destination/
  • Use a custom SSH port.
  1. rsync -e "ssh -i /path/to/key" source/ user@remote:/destination/
  • Use an SSH key for authentication.

Include/Exclude Files

  1. rsync --exclude='*.tmp' source/ destination/
  • Exclude files matching a pattern.
  1. rsync --include='*.jpg' source/ destination/
  • Include files matching a pattern.
  1. rsync --exclude-from=exclude-list.txt source/ destination/
  • Exclude files listed in a file.
  1. rsync --include-from=include-list.txt source/ destination/
  • Include files listed in a file.

Backup and Restore

  1. rsync --backup source/ destination/
  • Create backups of existing files.
  1. rsync --backup-dir=/path/to/backup source/ destination/
  • Specify a backup directory.
  1. rsync --suffix=.backup source/ destination/
  • Append a suffix to backup files.

Progress and Logging

  1. rsync --progress source/ destination/
  • Show progress during transfer.
  1. rsync --log-file=rsync.log source/ destination/
  • Save logs to a file.

Checksum and Integrity

  1. rsync -c source/ destination/
  • Use checksum to determine file differences.
  1. rsync --checksum
  • Always verify file integrity with checksums.

Bandwidth and Performance

  1. rsync --bwlimit=1000 source/ destination/
  • Limit bandwidth to 1000 KB/s.
  1. rsync --whole-file source/ destination/
  • Transfer the whole file instead of using deltas.

Dry Run

  1. rsync --dry-run source/ destination/
  • Simulate synchronization without making changes.

Hard Links and Symlinks

  1. rsync -L source/ destination/
  • Copy symlinks as the files they point to.
  1. rsync --copy-links source/ destination/
  • Same as -L.

Partial Transfers

  1. rsync --partial source/ destination/
  • Keep partially transferred files to resume later.
  1. rsync --partial-dir=.rsync-partial source/ destination/
  • Store partial files in a specific directory.

Parallel Transfers

  1. rsync --compress-level=9 source/ destination/
  • Set compression level to maximum.

File Size Control

  1. rsync --max-size=10MB source/ destination/
  • Exclude files larger than 10MB.
  1. rsync --min-size=100KB source/ destination/
  • Exclude files smaller than 100KB.

Archiving

  1. rsync -a --delete source/ destination/
  • Archive and remove extraneous files.
  1. rsync -a --progress source/ destination/
  • Archive mode with progress output.

Version Information

  1. rsync --version
  • Check the version of rsync.

Remote-to-Remote Sync

  1. rsync -a user@remote1:/path/ user@remote2:/path/
  • Synchronize between two remote systems.

Exclude Hidden Files

  1. rsync --exclude='.*' source/ destination/
  • Exclude hidden files (starting with a dot).

These commands cover most use cases for file synchronization, backup, and replication using rsync.