}
+pre=btrbk-run
script_name="${BASH_SOURCE[0]}"
script_name="${script_name##*/}"
-m() { if $verbose; then printf "%s\n" "$*"; fi; "$@"; }
-e() { printf "%s\n" "$*"; }
-die() { printf "%s\n" "$*" >&2; echo "exiting with status 1" >&2; exit 1; }
-mexit() { echo ": exiting with status $1"; exit $1; }
+m() { if $verbose; then printf "$pre %s\n" "$*"; fi; "$@"; }
+e() { printf "$pre %s\n" "$*"; }
+die() { printf "$pre error: %s\n" "$*" >&2; echo "$pre exiting with status 1" >&2; exit 1; }
+mexit() { echo "$pre exiting with status $1"; exit $1; }
# latest $MAIL_HOST
if [[ -e /b/bash_unpublished/source-state ]]; then
early=false
fast=false
kd_spread=false
+check_installed=false
orig_args=("$@")
-temp=$(getopt -l fast,pull-reexec,help 23cefikl:m:npqrs:t:vh "$@") || usage 1
+temp=$(getopt -l check-installed,fast,pull-reexec,help 23cefikl:m:npqrs:t:vh "$@") || usage 1
eval set -- "$temp"
while true; do
case $1 in
-3) conf_suf=3 ;;
# only creates the config file, does not run btrbk
-c) conf_only=true ;;
+ --check-installed)
+ check_installed=true
+ ;;
# quit early, just btrbk, no extra remounting etc.
-e) early=true ;;
# avoids some default behaviors:
cmd_arg="$1"
+
+uninstalled-file-die() {
+ die "uninstalled file $1. run install-my-scripts or rerun with -f"
+}
+
+if ! $force && { $check_installed || [[ ! $source ]]; } ; then
+ install_bin_files=(
+ mount-latest-subvol
+ check-subvol-stale
+ btrbk-run
+ )
+ for f in ${install_bin_files[@]}; do
+ if ! diff -q /a/bin/ds/$f /usr/local/bin/$f; then
+ uninstalled-file-die $f
+ fi
+ done
+ if ! diff -q /a/bin/errhandle/err /usr/local/lib/err; then
+ uninstalled-file-die err
+ fi
+ if $check_installed; then
+ exit 0
+ fi
+fi
+
+
if $kd_spread; then
if [[ $cmd_arg && $cmd_arg != resume ]]; then
die "dont pass -k without resume or empty run arg"
die "error: no btrbk binary found"
fi
+if ! $pull_reexec && [[ $source ]] && $pulla && ! $force ; then
+ ssh root@$source btrbk-run --check-installed || exit 1
+fi
#### end pre-checks #####
+
+
mkdir -p /var/log/btrbk
# The journal doesnt go back to my oldest backups, and I've found myself
# wanting older logs. Not going to bother expiring old logs, since it is
# fine if they go back years.
log_path=/var/log/btrbk/$(date +%F_%T%:::z).log
echo copying output to $log_path
-exec &> >(ts "%F %T" | tee -a $log_path)
+exec &> >(pee cat 'ts "%F %T"|dd of='$log_path' status=none')
if $verbose; then
echo "mountpoints: ${mountpoints[*]}"
-uninstalled-file-die() {
- err "uninstalled file $1. run install-my-scripts or rerun with -f"
- exit 1
-}
-if ! $force; then
- install_bin_files=(
- mount-latest-subvol
- check-subvol-stale
- btrbk-run
- )
- for f in ${install_bin_files[@]}; do
- if ! diff -q /a/bin/ds/$f /usr/local/bin/$f; then
- uninstalled-file-die $f
- fi
- done
- if ! diff -q /a/bin/errhandle/err /usr/local/lib/err; then
- uninstalled-file-die err
- fi
-fi
# pull_reexec stops us from getting into an infinite loop if there is some
break
fi
done
+
if ! $pull_reexec && [[ $source ]] && $pulla ; then
tmpf=$(mktemp)
m rsync -ra $source:/usr/local/bin/{mount-latest-subvol,check-subvol-stale} /usr/local/bin