From: Ian Kelling Date: Thu, 5 May 2016 14:19:10 +0000 (-0700) Subject: mostly working X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=commitdiff_plain;h=474fb77f4aa8e79a4706aff9c511452e180fff64 mostly working --- 474fb77f4aa8e79a4706aff9c511452e180fff64 diff --git a/myunison b/myunison new file mode 100755 index 0000000..fa79b4a --- /dev/null +++ b/myunison @@ -0,0 +1,55 @@ +#!/bin/bash -l + +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR + +gen_args=() +do_snapshot=true +while [[ $1 == -* ]]; do + case $1 in + -n) do_snapshot=false; shift ;; + --) shift; break ;; + -*) gen_args+=($1) ; shift ;; + esac +done + + +# arch and debian don't play nice with unison. +# "connection lost" on unison-gtk, with bignum errs in term, +# and simply freezing on cli, all means compiled under +# different ocaml versions. +# I had the great realization that unison is a self contained +# binary with no special runtime dependencies. +# However, I got a gtk error running the ui version. +# todo: I should test pushing my unison version instead +# of pulling it. +/p/c/subdir_files/.unison/gen ${gen_args[@]} +if [[ ! $1 ]]; then + echo "$0: error: expected argument for hostname" + exit 1 +fi + +host=$1 + +# todo: this doesn't deal with if the host is running arch too + +# note, without bash, it prints some crap about tty +# on an uncustomized jessie install. +scp /usr/bin/unison root@$host:/usr/local/bin + +if $do_snapshot; then + unison-snapshot + ssh root@$host unison-snapshot +fi + +f=unison-gtk +type -t $f &>/dev/null || f=unison-gtk2 # for arch +if s $f "$@"; then + if [[ $host == frodo ]]; then + # only send data to the machine i do full backups to + p=/p/c/machine_specific/$HOSTNAME/.unison/ + s rsync -rlptgohi $p root@$host:$p + fi + p=/p/c/machine_specific/$host/.unison/ + s rsync -rlptgohvi root@$host:$p $p +fi diff --git a/unison-snapshot b/unison-snapshot new file mode 100755 index 0000000..aa2a63b --- /dev/null +++ b/unison-snapshot @@ -0,0 +1,24 @@ +#!/bin/bash -l + +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR + +base=unison-$(date "+%Y:%m:%d") +for mountp in /mnt/root /mnt/iroot; do + [[ -e $mountp ]] || continue + full_base=$mountp/$base + existing=( $full_base-* ) + if [[ -e ${existing[0]} ]]; then + snapshot=$full_base-$(( ${#existing[@]} + 1 )) + else + snapshot=$full_base-1 + fi + s btrfs subvolume snapshot -r $mountp $snapshot + existing=( $mountp/unison-* ) + # keep 10 unison snapshots around + if (( ${#existing[@]} > 10 )); then + IFS=$'\n' existing=($(sort -Vr <<<"${existing[*]}")) + unset IFS + s btrfs subvolume delete ${existing[@]:10} + fi +done