diff options
-rwxr-xr-x | ssync | 35 |
1 files changed, 21 insertions, 14 deletions
@@ -54,23 +54,30 @@ log "Syncing files since: $PREV_RUN_DATE" log "Fetching files" mkdir -p $RUN_DIR ssh -i $KEY_FILE $REMOTE "find ${REMOTE_DIR} -type f -newermt ${PREV_RUN_DATE} -exec realpath --relative-to ${REMOTE_DIR} {} \;" >> $CURGET_FILE -comm -23 <(sort -u $CURGET_FILE) <(sort -u $FETCHED_FILE) > $FETCH_FILE -COUNT=$(wc -l $FETCH_FILE | cut -d' ' -f1) +GET_COUNT=$(wc -l $CURGET_FILE | cut -d' ' -f1) -if [ $COUNT -gt 0 ]; then - # - # Syncing - # - log "Found ${COUNT} files to fetch" +if [ $GET_COUNT -gt 0 ]; then + comm -23 <(sort -u $CURGET_FILE) <(sort -u $FETCHED_FILE) > $FETCH_FILE + COUNT=$(wc -l $FETCH_FILE | cut -d' ' -f1) - cat $FETCH_FILE >> $FETCHED_FILE - log "Wrote files to fetched files" - log "Syncing now" - cat $FETCH_FILE | xargs -n1 -P$PARALLEL -I '{}' rsync -e "ssh -i $KEY_FILE" \ - -av \ - $REMOTE:"${REMOTE_DIR}/'{}'" ${SRC_DIR} + if [ $COUNT -gt 0 ]; then + # + # Syncing + # + log "Found ${COUNT} files to fetch" + + cat $FETCH_FILE >> $FETCHED_FILE + log "Wrote files to fetched files" + log "Syncing now" + cat $FETCH_FILE | xargs -n1 -P$PARALLEL -I '{}' rsync -e "ssh -i $KEY_FILE" \ + -av \ + $REMOTE:"${REMOTE_DIR}/'{}'" ${SRC_DIR} + else + log "No files to sync - deleting $CURGET_FILE" + rm -f $CURGET_FILE + fi else - log "No files to sync - deleting $CURGET_FILE" + log "No new files found - deleting $CURGET_FILE" rm -f $CURGET_FILE fi |