dimitrisprama.com

rsync notes

This is a breakdown of how you can upload a file or a folder to a remote host using rsync.

rsync -avzP /path/to/local/folder/ username@SERVER_IP:/path/to/remote/destination/

Breakdown of Flags & Syntax

  • -a (archive): Preserves file permissions, symlinks, timestamps, and ownership recursively.
  • -v (verbose): Outputs what files are being transferred.
  • -z (compress): Compresses file data during transfer to save bandwidth.
  • -P: Combines --progress (shows real-time transfer speed and progress) and --partial (allows resuming interrupted transfers).
  • Trailing slash on source (folder/ vs folder):
    • folder/ (with slash): Copies the contents inside folder directly into the destination directory.
    • folder (without slash): Copies the directory itself, creating destination/folder.

Common Variations

Using a custom SSH port (e.g., 2222):

rsync -avzP -e 'ssh -p 2222' /path/to/local/folder/ username@SERVER_IP:/remote/path/

Using a specific SSH key:

rsync -avzP -e 'ssh -i ~/.ssh/id_rsa' /path/to/local/folder/ username@SERVER_IP:/remote/path/ 

Dry run (test without actually transferring):

rsync -avzPn /path/to/local/folder/ username@SERVER_IP:/remote/path/

The -n flag simulates the run to confirm paths before transferring data.