+ case $1 in
+ # only creates the config file, does not run btrbk
+ -c) conf_only=true; shift ;;
+ # bytes per second, suffix k m g
+ -l) rate_limit=$2; shift 2 ;;
+ # Comma separated mountpoints to backup. This has defaults set below.
+ -m) IFS=, mountpoints=($2); unset IFS; shift 2 ;;
+ -n) dry_run=true; dry_run_arg=-n; shift ;;
+ -p) progress_arg="--progress"; shift ;;
+ -q) verbose=false; verbose_arg=; progress_arg=; shift ;;
+ # target hosts to send to. empty is valid for just doing local
+ # snapshot. we have default hosts we will populate.
+ -t) IFS=, targets=($2); unset IFS; shift 2 ;;
+ -v) verbose=true; verbose_arg=-v; shift ;;
+ -h|--help) usage ;;
+ --) shift; break ;;
+ *) echo "$0: Internal error!" ; exit 1 ;;
+ esac
+done
+
+# usefull commands are resume and archive
+cmd_arg=${1:-run}
+
+if [[ -s $default_args_file ]]; then
+ echo "$0: warning: default btrbk-run options set in $default_args_file (sleeping 5 seconds):"
+ cat $default_args_file
+ sleep 5
+fi
+
+echo -e "$0: options: conf_only=$conf_only\ndry_run=$dry_run\nrate_limit=$rate_limit\nverbose=$verbose\ncmd_arg=$cmd_arg"
+
+# set default targets
+if [[ ! -v targets ]]; then
+ case $HOSTNAME in
+ x2|kw)
+ if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
+ targets=($HOME_DOMAIN)
+ fi
+ ;;
+ tp)
+ targets=(frodo)
+ if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
+ if timeout -s 9 10 ssh x2 :; then
+ targets+=(x2)
+ fi
+ fi
+ ;;
+ frodo)
+ targets=()
+ ;;
+ *)
+ echo "$0: error: no default targets for this host, use -t"
+ exit 1
+ ;;
+ esac
+fi
+
+echo "targets: ${targets[*]}"
+
+
+
+# set default mountpoints
+case $HOSTNAME in
+ frodo)
+ prospective_mps=(/i)
+ ;;
+ *)
+ prospective_mps=(/a /q)
+ if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
+ prospective_mps+=(/o)
+ fi
+ ;;
+esac
+case ${targets[0]} in
+ kw|kww)
+ prospective_mps=(/a)
+ ;;
+esac
+
+for mp in ${prospective_mps[@]}; do # default mountpoints to sync
+ if [[ -e /nocow/btrfs-stale/$mp ]]; then
+ echo "$0: warning: $mp stale, not adding to default mountpoints"
+ continue
+ fi
+ if awk '{print $2}' /etc/fstab | grep -xF $mp &>/dev/null; then
+ mountpoints+=($mp)
+ fi