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 source /a
/bin
/bash-bear-trap
/bash-bear
9 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
13 Usage: ${0##*/} TARGET_HOST
17 -h|--help Print help and exit.
19 Note: Uses util-linux getopt option parsing: spaces between args and
20 options, short options can be combined, options before args.
25 ##### begin command line parsing ########
27 # ensure we can handle args with spaces or empty.
28 ret
=0; getopt
-T || ret
=$?
29 [[ $ret == 4 ]] ||
{ echo "Install util-linux for enhanced getopt" >&2; exit 1; }
31 temp
=$
(getopt
-l help h
"$@") || usage
1
37 *) echo "$0: unexpected args: $*" >&2 ; usage
1 ;;
42 read -r target
<<<"$@"
44 if [[ ! $target ]]; then
45 echo $0: error
: specify target
49 cat >/etc
/btrbk
/root2.conf
<<EOF
51 ssh_identity /root/.ssh/home
52 # Just a guess that local7 is a good facility to pick.
53 # It's a bit odd that the transaction log has to be logged to
54 # a file or syslog, while other output is sent to std out.
55 # The man does not mention a way for them to be together, but
56 # I dunno if setting a log level like warn might also output
58 transaction_syslog local7
63 archive_preserve_min latest
65 # so we only run one at a time
66 lockfile /var/lock/btrbkroot2.lock
68 # default format of short does not accomidate hourly preservation setting
69 timestamp_format long-iso
71 # dont make new snapshot, we only receive new snapshots
74 # if something fails and it's not obvious, try doing
75 # btrbk -l debug -v dryrun
79 subvolume root_ubuntubionic
80 target send-receive ssh://$target/mnt/root2/btrbk
82 subvolume boot_ubuntubionic
83 target send-receive ssh://$target/mnt/boot2/btrbk
87 tmpconf
=$
(mktemp
-d)/b.conf
89 timeout
-s 9 6 ssh root@
$target mkdir
-p /mnt
/{b
,r
}oot
2/btrbk
92 for base
in boot root
; do
93 cat - /etc
/btrbk
/root2.conf
>$tmpconf <<<"archive_exclude ${exclude}_ubuntubionic"
94 btrbk -c $tmpconf archive /mnt/r7/amy/btrbk ssh://$target/mnt/${base}2/btrbk