FOLDS / hf_sync_loop.sh
Amar-Aly's picture
Add files using upload-large-folder tool
59b0bc0 verified
Raw
History Blame Contribute Delete
1.66 kB
#!/usr/bin/env bash
set -u
REPO_ID="AI-555/APR_10_FOLDS"
SRC_DIR="/workspace"
SNAP_TAR="/workspace/workspace_snapshot.tar"
SNAP_DIR="/workspace/_hf_snapshot"
LOG_FILE="/workspace/hf_upload.log"
SLEEP_SECS=2400
log() {
printf '[%s] %s\n' "$(date -Is)" "$*"
}
while true; do
log "========================================"
log "starting new sync cycle"
log "repo: ${REPO_ID}"
log "source: ${SRC_DIR}"
log "removing old tar snapshot if present"
rm -f "${SNAP_TAR}"
log "creating tar snapshot"
if tar \
--exclude="${SRC_DIR}/.cache" \
--exclude="${SRC_DIR}/_hf_snapshot" \
--exclude="${SRC_DIR}/hf_upload.log" \
--exclude="${SRC_DIR}/workspace_snapshot.tar" \
-cf "${SNAP_TAR}" "${SRC_DIR}"
then
log "tar snapshot created: ${SNAP_TAR}"
else
log "ERROR: failed to create tar snapshot"
log "sleeping ${SLEEP_SECS}s before retry"
sleep "${SLEEP_SECS}"
continue
fi
log "rebuilding extracted snapshot directory"
rm -rf "${SNAP_DIR}"
mkdir -p "${SNAP_DIR}"
log "extracting tar snapshot into ${SNAP_DIR}"
if tar -xf "${SNAP_TAR}" -C "${SNAP_DIR}" --strip-components=1
then
log "snapshot extracted successfully"
else
log "ERROR: failed to extract tar snapshot"
log "sleeping ${SLEEP_SECS}s before retry"
sleep "${SLEEP_SECS}"
continue
fi
log "starting HF upload-large-folder"
if hf upload-large-folder "${REPO_ID}" "${SNAP_DIR}" --repo-type dataset
then
log "HF sync finished successfully"
else
EXIT_CODE=$?
log "ERROR: HF sync failed with exit code ${EXIT_CODE}"
fi
log "cycle done, sleeping ${SLEEP_SECS}s"
sleep "${SLEEP_SECS}"
done