Quick and Efficient Way to Backup a Remote Folder using Rsync

Rsync stands as a formidable utility. However, to harness its full potential, it's essential to recall the specific arguments that it needs. Herein lies my personal aide-memoire to address this very concern.

1 min read
Quick and Efficient Way to Backup a Remote Folder using Rsync
Photo by Sergei Starostin on Pexels.

Occasionally, there arises a need for me to download directories stored on my remote server, often for backup purposes. Yet, on each occasion, I find myself scouring the Internet to determine the precise arguments required for the rsync utility.

Those days are now relegated to history, as I have chosen today to write down a future-oriented reminder right here. 😅

Without further ado, here is the definitive command to download a remote directory on your computer:

# Adapt the variables below

# From your local machine
rsync \
  --archive \
  --compress \
  --human-readable \
  --partial \
  --progress \
  --rsh "ssh -p ${SSH_PORT}" \
  --stats \
  --verbose \
An example of the rsync command to download a remote directory.

Explanation of the arguments

  1. --archive: Preserves file permissions, ownership, timestamps, and more.
  2. --compress: Enables compression of data during transfer, reducing the amount of data transmitted.
  3. --human-readable: File sizes are displayed in a human-readable format (e.g., kB, Mb or gB).
  4. --partial: If the transfer is interrupted, partially transferred files are keep instead of discarding them.
  5. --progress: Displays a progress indicator.
  6. --rsh "ssh -p ${SSH_PORT}": The communication should be done over SSH using port 22. It is useful if your server use another port for SSH.
  7. --stats: Provides a summary of the transfer statistics once the process is completed.
  8. --verbose: Increases the verbosity of the output, offering more detailed information.
  9. "${SSH_USER}@${SSH_SERVER}:${REMOTE_SOURCE_DIRECTORY}:: The source directory on the remote server that you wish to back up.
  10. "${LOCAL_DESTINATION_DIRECTORY}": The destination directory on your local machine where the backup will be saved.