diff options
author | Bill <bill@billserver.senders.io> | 2021-04-23 21:34:59 -0400 |
---|---|---|
committer | Bill <bill@billserver.senders.io> | 2021-04-23 21:34:59 -0400 |
commit | 440d3482e21e147c39d965e104ab41d7241cbde8 (patch) | |
tree | f749329f22219e71167624ea4db3e79cebfb040c |
Initial draft
-rwxr-xr-x | ssync | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -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" |