Rsync

Command Syntax

rsync [OPTIONS] SOURCE DESTINATION
  • -v – Verbose output.

  • -r – copies data recursively, doesn’t preserve timestamps and permission while transferring data.

  • -a – archive mode, which allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships, and timestamps.

  • -z – Compress files during transfer to reduce network usage.

  • -h – output numbers in a human-readable format.

  • -P – Show progress during the transfer.

  • SOURCE – Specifies the source file(s) or directory to be transferred, which can be a local or a remote location.

  • DESTINATION – Specifies the destination path where the files or directories will be copied. Similar to the source, it can be a local path or a remote location.

Installation

# Debian based
apt install rsync

# Redhat based
yum install rsync

Example of Usage

# Copy/Sync File Locally
rsync -zvh backup.tgz /tmp/backups/

# Copy/Sync Folder Locally
rsync -avzh /root/backups /tmp/backups/

# Copy a Directory from Local to Remote Server
rsync -avzh /root/backups root@192.168.0.100:/tmp/

# Copy a Directory from Remote to Local Server
rsync -avzh root@192.168.0.100:/root/backups /tmp/

# Copy a File from a Remote Server to a Local Server with SSH
rsync -avzhe ssh root@192.168.0.100:/root/backup.tgz /tmp/

# Copy a File from a Local Server to a Remote Server with SSH
rsync -avzhe ssh /root/backup.tgz root@192.168.0.100:/tmp/

# Show Progress While Transferring Data with Rsync
rsync -avzh --progress /root/backup.tgz root@192.168.0.100:/tmp/

# Include Files with Particular Extension
rsync -avzh --include='*.txt' SOURCE DESTINATION

# Exclude Files with Particular Extension
rsync -avzh --exclude='*.txt' SOURCE DESTINATION

# Use of --delete Option
rsync -avzh --delete /root/backups root@192.168.0.100:/tmp/

# Set File Transfer Limit
rsync -avzh --max-size='200K' /root/backups root@192.168.0.100:/tmp/

# Automatically Delete Source Files After Transfer
rsync -avzh --remove-source-files /root/backup.tgz root@192.168.0.100:/tmp/

# Do a Dry Run
rsync -avzh --dry-run --remove-source-files /root/backup.tgz root@192.168.0.100:/tmp/

# Set Bandwidth Limit
rsync -avzh --bwlimit=100 /root/backups root@192.168.0.100:/tmp/

Last updated

Was this helpful?