Skip to content

rsync Command on ChromeOS Linux Environment

The rsync command is a robust and efficient utility for synchronizing and transferring files and directories between locations. On ChromeOS, with the Linux (Crostini) environment enabled, rsync is an indispensable tool for backups, mirroring directories, and minimizing file transfer times by copying only the differences.


Installing rsync

In many ChromeOS Linux setups, rsync is not installed by default. You can install it using the following commands:

sudo apt update
sudo apt install rsync

Verify the installation:

rsync --version

Syntax

The basic syntax of rsync is:

rsync [options] source destination

Key Components:

  • Source: The file or directory to sync.
  • Destination: The target location (can be local or remote).

Common Examples

Local Synchronization

Synchronize a source directory with a target directory on the same system:

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

Options used: - -a: Archive mode (preserves permissions, timestamps, symbolic links, etc.). - -v: Verbose output. - -h: Human-readable format for file sizes.

Remote Synchronization

Synchronize files between your Chromebook and a remote server:

Upload Files to Remote Server

rsync -avh /path/to/local/ user@remote_host:/path/to/remote/

Download Files from Remote Server

rsync -avh user@remote_host:/path/to/remote/ /path/to/local/

Synchronize Specific Files

To sync only certain files, specify their names:

rsync -avh file1.txt file2.txt /path/to/destination/

Excluding Files or Directories

Use the --exclude option to skip specific files or directories:

rsync -avh --exclude 'node_modules/' /path/to/source/ /path/to/destination/

Deleting Files at the Destination

To delete files at the destination that are not present in the source:

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

Advanced Options

Using SSH for Secure Transfers

To synchronize files securely over SSH, include the -e ssh option:

rsync -avh -e ssh /path/to/local/ user@remote_host:/path/to/remote/

Compressing Data During Transfer

The -z option compresses data during transfer, reducing bandwidth usage:

rsync -avzh /path/to/source/ user@remote_host:/path/to/remote/

Partial Transfers

Enable partial transfers to resume interrupted syncs:

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

Dry-Run Mode

Simulate a transfer to preview the changes without making them:

rsync -avh --dry-run /path/to/source/ /path/to/destination/

Troubleshooting

Permission Denied

If you encounter a "Permission denied" error, ensure you have the necessary access rights. Use sudo if needed:

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

Remote Host Unreachable

Verify the remote host is accessible and ensure SSH is set up correctly:

ping remote_host
ssh user@remote_host

Files Not Syncing

Ensure the paths and options are correctly specified. Use verbose mode (-v) for detailed output.


Best Practices

  1. Use --dry-run: Always test your commands before running them to ensure they do what you expect.
  2. Combine with Cron: Automate regular backups by scheduling rsync commands with cron.
  3. Enable Compression: Use the -z option for faster transfers, especially over slow connections.
  4. Secure Your Keys: When using SSH, secure your private key with appropriate file permissions (chmod 600 ~/.ssh/id_rsa).

Example Scenarios

Backing Up Home Directory

Synchronize your home directory to an external drive:

rsync -avh --exclude='.cache/' ~/ /media/external_drive/backup/

Mirroring a Remote Directory

Create a mirror of a remote directory on your local machine:

rsync -avzh --delete user@remote_host:/remote/directory/ ~/local/mirror/

rsync is an invaluable tool for file synchronization, offering speed, efficiency, and flexibility. By mastering its options, ChromeOS users can streamline file management tasks locally and remotely.