diff --git a/README.md b/README.md index a536628..a4d9752 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,17 @@ The syntax is similar to that of _scp_ Usage: btrfs-sync [options] [...] [[user@]host:] - -k|--keep NUM keep only last sync'ed snapshots - -d|--delete delete snapshots in that don't exist in - -z|--xz use xz compression. Saves bandwidth, but uses one CPU - -Z|--pbzip2 use pbzip2 compression. Saves bandwidth, but uses all CPUs - -q|--quiet don't display progress - -v|--verbose display more information - -h|--help show usage + -k|--keep NUM keep only last sync'ed snapshots + -d|--delete delete snapshots in that don't exist in + -z|--xz use xz compression. Saves bandwidth, but uses one CPU + -Z|--pbzip2 use pbzip2 compression. Saves bandwidth, but uses all CPUs + -p|--port SSH port. Default 22 + -L|--rate-limit RATE limit the transfer to a maximum of RATE bytes per second. + A suffix of \"K\", \"M\", \"G\", or \"T\" can be added to denote + kibibytes (*1024), mebibytes, and so on. + -q|--quiet don't display progress + -v|--verbose display more information + -h|--help show usage can either be a single snapshot, or a folder containing snapshots requires privileged permissions at for the 'btrfs' command diff --git a/btrfs-sync b/btrfs-sync index 3179177..1db097e 100644 --- a/btrfs-sync +++ b/btrfs-sync @@ -7,13 +7,16 @@ # Usage: # btrfs-sync [options] [...] [[user@]host:] # -# -k|--keep NUM keep only last sync'ed snapshots -# -d|--delete delete snapshots in that don't exist in -# -z|--xz use xz compression. Saves bandwidth, but uses one CPU -# -Z|--pbzip2 use pbzip2 compression. Saves bandwidth, but uses all CPUs -# -q|--quiet don't display progress -# -v|--verbose display more information -# -h|--help show usage +# -k|--keep NUM keep only last sync'ed snapshots +# -d|--delete delete snapshots in that don't exist in +# -z|--xz use xz compression. Saves bandwidth, but uses one CPU +# -Z|--pbzip2 use pbzip2 compression. Saves bandwidth, but uses all CPUs +# -L|--rate-limit RATE limit the transfer to a maximum of RATE bytes per second. +# A suffix of "K", "M", "G", or "T" can be added to denote +# kibibytes (*1024), mebibytes, and so on. +# -q|--quiet don't display progress +# -v|--verbose display more information +# -h|--help show usage # # can either be a single snapshot, or a folder containing snapshots # requires privileged permissions at for the 'btrfs' command @@ -39,14 +42,17 @@ print_usage() { echo "Usage: $BIN [options] [[user@]host:] [...] [[user@]host:] - -k|--keep NUM keep only last sync'ed snapshots - -d|--delete delete snapshots in that don't exist in - -z|--xz use xz compression. Saves bandwidth, but uses one CPU - -Z|--pbzip2 use pbzip2 compression. Saves bandwidth, but uses all CPUs - -p|--port SSH port. Default 22 - -q|--quiet don't display progress - -v|--verbose display more information - -h|--help show usage + -k|--keep NUM keep only last sync'ed snapshots + -d|--delete delete snapshots in that don't exist in + -z|--xz use xz compression. Saves bandwidth, but uses one CPU + -Z|--pbzip2 use pbzip2 compression. Saves bandwidth, but uses all CPUs + -p|--port SSH port. Default 22 + -L|--rate-limit RATE limit the transfer to a maximum of RATE bytes per second. + A suffix of \"K\", \"M\", \"G\", or \"T\" can be added to denote + kibibytes (*1024), mebibytes, and so on. + -q|--quiet don't display progress + -v|--verbose display more information + -h|--help show usage can either be a single snapshot, or a folder containing snapshots requires privileged permissions at for the 'btrfs' command @@ -73,23 +79,25 @@ BIN="${0##*/}" # parse arguments KEEP=0 PORT=22 +LIMIT=0 ZIP=cat PIZ=cat SILENT=">/dev/null" -OPTS=$( getopt -o hqzZk:p:dv -l quiet -l help -l xz -l pbzip2 -l keep: -l port: -l delete -l verbose -- "$@" 2>/dev/null ) +OPTS=$( getopt -o hqzZk:p:L:dv -l quiet -l help -l xz -l pbzip2 -l keep: -l port: -l rate-limit: -l delete -l verbose -- "$@" 2>/dev/null ) [[ $? -ne 0 ]] && { echo "error parsing arguments"; exit 1; } eval set -- "$OPTS" while true; do case "$1" in - -h|--help ) print_usage; exit 0 ;; - -q|--quiet ) QUIET=1 ; shift 1 ;; - -d|--delete ) DELETE=1 ; shift 1 ;; - -k|--keep ) KEEP=$2 ; shift 2 ;; - -p|--port ) PORT=$2 ; shift 2 ;; - -z|--xz ) ZIP=xz PIZ=( xz -d ); shift 1 ;; - -Z|--pbzip2 ) ZIP=pbzip2 PIZ=( pbzip2 -d ); shift 1 ;; - -v|--verbose) SILENT="" VERBOSE=1 ; shift 1 ;; + -h|--help ) print_usage; exit 0 ;; + -q|--quiet ) QUIET=1 ; shift 1 ;; + -d|--delete ) DELETE=1 ; shift 1 ;; + -k|--keep ) KEEP=$2 ; shift 2 ;; + -p|--port ) PORT=$2 ; shift 2 ;; + -z|--xz ) ZIP=xz PIZ=( xz -d ); shift 1 ;; + -Z|--pbzip2 ) ZIP=pbzip2 PIZ=( pbzip2 -d ); shift 1 ;; + -L|--rate-limit ) LIMIT=$2 ; shift 2 ;; + -v|--verbose ) SILENT="" VERBOSE=1 ; shift 1 ;; --) shift; break ;; esac done @@ -162,7 +170,7 @@ while read entry; do SRCS+=( "$entry" ); done < <( } ## use 'pv' command if available -PV=( pv -F"time elapsed [%t] | rate %r | total size [%b]" ) +PV=( pv -L "$LIMIT" -F"time elapsed [%t] | rate %r | total size [%b]" ) [[ "$QUIET" == "1" ]] && PV=( cat ) || type pv &>/dev/null || { echo "INFO: install the 'pv' package in order to get a progress indicator" PV=( cat )