File size: 1,657 Bytes
59b0bc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/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