2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4 # SPDX-License-Identifier: GPL-3.0-or-later
5 # SPDX-License-Identifier: Apache-2.0
7 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
8 shopt -s inherit_errexit
2>/dev
/null ||
: # ignore fail in bash < 4.4
10 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
11 # alternatively, using https://iankelling.org/git/?p=errhandle;a=tree
12 # source /path/errhandle/err
14 source /a
/bin
/errhandle
/err
16 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
20 Usage: ${0##*/} TARGET_HOST
24 -h|--help Print help and exit.
26 Note: Uses util-linux getopt option parsing: spaces between args and
27 options, short options can be combined, options before args.
32 ##### begin command line parsing ########
34 # ensure we can handle args with spaces or empty.
35 ret
=0; getopt
-T || ret
=$?
36 [[ $ret == 4 ]] ||
{ echo "Install util-linux for enhanced getopt" >&2; exit 1; }
38 temp
=$
(getopt
-l help h
"$@") || usage
1
44 *) echo "$0: unexpected args: $*" >&2 ; usage
1 ;;
49 read -r target
<<<"$@"
51 if [[ ! $target ]]; then
52 echo $0: error
: specify target
56 cat >/etc
/btrbk
/root2.conf
<<EOF
58 ssh_identity /root/.ssh/home
59 # Just a guess that local7 is a good facility to pick.
60 # It's a bit odd that the transaction log has to be logged to
61 # a file or syslog, while other output is sent to std out.
62 # The man does not mention a way for them to be together, but
63 # I dunno if setting a log level like warn might also output
65 transaction_syslog local7
70 archive_preserve_min latest
72 # so we only run one at a time
73 lockfile /var/lock/btrbkroot2.lock
75 # default format of short does not accomidate hourly preservation setting
76 timestamp_format long-iso
78 # dont make new snapshot, we only receive new snapshots
81 # if something fails and it's not obvious, try doing
82 # btrbk -l debug -v dryrun
86 subvolume root_ubuntubionic
87 target send-receive ssh://$target/mnt/root2/btrbk
89 subvolume boot_ubuntubionic
90 target send-receive ssh://$target/mnt/boot2/btrbk
94 tmpconf
=$
(mktemp
-d)/b.conf
96 timeout
-s 9 6 ssh root@
$target mkdir
-p /mnt
/{b
,r
}oot
2/btrbk
99 for base
in boot root
; do
100 cat - /etc
/btrbk
/root2.conf
>$tmpconf <<<"archive_exclude ${exclude}_ubuntubionic"
101 btrbk -c $tmpconf archive /mnt/r7/amy/btrbk ssh://$target/mnt/${base}2/btrbk