X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=btrbk-run;h=4a2816b88376ef206f4e895de6537024dbf7d25d;hb=25d20d07292550e8701e33aa409e4947f3075ede;hp=71b0e6b76c939a2c36f085a93dd947adb0a49029;hpb=cca99b5a9d3cf311585a9c37b39698b0febe417c;p=distro-setup diff --git a/btrbk-run b/btrbk-run index 71b0e6b..4a2816b 100644 --- a/btrbk-run +++ b/btrbk-run @@ -21,6 +21,7 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" + usage() { cat <<'EOF' btrbk-run [OPTIONS] @@ -35,16 +36,21 @@ EOF exit $1 } +rsync-dirs() { + local host=$1 + local path=$2 + m rsync $dry_run_arg -ahi --relative --delete "$path" "root@$host:/" +} + + +m() { printf "%s: %s\n" "${0##*/}" "$*"; "$@"; } + # latest $MAIL_HOST if [[ -e /b/bash_unpublished/source-semi-priv ]]; then source /b/bash_unpublished/source-semi-priv fi -script_dir=$(dirname $(readlink -f "$BASH_SOURCE")) - # note q is owned by root:1000 -# note p/m is owned 1000:1000 and chmod 700 - mountpoints=() @@ -56,13 +62,18 @@ dry_run=false # mostly for testing rate_limit=no verbose=true; verbose_arg=-v progress_arg="--progress" +pull_reexec=false default_args_file=/etc/btrbk-run.conf if [[ -s $default_args_file ]]; then set -- $(< $default_args_file) "$@" + echo "$0: warning: default btrbk-run options set in $default_args_file (sleeping 5 seconds):" + cat $default_args_file + sleep 5 fi -temp=$(getopt -l help cl:m:nps:t:vh "$@") || usage 1 +orig_args=("$@") +temp=$(getopt -l pull-reexec,help cl:m:nps:t:vh "$@") || usage 1 eval set -- "$temp" while true; do case $1 in @@ -74,6 +85,7 @@ while true; do -m) IFS=, mountpoints=($2); unset IFS; shift 2 ;; -n) dry_run=true; dry_run_arg=-n; shift ;; -p) progress_arg="--progress"; shift ;; + --pull-reexec) pull_reexec=true; shift ;; -q) verbose=false; verbose_arg=; progress_arg=; shift ;; # source host to receive a backup from -s) source=$2; shift 2 ;; @@ -90,18 +102,15 @@ 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 - if [[ -v targets && $source ]]; then echo "$0: error: -t and -s are mutually exclusive" >&2 exit 1 fi + echo -e "$0: options: conf_only=$conf_only\ndry_run=$dry_run\nrate_limit=$rate_limit\nverbose=$verbose\ncmd_arg=$cmd_arg" +### end options parsing + # set default targets if [[ ! -v targets && ! $source ]]; then @@ -172,16 +181,31 @@ fi echo "mountpoints: ${mountpoints[*]}" -##### end command line parsing ######## -rsync-dirs() { - local host=$1 - local path=$2 - m rsync $dry_run_arg -ahi --relative --delete "$path" "root@$host:/" -} +# pull_reexec stops us from getting into an infinite loop if there is some +# kind of weird problem +pulla=false +for m in "${mountpoints[@]}"; do + if [[ $m == /a ]]; then + pulla=true + break + fi +done +if ! $pull_reexec && [[ $source ]] && ! $pulla ; then + tmpf=$(mktemp) + scp $source:/a/bin/distro-setup/btrbk-run $tmpf + if ! diff -q $tmpf $BASH_SOURCE; then + echo "$0: found newer version on host $source. reexecing" + install -T $tmpf /usr/local/bin/btrbk-run + m /usr/local/bin/btrbk-run --pull-reexec "${orig_args[@]}" + exit + fi +fi + + +##### end command line parsing ######## -m() { printf "%s: %s\n" "${0##*/}" "$*"; "$@"; } if ! which btrbk &>/dev/null; then @@ -203,8 +227,9 @@ ssh_identity /root/.ssh/home # transaction info. transaction_syslog local7 -# 20%ish speedup[] -stream_buffer 512m +# note, i had this because man said 20% speedup, but ran into +# this issue, https://github.com/digint/btrbk/issues/275 +#stream_buffer 512m # so we only run one at a time lockfile /var/lock/btrbk.lock @@ -233,9 +258,15 @@ EOF -for tg in ${targets[@]:-$HOSTNAME}; do - # for an initial run, btrbk requires the dir to exist. - ssh root@$tg mkdir -p /mnt/root/btrbk +# for an initial run, btrbk requires the dir to exist. +mkdir -p /mnt/root/btrbk +local_zone=$(date +%z) +for h in ${targets[@]} $source; do + zone=$(ssh root@$h "mkdir -p /mnt/root/btrbk; date +%z") + if [[ $zone != $local_zone ]]; then + echo "error: error. dont confuse yourself with multiple time zones. $h has different timezone than localhost" >&2 + exit 1 + fi done