i think this fixes i3 issues
[distro-setup] / btrbkr2
1 #!/bin/bash
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
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
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
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
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.
22
23
24 source /a/bin/bash-bear-trap/bash-bear
25
26 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
27
28 usage() {
29 cat <<EOF
30 Usage: ${0##*/} TARGET_HOST
31 Send btrbk for root2
32
33
34 -h|--help Print help and exit.
35
36 Note: Uses util-linux getopt option parsing: spaces between args and
37 options, short options can be combined, options before args.
38 EOF
39 exit $1
40 }
41
42 ##### begin command line parsing ########
43
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; }
47
48 temp=$(getopt -l help h "$@") || usage 1
49 eval set -- "$temp"
50 while true; do
51 case $1 in
52 -h|--help) usage ;;
53 --) shift; break ;;
54 *) echo "$0: unexpected args: $*" >&2 ; usage 1 ;;
55 esac
56 shift
57 done
58
59 read -r target <<<"$@"
60
61 if [[ ! $target ]]; then
62 echo $0: error: specify target
63 exit 1
64 fi
65
66 cat >/etc/btrbk/root2.conf <<EOF
67
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
74 # transaction info.
75 transaction_syslog local7
76
77 # trying this out
78 stream_compress zstd
79
80 archive_preserve_min latest
81
82 # so we only run one at a time
83 lockfile /var/lock/btrbkroot2.lock
84
85 # default format of short does not accomidate hourly preservation setting
86 timestamp_format long-iso
87
88 # dont make new snapshot, we only receive new snapshots
89 snapshot_create no
90
91 # if something fails and it's not obvious, try doing
92 # btrbk -l debug -v dryrun
93
94 rate_limit no
95 volume /mnt/r7/amy
96 subvolume root_ubuntubionic
97 target send-receive ssh://$target/mnt/root2/btrbk
98 volume /mnt/r7/amy
99 subvolume boot_ubuntubionic
100 target send-receive ssh://$target/mnt/boot2/btrbk
101
102 EOF
103
104 tmpconf=$(mktemp -d)/b.conf
105
106 timeout -s 9 6 ssh root@$target mkdir -p /mnt/{b,r}oot2/btrbk
107
108 exclude=root
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
112 # swaps the vars
113 exclude=$base
114 done