From 82b146c2299fce1aec68d492e4bd881d81e8e6c9 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Fri, 18 Nov 2016 06:43:32 -0800 Subject: [PATCH] various fixes --- btrbk-run | 14 +++++++++----- distro-begin | 25 ++++++++++++++++--------- distro-end | 20 +++++++++++++------- mail-setup | 11 ++++++----- mount-latest-subvol | 24 +++++++++++++++++------- 5 files changed, 61 insertions(+), 33 deletions(-) diff --git a/btrbk-run b/btrbk-run index 05589d1..c59faf9 100755 --- a/btrbk-run +++ b/btrbk-run @@ -18,13 +18,15 @@ script_dir=$(dirname $(readlink "$BASH_SOURCE")) conf_only=false dry_run=false # mostly for testing +resume_arg= -temp=$(getopt -l help hcnt: "$@") || usage 1 +temp=$(getopt -l help hcnrt: "$@") || usage 1 eval set -- "$temp" while true; do case $1 in -c) conf_only=true; shift ;; -n) dry_run=true; dry_run_arg=-n; shift ;; + -r) resume_arg=-r; shift ;; -t) IFS=, targets=($2); shift 2 ;; -h|--help) usage ;; --) shift; break ;; @@ -81,7 +83,9 @@ fi # a subvol on current host is not fresh. # umount first to ensure we don't have any errors # todo: do some kill fuser stuff to make umount more reliable -# todo: run this on a systemd timer on $primary, once per hour. +# todo: run this on a systemd timer on $primary, once per hour, +# and if primary is, change that timer over to primary, and make +# sure we mount the latest # todo: setup lock so that if this is already running, we exit out, so # that manual runs don't interfere with cronjobs. @@ -129,9 +133,9 @@ if $conf_only; then fi if $dry_run; then - btrbk -n run + btrbk -n $resume_arg run else - btrbk -q run + btrbk -q $resume_arg run fi # if we have /p, rsync to targets without /p @@ -153,7 +157,7 @@ fi if ! $dry_run; then for tg in ${targets[@]}; do scp $script_dir/{mount-latest-subvol,check-subvol-stale} \ - root@tg:/usr/local/bin + root@$tg:/usr/local/bin ssh root@$tg bash <<'EOF' set -e chmod +x /usr/local/bin/{mount-latest-subvol,check-subvol-stale} diff --git a/distro-begin b/distro-begin index 5297da8..bf298d5 100755 --- a/distro-begin +++ b/distro-begin @@ -577,10 +577,17 @@ for dir in /{i,w,k}; do done dir=/nocow -l=$(sed -rn "s#^(\s*\S+\s+)/q(\s.*)(subvol=q)#\1$dir\2subvol=nocow#p" /etc/fstab) -if [[ $l ]] && ! mountpoint $dir; then +if ! mountpoint $dir; then + subvol=/mnt/root/nocow + if [[ ! -e nocow ]]; then + btrfs subvolume create $subvol + chown root:1000 $subvol + chattr +C $subvol + fi + + first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab) tu /etc/fstab < ~/.forward e $forward | s tee /root/.forward -# linode image has a root alias. completely useless, remove it. -sudo sed -i '/^root:/d' /etc/aliases - -s newaliases - # offlineimap uses this too, it is much easier to use one location than to # condition it's config and postfix's config @@ -180,6 +175,12 @@ EOF fi fi +# linode image has a root alias. completely useless, remove it. +sudo sed -i '/^root:/d' /etc/aliases + +s newaliases + + # based on http://www.postfix.org/qmgr.8.html and my notes in gnus dir=/nocow/$type sdir=/var/spool/$type diff --git a/mount-latest-subvol b/mount-latest-subvol index 6a714d1..f62f1f4 100644 --- a/mount-latest-subvol +++ b/mount-latest-subvol @@ -44,8 +44,20 @@ bash-trace() { } errcatch - +tu() { + while read -r line; do + file="$1" + grep -xFq "$line" "$file" || tee -a "$file"<<<"$line" + done +} e() { printf "%s\n" "$*"; "$@"; } +mnt() { + dir=$1 + if ! mountpoint $dir >/dev/null; then + mkdir -p $dir + e mount $dir + fi +} ret=0 @@ -90,8 +102,6 @@ EOF fi -mkdir -p /q /p /i - for vol in q p; do d=/$vol if ! awk '{print $2}' /etc/fstab | grep -xF $d &>/dev/null; then @@ -105,7 +115,7 @@ for vol in q p; do new_roots=() for r in ${roots[@]}; do # /q/a /a none bind 0 0 - new_roots+=($(sed -rn "s#^$r/\S+\s+(\S+)\s+none\s+bind\s.*#\1#" /etc/fstab)) + new_roots+=($(sed -rn "s#^$r/\S+\s+(\S+)\s+none\s+bind\s.*#\1#p" /etc/fstab)) done (( ${#new_roots} )) || break binds+=(${new_roots[@]}) @@ -114,7 +124,7 @@ for vol in q p; do if e check-subvol-stale $d; then for b in ${binds[@]}; do - mount $b + mnt $b done continue fi @@ -142,7 +152,7 @@ for vol in q p; do if ! $umount_ret; then for dir in ${unmounted[@]}; do - mount $dir + mnt $dir done ret=1 continue @@ -157,7 +167,7 @@ for vol in q p; do # things otherwise didn't get mounted very strangely. e btrfs sub snapshot btrbk/$last_snap $vol for dir in $d ${binds[@]}; do - e mount $dir + e mnt $dir done done exit $ret -- 2.30.2