Home Rsync
Post
Cancel

Rsync

Introduction to Rsync

Rsync (Remote Sync) is a widely used command-line tool for efficiently transferring and synchronizing files across computer systems, with support for incremental file transfer. It’s commonly used for backups, mirroring, and as an improved copy command for everyday use.

Basic Rsync Usage

Basic File Transfer

Transfer files from local system to a remote system:

1
rsync local_file username@server_ip:/remote/directory/

Transfer files from a remote system to the local system:

1
rsync username@server_ip:/remote/file /local/directory

Directory Transfer

To transfer a directory and its contents:

1
rsync -r /local/directory username@server_ip:/remote/directory

Synchronizing Directories

To synchronize the contents of a directory:

1
rsync -a /local/directory/ username@server_ip:/remote/directory

Incremental File Transfer

Rsync transfers only the changed parts of files:

1
rsync -av /local/directory/ username@server_ip:/remote/directory

Advanced Rsync Features

Using SSH for Transfer

To use SSH for secure file transfer:

1
rsync -avz -e ssh /local/directory/ username@server_ip:/remote/directory

Exclude Files

Excluding files from transfer:

1
rsync -av --exclude 'pattern_to_exclude' /source/ /destination/

Delete Option

To delete extraneous files from the destination directory:

1
rsync -av --delete /local/directory/ username@server_ip:/remote/directory

Dry Run

Perform a trial run with no changes made:

1
rsync -av --dry-run /source/ /destination/

Bandwidth Limit

Limit the bandwidth used by Rsync:

1
rsync -avz --bwlimit=1000 /source/ /destination/

Synchronization of File Permissions and Ownership

To maintain file permissions and ownership:

1
rsync -avz --perms --owner --group /source/ /destination/

Rsync Daemon for Frequent Transfers

Setting Up Rsync Daemon

For frequent transfers, set up an Rsync daemon on the remote server.

  1. Configure the Rsync daemon settings in rsyncd.conf file.
  2. Run Rsync in daemon mode:
    1
    
    rsync --daemon
    

Using Rsync Daemon for Transfer

To transfer files using the Rsync daemon:

1
rsync /local/directory/ rsync://username@server_ip/module_name/destination

Rsync in Backup Solutions

Incremental Backups

Rsync can be used for incremental backups, transferring only changed files:

1
rsync -a --link-dest=/path/to/previous/backup /source/ /current/backup/
This post is licensed under CC BY 4.0 by the author.