2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
24 source /a
/bin
/bash-bear-trap
/bash-bear
26 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
30 Usage: ${0##*/} TARGET_HOST
34 -h|--help Print help and exit.
36 Note: Uses util-linux getopt option parsing: spaces between args and
37 options, short options can be combined, options before args.
42 ##### begin command line parsing ########
44 # ensure we can handle args with spaces or empty.
45 ret
=0; getopt
-T || ret
=$?
46 [[ $ret == 4 ]] ||
{ echo "Install util-linux for enhanced getopt" >&2; exit 1; }
48 temp
=$
(getopt
-l help h
"$@") || usage
1
54 *) echo "$0: unexpected args: $*" >&2 ; usage
1 ;;
59 read -r target
<<<"$@"
61 if [[ ! $target ]]; then
62 echo $0: error
: specify target
66 cat >/etc
/btrbk
/root2.conf
<<EOF
68 ssh_identity /root/.ssh/home
69 # Just a guess that local7 is a good facility to pick.
70 # It's a bit odd that the transaction log has to be logged to
71 # a file or syslog, while other output is sent to std out.
72 # The man does not mention a way for them to be together, but
73 # I dunno if setting a log level like warn might also output
75 transaction_syslog local7
80 archive_preserve_min latest
82 # so we only run one at a time
83 lockfile /var/lock/btrbkroot2.lock
85 # default format of short does not accomidate hourly preservation setting
86 timestamp_format long-iso
88 # dont make new snapshot, we only receive new snapshots
91 # if something fails and it's not obvious, try doing
92 # btrbk -l debug -v dryrun
96 subvolume root_ubuntubionic
97 target send-receive ssh://$target/mnt/root2/btrbk
99 subvolume boot_ubuntubionic
100 target send-receive ssh://$target/mnt/boot2/btrbk
104 tmpconf
=$
(mktemp
-d)/b.conf
106 timeout
-s 9 6 ssh root@
$target mkdir
-p /mnt
/{b
,r
}oot
2/btrbk
109 for base
in boot root
; do
110 cat - /etc
/btrbk
/root2.conf
>$tmpconf <<<"archive_exclude ${exclude}_ubuntubionic"
111 btrbk -c $tmpconf archive /mnt/r7/amy/btrbk ssh://$target/mnt/${base}2/btrbk