← back to Dw Photo Capture
scripts/sync-vendor-photos-to-henry.sh
24 lines
#!/bin/bash
# Nightly: copy the dwphoto per-vendor photo archive (Kamatera) down to Henry.
# Additive only — never passes --delete, so a photo removed on the server is kept on Henry.
# Runs under launchd's /bin/bash 3.2: keep it simple (no heredocs inside $()).
set -u
REMOTE="root@45.61.58.125:/root/public-projects/dwphoto"
DEST="/Volumes/Henry/dwphoto-vendor-photos"
LOG="$HOME/Library/Logs/dwphoto-vendor-photos-sync.log"
STAMP="$DEST/.last-sync"
ts() { date '+%Y-%m-%dT%H:%M:%S%z'; }
if [ ! -d /Volumes/Henry ]; then echo "$(ts) FAIL Henry not mounted" >> "$LOG"; exit 2; fi
mkdir -p "$DEST/vendors" || { echo "$(ts) FAIL mkdir $DEST" >> "$LOG"; exit 3; }
SSH="ssh -o BatchMode=yes -o ConnectTimeout=15"
if ! $SSH root@45.61.58.125 'test -d /root/public-projects/dwphoto/photos/vendors'; then
if $SSH root@45.61.58.125 true; then echo "$(ts) OK 0 photos (nothing archived on server yet)" | tee "$STAMP" >> "$LOG"; exit 0; fi
echo "$(ts) FAIL cannot reach server" >> "$LOG"; exit 5
fi
if ! rsync -a -e "$SSH" "$REMOTE/photos/vendors/" "$DEST/vendors/" >> "$LOG" 2>&1; then
echo "$(ts) FAIL rsync photos" >> "$LOG"; exit 4
fi
rsync -a -e "$SSH" "$REMOTE/data/vendor-photos.jsonl" "$DEST/vendor-photos.jsonl" >> "$LOG" 2>&1 || echo "$(ts) WARN index not copied" >> "$LOG"
N=$(find "$DEST/vendors" -type f -name '*.jpg' | wc -l | tr -d ' ')
echo "$(ts) OK $N photos" | tee "$STAMP" >> "$LOG"