Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ The syntax is similar to that of _scp_
Usage:
btrfs-sync [options] <src> [<src>...] [[user@]host:]<dir>

-k|--keep NUM keep only last <NUM> sync'ed snapshots
-d|--delete delete snapshots in <dst> that don't exist in <src>
-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 <NUM> sync'ed snapshots
-d|--delete delete snapshots in <dst> that don't exist in <src>
-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

<src> can either be a single snapshot, or a folder containing snapshots
<user> requires privileged permissions at <host> for the 'btrfs' command
Expand Down
58 changes: 33 additions & 25 deletions btrfs-sync
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
# Usage:
# btrfs-sync [options] <src> [<src>...] [[user@]host:]<dir>
#
# -k|--keep NUM keep only last <NUM> sync'ed snapshots
# -d|--delete delete snapshots in <dst> that don't exist in <src>
# -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 <NUM> sync'ed snapshots
# -d|--delete delete snapshots in <dst> that don't exist in <src>
# -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
#
# <src> can either be a single snapshot, or a folder containing snapshots
# <user> requires privileged permissions at <host> for the 'btrfs' command
Expand All @@ -39,14 +42,17 @@ print_usage() {
echo "Usage:
$BIN [options] [[user@]host:]<src> [<src>...] [[user@]host:]<dir>

-k|--keep NUM keep only last <NUM> sync'ed snapshots
-d|--delete delete snapshots in <dst> that don't exist in <src>
-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 <NUM> sync'ed snapshots
-d|--delete delete snapshots in <dst> that don't exist in <src>
-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

<src> can either be a single snapshot, or a folder containing snapshots
<user> requires privileged permissions at <host> for the 'btrfs' command
Expand All @@ -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
Expand Down Expand Up @@ -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 )
Expand Down