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 temp
=$
(getopt
-l help wh
"$@") || usage
1
29 -w) update_wrt
=false
; shift ;;
32 *) echo "$0: Internal error! unexpected args: $*" ; exit 1 ;;
37 (( $# == 2 )) || usage
1
41 source /a
/bin
/bash_unpublished
/source-semi-priv
43 if [[ $old_host != $MAIL_HOST ]]; then
44 read -p "warning: \$old_host != \$MAIL_HOST: $old_host != $MAIL_HOST, proceed? y/N "
45 if [[ $REPLY != [yY
] ]]; then
50 if [[ $new_host == "$HOSTNAME" ]]; then
55 new_shell
="ssh $new_host"
58 old_shell
="ssh $old_host"
59 if [[ $old_host == "$HOSTNAME" ]]; then
63 if [[ ! $new_host ||
! $old_host ]]; then
64 echo "$0: bad args. see script"
69 if [[ $HOSTNAME == tp
]] ||
[[ $HOSTNAME == frodo
]] || timeout
-s 9 5 ssh wrt.b8.nz
:; then
72 echo "$0: at_home = $at_home"
74 source /a
/bin
/bash_unpublished
/source-semi-priv
75 #### begin convert private hostnames to public hostnames ####
77 # for var in old_host new_host; do
80 # eval $var=$HOME_DOMAIN
85 #### end convert private hostnames to public hostnames ####
88 # because our port forward is not robust enough, we can't use proxy command,
89 # todo: setup vpn so this is all taken care of.
90 if ! $update_wrt; then
93 wrt_shell
="ssh wrt.b8.nz"
95 if [[ $old_host == iank.vpn.office.fsf.org ||
$new_host == iank.vpn.office.fsf.org
]]; then
96 wrt_shell
="ssh iank.vpn.office.fsf.org ssh wrt.b8.nz"
98 wrt_shell
="ssh $HOME_DOMAIN ssh wrt.b8.nz"
102 btrbk_test
="systemctl is-active btrbk.service"
103 while $new_shell $btrbk_test ||
$old_shell $btrbk_test; do
104 echo "$0: btrbk is running on new or old host. sleeping for 8 seconds"
106 echo "$0: testing for btrbk activity in 2 seconds"
110 new_hostname
=$
($new_shell hostname
)
112 ########### end initial processing, begin actually modifying things ##########
114 restore_new_btrbk
=false
115 if $new_shell systemctl is-active btrbk.timer
; then
116 $new_shell sudo systemctl stop btrbk.timer
117 restore_new_btrbk
=true
119 restore_old_btrbk
=false
120 if $old_shell systemctl is-active btrbk.timer
; then
121 $old_shell sudo systemctl stop btrbk.timer
122 restore_old_btrbk
=true
126 $new_shell bash
-xs <<'EOF'
128 if mountpoint -q /m; then sudo umount /m; fi
129 if mountpoint -q /o; then sudo umount /o; fi
132 # if new_host is not on home network, make mail.iankelling.org not resolve
133 # on the home network.
134 if [[ $new_host == $HOSTNAME ]] && ! $at_home; then
135 echo |
$wrt_shell cedit mail_host
/etc
/hosts ||
[[ $?
== 1 ]] # 1 means file changed.
137 $wrt_shell bash
-xs $new_host <<'EOFOUTER'
139 cedit mail_host /etc/hosts <<EOF || /etc/init.d/dnsmasq restart
140 $(grep "\b$new_hostname\b" /etc/hosts | awk '{print $1}') mail.iankelling.org
145 $old_shell /a
/bin
/distro-setup
/install-my-scripts
146 $old_shell primary-setup
$new_hostname
148 sudo
dd of
=/etc
/btrbk.conf
<<'EOF'
149 ssh_identity /root/.ssh/home
150 # Just a guess that local7 is a good facility to pick.
151 # It's a bit odd that the transaction log has to be logged to
152 # a file or syslog, while other output is sent to std out.
153 # The man does not mention a way for them to be together, but
154 # I dunno if setting a log level like warn might also output
156 transaction_syslog local7
158 # so we only run one at a time
159 lockfile /var/lock/btrbk.lock
161 # default format of short does not accomidate hourly preservation setting
162 timestamp_format long-iso
164 # only make a snapshot if things have changed
165 snapshot_create onchange
166 # I could make this different from target_preserve,
167 # if one disk had less space.
168 # for now, keeping them equal.
169 snapshot_preserve 36h 14d 8w 24m
170 snapshot_preserve_min 4h
173 # so, total backups = ~89
174 target_preserve 36h 14d 8w 24m
175 target_preserve_min 4h
177 # if something fails and it's not obvious, try doing
178 # btrbk -l debug -v dryrun
184 if $localhost_new; then
185 btrbk_src
=ssh://$old_host/mnt
/root
186 btrbk_dst
=/mnt
/root
/btrbk
189 btrbk_dst
=ssh://$new_host/mnt
/root
/btrbk
192 sudo
tee -a /etc
/btrbk.conf
<<EOF
195 target send-receive $btrbk_dst
199 sudo btrbk
-l debug
--progress run
200 $new_shell /a
/bin
/distro-setup
/install-my-scripts
201 $new_shell mount-latest-subvol
202 $new_shell primary-setup
$new_hostname
204 if $restore_new_btrbk; then
205 $new_shell sudo systemctl start btrbk.timer
207 if $restore_old_btrbk; then
208 $old_shell sudo systemctl start btrbk.timer