Overview

rsync is an excellent option to copy or synchronize a remote directory over ssh.

Use Cases

  • Transferring large directories since rsync will allow you to resume a transfer if it gets interrupted.
  • Keeping directories in sync (periodically)

Command

$ rsync --recursive --info=progress2 --info=name0  --partial --rsh="ssh -q" [<user>@]<host>:<remote directory> <local directory>

See Graphical Explanation

Example Usage

Important: Note the trailing / at the end of both directory paths.

$ mkdir training
$ rsync --recursive --info=progress2 --info=name0  --partial --rsh="ssh -q" erik@remote-host:/srv/data/training/ training/

Scripting

Save this as rsync-partial somewhere in your $PATH.

#!/bin/bash

_remote_host=$1
_remote_path=$2
_local_path=$3

# Ensure the local directory exists
test -d $3 || mkdir $3

rsync --recursive --info=progress2 --info=name0  --partial --rsh="ssh -q" $_remote_host:$_remote_path $_local_path/

Example Usage

$ rsync-partial erik@remote-host /srv/data/training training/