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.
14 -w Don't try to ssh to wrt. Should only be used in unusual network situation.
15 -h|--help Print help and exit.
17 Note: Uses GNU getopt options parsing style
22 ##### begin command line parsing ########
24 update_wrt
=true
# default
25 long_opt
=foo
# default
26 temp
=$
(getopt
-l help wh
"$@") || usage
1
30 -w) update_wrt
=false
; shift ;;
33 *) echo "$0: Internal error! unexpected args: $*" ; exit 1 ;;
38 (( $# == 2 )) || usage
1
42 source /a
/bin
/bash_unpublished
/source-semi-priv
44 if [[ $old_host != $MAIL_HOST ]]; then
45 read -p "warning: \$old_host != \$MAIL_HOST: $old_host != $MAIL_HOST, proceed? y/N "
46 if [[ $REPLY != [yY
] ]]; then
51 if [[ $new_host == "$HOSTNAME" ]]; then
56 new_shell
="ssh $new_host"
59 old_shell
="ssh $old_host"
60 if [[ $old_host == "$HOSTNAME" ]]; then
64 if [[ ! $new_host ||
! $old_host ]]; then
65 echo "$0: bad args. see script"
70 if [[ $HOSTNAME == tp
]] ||
[[ $HOSTNAME == frodo
]] || timeout
-s 9 5 ssh wrt.b8.nz
:; then
73 echo "$0: at_home = $at_home"
75 source /a
/bin
/bash_unpublished
/source-semi-priv
76 #### begin convert private hostnames to public hostnames ####
78 for var
in old_host new_host
; do
81 eval $var=$HOME_DOMAIN
86 #### end convert private hostnames to public hostnames ####
89 # because our port forward is not robust enough, we can't use proxy command,
90 # todo: setup vpn so this is all taken care of.
91 if ! $update_wrt; then
94 wrt_shell
="ssh wrt.b8.nz"
96 if [[ $old_host == iank.vpn.office.fsf.org ||
$new_host == iank.vpn.office.fsf.org
]]; then
97 wrt_shell
="ssh iank.vpn.office.fsf.org ssh wrt.b8.nz"
99 wrt_shell
="ssh $HOME_DOMAIN ssh wrt.b8.nz"
103 btrbk_test
="systemctl is-active btrbk.service"
104 while $new_shell $btrbk_test ||
$old_shell $btrbk_test; do
105 echo "$0: btrbk is running on new or old host. sleeping for 8 seconds"
107 echo "$0: testing for btrbk activity in 2 seconds"
111 ########### end initial processing, begin actually modifying things ##########
113 restore_new_btrbk
=false
114 if $new_shell systemctl is-active btrbk.timer
; then
115 $new_shell sudo systemctl stop btrbk.timer
116 restore_new_btrbk
=true
118 restore_old_btrbk
=false
119 if $old_shell systemctl is-active btrbk.timer
; then
120 $old_shell sudo systemctl stop btrbk.timer
121 restore_old_btrbk
=true
124 $new_shell bash
-s <<'EOF'
126 if mountpoint /m; then sudo umount /m; fi
127 if mountpoint /o; then sudo umount /o; fi
130 # if new_host is not on home network, make mail.iankelling.org not resolve
131 # on the home network.
132 if [[ $new_host == $HOSTNAME ]] && ! $at_home; then
133 echo |
$wrt_shell cedit mail_host
/etc
/hosts ||
[[ $?
== 1 ]] # 1 means file changed.
135 $wrt_shell bash
-s <<EOFOUTER
136 cedit mail_host /etc/hosts <<EOF || /etc/init.d/dnsmasq restart
137 \$(grep "\b$new_host\b" /etc/hosts | awk '{print \$1}') mail.iankelling.org
144 $shell sed -ri "s/MAIL_HOST=.*/MAIL_HOST=$new_host/" /a
/bin
/bash_unpublished
/source-semi-priv
145 $shell /a
/bin
/distro-setup
/mail-setup exim4
148 mail-setup
"$old_shell"
150 sudo
dd of
=/etc
/btrbk.conf
<<'EOF'
151 ssh_identity /root/.ssh/id_rsa
152 # Just a guess that local7 is a good facility to pick.
153 # It's a bit odd that the transaction log has to be logged to
154 # a file or syslog, while other output is sent to std out.
155 # The man does not mention a way for them to be together, but
156 # I dunno if setting a log level like warn might also output
158 transaction_syslog local7
160 # so we only run one at a time
161 lockfile /var/lock/btrbk.lock
163 # default format of short does not accomidate hourly preservation setting
164 timestamp_format long-iso
166 # only make a snapshot if things have changed
167 snapshot_create onchange
168 # I could make this different from target_preserve,
169 # if one disk had less space.
170 # for now, keeping them equal.
171 snapshot_preserve 36h 14d 8w 24m
172 snapshot_preserve_min 4h
175 # so, total backups = ~89
176 target_preserve 36h 14d 8w 24m
177 target_preserve_min 4h
179 # if something fails and it's not obvious, try doing
180 # btrbk -l debug -v dryrun
186 if $localhost_new; then
187 btrbk_src
=ssh://$old_host/mnt
/root
188 btrbk_dst
=/mnt
/root
/btrbk
191 btrbk_dst
=ssh://$new_host/mnt
/root
/btrbk
194 sudo
tee -a /etc
/btrbk.conf
<<EOF
197 target send-receive $btrbk_dst
201 sudo btrbk
--progress run
202 $new_shell mount-latest-subvol
206 if $restore_new_btrbk; then
207 $new_shell sudo systemctl start btrbk.timer
209 if $restore_old_btrbk; then
210 $old_shell sudo systemctl start btrbk.timer