4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
8 Usage: ${0##*/} OLD_HOST NEW_HOST
10 Adjust home network dns so NEW_HOST resolves locally if it is on the
11 local network. Turn off mail receiving on OLD_HOST, run btrbk to move
12 mail to NEW_HOST, turn on mail receiving on NEW_HOST.
15 -h|--help Print help and exit.
17 Note: Uses GNU getopt options parsing style
22 ##### begin command line parsing ########
24 if (( $# != 2 )) ||
[[ $1 == -* ||
$2 == -* ]]; then
31 if [[ $old_host != $MAIL_HOST ]]; then
32 read -p "warning: \$old_host != \$MAIL_HOST: $old_host != $MAIL_HOST, proceed? y/N "
33 if [[ $REPLY != [yY
] ]]; then
38 if [[ $new_host == "$HOSTNAME" ]]; then
40 new_shell
="ssh $new_host"
47 if [[ $old_host == "$HOSTNAME" ]]; then
48 old_shell
="ssh $old_host"
51 if [[ ! $new_host ||
! $old_host ]]; then
52 echo "$0: bad args. see script"
57 if [[ $HOSTNAME == treetowl
]] ||
[[ $HOSTNAME == frodo
]] || timeout
-s 9 5 ssh wrt.lan
:; then
60 echo "$0: at_home = $at_home"
62 source /a
/bin
/bash_unpublished
/source-semi-priv
63 #### begin convert private hostnames to public hostnames ####
65 for var
in old_host new_host
; do
68 eval $var=$HOME_DOMAIN
73 #### end convert private hostnames to public hostnames ####
76 # because our port forward is not robust enough, we can't use proxy command,
77 # todo: just open an ssh port to the world on wrt.lan
79 wrt_shell
="ssh $HOME_DOMAIN ssh wrt.lan"
81 wrt_shell
="ssh wrt.lan"
84 btrbk_test
="systemctl is-active btrbk.service"
85 while ! $new_shell $btrbk_test ||
$old_shell $btrbk_test; do
86 echo "$0: btrbk is running on new or old host. sleeping for 8 seconds"
88 echo "$0: testing for btrbk activity in 2 seconds"
92 ########### end initial processing, begin actually modifying things ##########
94 restore_new_btrbk
=false
95 if $new_shell systemctl is-active btrbk.timer
; then
96 $new_shell sudo systemctl stop btrbk.timer
97 restore_new_btrbk
=true
99 restore_old_btrbk
=false
100 if $old_shell systemctl is-active btrbk.timer
; then
101 $old_shell sudo systemctl stop btrbk.timer
102 restore_old_btrbk
=true
105 $new_shell bash
-s <<'EOF'
107 if mountpoint /m; then sudo umount /m; fi
108 if mountpoint /o; then sudo umount /o; fi
111 # if new_host is not on home network, make mail.iankelling.org not resolve
112 # on the home network.
113 if [[ $new_host == $HOSTNAME ]] && ! $at_home; then
114 echo |
$wrt_shell cedit mail_host
/etc
/hosts ||
[[ $?
== 1 ]] # 1 means file changed.
116 $wrt_shell bash
-s <<EOFOUTER
117 cedit mail_host /etc/hosts <<'EOF' || /etc/init.d/dnsmasq restart
118 \$(grep "\b$new_host\b" /etc/hosts | awk '{print $1}') mail.iankelling.org
125 $shell sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a
/bin
/bash_unpublished
/source-semi-priv
126 $shell /a
/bin
/distro-setup
/mail-setup exim4
129 mail-setup
"$old_shell"
131 sudo
dd of
=/etc
/btrbk.conf
<<'EOF'
132 ssh_identity /root/.ssh/id_rsa
133 # Just a guess that local7 is a good facility to pick.
134 # It's a bit odd that the transaction log has to be logged to
135 # a file or syslog, while other output is sent to std out.
136 # The man does not mention a way for them to be together, but
137 # I dunno if setting a log level like warn might also output
139 transaction_syslog local7
141 # so we only run one at a time
142 lockfile /var/lock/btrbk.lock
144 # default format of short does not accomidate hourly preservation setting
145 timestamp_format long-iso
147 # only make a snapshot if things have changed
148 snapshot_create onchange
149 # I could make this different from target_preserve,
150 # if one disk had less space.
151 # for now, keeping them equal.
152 snapshot_preserve 36h 14d 8w 24m
153 snapshot_preserve_min 4h
156 # so, total backups = ~89
157 target_preserve 36h 14d 8w 24m
158 target_preserve_min 4h
160 # if something fails and it's not obvious, try doing
161 # btrbk -l debug -v dryrun
167 if $localhost_new; then
168 btrbk_src
=ssh://$old_host/mnt
/root
169 btrbk_dst
=/mnt
/root
/btrbk
172 btrbk_dst
=ssh://$old_host/mnt
/root
/btrbk
175 sudo
tee -a /etc
/btrbk.conf
<<EOF
178 target send-receive $btrbk_dst
182 sudo btrbk
--progress run
183 $new_shell mount-latest-subvol
187 if $restore_new_btrbk; then
188 $new_shell sudo systemctl start btrbk.timer
190 if $restore_old_btrbk; then
191 $old_shell sudo systemctl start btrbk.timer