Pages

Sunday, October 6, 2013

Rsync command

Rsync (Remote Sync) is a powerful utility for copying and synchronizing files and directories, particularly across networked locations. Unlike simple copy commands, Rsync is designed for speed and efficiency by only transferring the parts of files that have actually changed.

This makes it the go-to tool for backups, file migration, and maintaining synchronized mirrors between servers.


THE CORE CONCEPT: DIFFERENTIAL COPYING

The key to Rsync's efficiency is its "delta transfer" algorithm.

  • Checks for Differences: Rsync first compares the files in the source location to the files in the destination location. It does this quickly by comparing file sizes and modification times.

  • Transfers Only the Delta: Instead of copying entire files that have been modified, Rsync calculates the differences (the "delta") within the files. It only transfers those small blocks of changed data, dramatically reducing the amount of network bandwidth and time required.

KEY BENEFIT: RESUMABLE TRANSFERS

One of Rsync's most valuable features is its ability to handle interruptions gracefully:

  • If a large transfer is interrupted (e.g., due to a lost network connection, power failure, or timeout), you can simply re-run the exact same rsync command.

  • Rsync will pick up where it left off, checking files and continuing the sync from the point of interruption, saving you from restarting the entire copy process.


UNDERSTANDING THE COMMAND SYNTAX

The basic Rsync command follows a simple pattern:

rsync [OPTIONS] [SOURCE] [DESTINATION]

EXAMPLE BREAKDOWN

The provided example is a very common and practical use of Rsync:

rsync -av source/public_html/ destination/public_html/

1. The Source and Destination:

  • source/public_html/: The location where the files currently reside (the directory to be copied from).

  • destination/public_html/: The location where the files should be copied to (the target directory).

2. The Options (-av):

The power of Rsync lies in its flags, with -av being the most widely used combination for general synchronization.

  • -a (Archive Mode): This is a shorthand for several important flags (-rlptgoD). It ensures the synchronization is comprehensive and preserves file integrity by:

    • recursing into directories.

    • linking files.

    • preserving permissions.

    • time-stamps (modification times).

    • group ownership.

    • owner (user) ownership.

    • Device files and special files.

  • -v (Verbose): This simply tells Rsync to output detailed information about the files being transferred, giving you confirmation and real-time progress.

Using this command ensures that the files in the destination directory are an exact, efficient, and attribute-preserving mirror of the source directory.

No comments:

Post a Comment