From 440d3482e21e147c39d965e104ab41d7241cbde8 Mon Sep 17 00:00:00 2001 From: Bill Date: Fri, 23 Apr 2021 21:34:59 -0400 Subject: Initial draft --- ssync | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 ssync diff --git a/ssync b/ssync new file mode 100755 index 0000000..5396be0 --- /dev/null +++ b/ssync @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -ex + +if [ $# -lt 3 ]; then + echo "Usage: ssync KEY_FILE REMOTE_DIR SRC_DIR" + exit 1 +fi + +KEY_FILE=$1 +REMOTE_DIR=$2 +SRC_DIR=$3 + +LASTRAN_DIR=$HOME/.local/ssync +LASTRAN_FILE=$LASTRAN_DIR/.lastran +NEXT_RUN_DATE=$(date -Is) +PREV_RUN_DATE=$(cat $HOME/.local/ssync/.lastran) + +echo "Failsafe - Running at: $NEXT_RUN_DATE - if failed to write use this timestamp in $LASTRAN_FILE" + +if [ ! -f $LASTRAN_FILE ]; then + mkdir -p $LASTRAN_DIR + echo $NEXT_RUN_DATE > $LASTRAN_FILE + echo "No run existed marking next run for files newer than: $NEXT_RUN_DATE" + exit 0; +fi + +if [ $PREV_RUN_DATE == "" ]; then + echo $NEXT_RUN_DATE > $LASTRAN_FILE + echo "No run existed marking next run for files newer than: $NEXT_RUN_DATE" + exit 0; +fi + +echo "Syncing files since: $PREV_RUN_DATE" + +rsync -e "ssh -i $KEY_FILE" \ + -av \ + --files-from=<(ssh -i $KEY_FILE billserver "find ${REMOTE_DIR} -newermt ${PREV_RUN_DATE} -exec realpath --relative-to ${REMOTE_DIR} {} \;") \ + billserver:${REMOTE_DIR} ${SRC_DIR} + +echo $NEXT_RUN_DATE > $LASTRAN_FILE +echo "Done syncing" -- cgit v1.2.3-54-g00ecf