Easy Data Backup with rsync: How to Do It Safely While Monitoring Progress

Today, I’d like to talk about “rsync," a handy tool for data backing up. rsync is a command-line tool that is extremely useful for file synchronization and backup. It is especially powerful for those who want to perform backups while checking the progress status.

目次

Basics and Precautions of rsync

First, let’s go over some basic precautions when using rsync.

  1. Data Integrity: Since rsync transfers file differences, it is important to ensure that the data at the source and destination match.
  2. Permissions and Ownership: By using the -a option, you can transfer files while preserving their permissions and ownership.
  3. Deletion Option: To delete files from the destination that do not exist at the source, use the --delete option.
  4. Network Load: Transferring large amounts of data can put a load on the network. Use the option to limit the transfer speed (--bwlimit) as needed.

Options for Displaying Progress

To display the progress of rsync, use the --progress option. You can also add the -v option to show detailed information.

Command Example

Below is an example of a command that uses rsync to back up data and display the progress:

rsync -avh --progress /path/to/source/ /path/to/destination/
  • -a: Archive mode. Preserves directory structure, symbolic links, permissions, timestamps, owner, group, and special files.
  • -v: Verbose mode. Displays a list of files being transferred.
  • -h: Outputs in a human-readable format (e.g., displaying sizes in KB, MB, GB).
  • --progress: Displays the transfer progress of each file.

Behavior Differences Based on the Presence of a Trailing Slash

It is also important to understand how rsync behaves differently depending on whether or not a trailing slash is included.

With a Trailing Slash (/)

  • Source: Copies only the contents of the directory.
  • Destination: Copies the contents directly inside the destination directory.

For example, consider the following command:

rsync -avh --progress /path/to/source/ /path/to/destination/

In this case, the contents (files and subdirectories) inside the /path/to/source/ directory are copied directly into the /path/to/destination/ directory.

Without a Trailing Slash

  • Source: Copies the directory itself, including its root.
  • Destination: Copies the entire directory into the destination directory.

For example, consider the following command:

rsync -avh --progress /path/to/source /path/to/destination/

In this case, the /path/to/source directory itself is copied inside the /path/to/destination/ directory, resulting in the creation of a directory named /path/to/destination/source/.

Summary

  • With a slash: Copies only the directory contents.
  • Without a slash: Copies the directory itself.

By understanding this difference and using the rsync command appropriately, you can perform backups and synchronizations exactly as intended.