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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# =============================================================================
|
| 3 |
+
# HiReT / Clinical-Reasoning backup - restore helper
|
| 4 |
+
#
|
| 5 |
+
# Backup repo : https://huggingface.co/datasets/Xin-Rui/Med_Reason
|
| 6 |
+
# Archive : hitraj_backup_20260929.7z.001 ... .061 (AES-256, header-encrypted)
|
| 7 |
+
# Contents : 444,063 files / 7,249 folders / 325.6 GB uncompressed
|
| 8 |
+
#
|
| 9 |
+
# WHAT THIS SCRIPT DOES
|
| 10 |
+
# 1. download the 61 encrypted volumes, the checksum list and RESTORE.md
|
| 11 |
+
# 2. verify every volume against the published SHA256 list
|
| 12 |
+
# 3. optional: concatenate the volumes into one single .7z file
|
| 13 |
+
# 4. extract the archive into /root (the original absolute paths come back)
|
| 14 |
+
# 5. print the command that rebuilds the Python environment
|
| 15 |
+
#
|
| 16 |
+
# THE PASSPHRASE
|
| 17 |
+
# * It is NOT in this script and NOT in the repository.
|
| 18 |
+
# * You are prompted for it in STEP 4 (extraction). If you also run the
|
| 19 |
+
# optional full integrity test you are prompted again there. Nothing else
|
| 20 |
+
# needs it.
|
| 21 |
+
# * Keep it in a password manager and in one offline copy. Without it the
|
| 22 |
+
# backup can never be opened again.
|
| 23 |
+
#
|
| 24 |
+
# RESOURCES
|
| 25 |
+
# download: about 310 GB; extraction: another ~326 GB. Budget ~700 GB free.
|
| 26 |
+
#
|
| 27 |
+
# USAGE
|
| 28 |
+
# bash restore_hitraj_backup.sh # download + verify + extract
|
| 29 |
+
# bash restore_hitraj_backup.sh --skip-download # volumes already on disk
|
| 30 |
+
# bash restore_hitraj_backup.sh --skip-verify # trust volumes already verified
|
| 31 |
+
# bash restore_hitraj_backup.sh --single-file # also build one single .7z
|
| 32 |
+
# bash restore_hitraj_backup.sh --only "autodl-tmp/backup_meta/*"
|
| 33 |
+
# # restore only a subset (quick test)
|
| 34 |
+
# DEST=/data/restore bash restore_hitraj_backup.sh # custom download directory
|
| 35 |
+
# =============================================================================
|
| 36 |
+
|
| 37 |
+
set -Eeuo pipefail
|
| 38 |
+
|
| 39 |
+
REPO="Xin-Rui/Med_Reason"
|
| 40 |
+
REPO_TYPE="dataset"
|
| 41 |
+
VOL_PREFIX="hitraj_backup_20260929.7z"
|
| 42 |
+
SHA_FILE="${VOL_PREFIX}.volumes.sha256"
|
| 43 |
+
DEST="${DEST:-/root/autodl-tmp/restore}"
|
| 44 |
+
EXTRACT_ROOT="${EXTRACT_ROOT:-/root}"
|
| 45 |
+
SKIP_DOWNLOAD=0
|
| 46 |
+
SKIP_VERIFY=0
|
| 47 |
+
SINGLE_FILE=0
|
| 48 |
+
ONLY_PATTERN=""
|
| 49 |
+
|
| 50 |
+
while [ $# -gt 0 ]; do
|
| 51 |
+
case "$1" in
|
| 52 |
+
--skip-download) SKIP_DOWNLOAD=1 ;;
|
| 53 |
+
--skip-verify) SKIP_VERIFY=1 ;;
|
| 54 |
+
--single-file) SINGLE_FILE=1 ;;
|
| 55 |
+
--dest) DEST="$2"; shift ;;
|
| 56 |
+
--only) ONLY_PATTERN="$2"; shift ;;
|
| 57 |
+
*) echo "unknown option: $1"; exit 2 ;;
|
| 58 |
+
esac
|
| 59 |
+
shift
|
| 60 |
+
done
|
| 61 |
+
|
| 62 |
+
log() { printf "\n=== %s\n" "$*"; }
|
| 63 |
+
|
| 64 |
+
# ------------------------------------------------------------------ step 0 --
|
| 65 |
+
log "STEP 0 checking tools"
|
| 66 |
+
for t in sha256sum cat; do
|
| 67 |
+
command -v "$t" >/dev/null || { echo "missing tool: $t"; exit 1; }
|
| 68 |
+
done
|
| 69 |
+
if ! command -v 7z >/dev/null; then
|
| 70 |
+
echo "7z is missing. Install it first, for example:"
|
| 71 |
+
echo " apt-get update && apt-get install -y p7zip-full"
|
| 72 |
+
exit 1
|
| 73 |
+
fi
|
| 74 |
+
HF_CLI=""
|
| 75 |
+
for c in hf huggingface-cli; do
|
| 76 |
+
if command -v "$c" >/dev/null; then HF_CLI="$c"; break; fi
|
| 77 |
+
done
|
| 78 |
+
echo "7z : $(7z | sed -n 2p)"
|
| 79 |
+
echo "hf cli : ${HF_CLI:-not found (only needed for the download step)}"
|
| 80 |
+
|
| 81 |
+
mkdir -p "$DEST"
|
| 82 |
+
|
| 83 |
+
# ------------------------------------------------------------------ step 1 --
|
| 84 |
+
if [ "$SKIP_DOWNLOAD" = 0 ]; then
|
| 85 |
+
log "STEP 1 downloading volumes from https://huggingface.co/datasets/$REPO"
|
| 86 |
+
if [ -z "$HF_CLI" ]; then
|
| 87 |
+
echo "huggingface cli not found. Install it with: pip install -U huggingface_hub"
|
| 88 |
+
exit 1
|
| 89 |
+
fi
|
| 90 |
+
# HF_HUB_DISABLE_XET=1 keeps the classic transfer path. On machines with a
|
| 91 |
+
# small memory cgroup the xet backend buffers about 1.3 GB per file and can
|
| 92 |
+
# be OOM-killed, which is exactly what happened when this backup was made.
|
| 93 |
+
HF_HUB_DISABLE_XET=1 "$HF_CLI" download "$REPO" \
|
| 94 |
+
--repo-type "$REPO_TYPE" \
|
| 95 |
+
--local-dir "$DEST" \
|
| 96 |
+
--include "${VOL_PREFIX}.0*" \
|
| 97 |
+
--include "$SHA_FILE" \
|
| 98 |
+
--include "RESTORE.md"
|
| 99 |
+
else
|
| 100 |
+
log "STEP 1 skipped (--skip-download)"
|
| 101 |
+
fi
|
| 102 |
+
|
| 103 |
+
cd "$DEST"
|
| 104 |
+
if ! ls -1 "${VOL_PREFIX}".0* >/dev/null 2>&1; then
|
| 105 |
+
echo "no volumes found in $DEST"
|
| 106 |
+
exit 1
|
| 107 |
+
fi
|
| 108 |
+
echo "volumes present: $(ls -1 ${VOL_PREFIX}.0* | wc -l)"
|
| 109 |
+
|
| 110 |
+
# ------------------------------------------------------------------ step 2 --
|
| 111 |
+
log "STEP 2 verifying every volume (SHA256)"
|
| 112 |
+
if [ "$SKIP_VERIFY" = 1 ]; then
|
| 113 |
+
echo "skipped (--skip-verify). Note: this step reads all volumes and takes a while."
|
| 114 |
+
else
|
| 115 |
+
sha256sum -c "$SHA_FILE"
|
| 116 |
+
fi
|
| 117 |
+
|
| 118 |
+
# ------------------------------------------------------------------ step 3 --
|
| 119 |
+
if [ "$SINGLE_FILE" = 1 ]; then
|
| 120 |
+
log "STEP 3 concatenating the volumes into one single .7z"
|
| 121 |
+
cat "${VOL_PREFIX}".0* > "${VOL_PREFIX}"
|
| 122 |
+
sha256sum "${VOL_PREFIX}" | tee "${VOL_PREFIX}.sha256"
|
| 123 |
+
ARCHIVE="${VOL_PREFIX}"
|
| 124 |
+
else
|
| 125 |
+
log "STEP 3 skipped - keeping the volume set (7z reads all volumes automatically)"
|
| 126 |
+
ARCHIVE="${VOL_PREFIX}.001"
|
| 127 |
+
fi
|
| 128 |
+
|
| 129 |
+
# ------------------------------------------------------------------ step 4 --
|
| 130 |
+
log "STEP 4 extracting >>> THE PASSPHRASE IS REQUIRED HERE <<<"
|
| 131 |
+
printf "archive passphrase: "
|
| 132 |
+
read -rs ARCHIVE_PASS
|
| 133 |
+
echo
|
| 134 |
+
if [ -z "$ARCHIVE_PASS" ]; then
|
| 135 |
+
echo "empty passphrase - aborting"
|
| 136 |
+
exit 1
|
| 137 |
+
fi
|
| 138 |
+
|
| 139 |
+
cd "$EXTRACT_ROOT"
|
| 140 |
+
if [ -n "$ONLY_PATTERN" ]; then
|
| 141 |
+
echo "restoring subset only: $ONLY_PATTERN"
|
| 142 |
+
7z x -p"$ARCHIVE_PASS" -y "$DEST/$ARCHIVE" "$ONLY_PATTERN"
|
| 143 |
+
else
|
| 144 |
+
7z x -p"$ARCHIVE_PASS" -y "$DEST/$ARCHIVE"
|
| 145 |
+
fi
|
| 146 |
+
unset ARCHIVE_PASS
|
| 147 |
+
|
| 148 |
+
echo
|
| 149 |
+
echo "extracted into $EXTRACT_ROOT"
|
| 150 |
+
echo "restored layout: $EXTRACT_ROOT/autodl-tmp/Clinical_Reasoning/..."
|
| 151 |
+
echo " $EXTRACT_ROOT/autodl-tmp/ClinicalReasoning-ICLR/..."
|
| 152 |
+
echo " $EXTRACT_ROOT/autodl-tmp/backup_meta/..."
|
| 153 |
+
echo
|
| 154 |
+
echo "optional, end-to-end integrity test of the archive (asks for the passphrase again):"
|
| 155 |
+
echo " 7z t -p\"<passphrase>\" \"$DEST/${VOL_PREFIX}.001\""
|
| 156 |
+
|
| 157 |
+
# ------------------------------------------------------------------ step 5 --
|
| 158 |
+
log "STEP 5 rebuilding the Python environment"
|
| 159 |
+
cat <<EOT
|
| 160 |
+
with conda:
|
| 161 |
+
/root/miniconda3/bin/conda env create -f ${EXTRACT_ROOT}/autodl-tmp/backup_meta/env_llama-fac-wxr.yml
|
| 162 |
+
|
| 163 |
+
without conda:
|
| 164 |
+
pip install -r ${EXTRACT_ROOT}/autodl-tmp/backup_meta/pip_freeze.txt
|
| 165 |
+
|
| 166 |
+
Full notes, including what is deliberately not included and how the embedding
|
| 167 |
+
caches were produced, are in ${EXTRACT_ROOT}/autodl-tmp/backup_meta/RESTORE.md.
|
| 168 |
+
|
| 169 |
+
Reminder: Datasets/, per-sample predictions and the embedding caches are
|
| 170 |
+
MIMIC-IV derived. Keep repository access restricted and keep the passphrase
|
| 171 |
+
private even though the archive itself is encrypted.
|
| 172 |
+
EOT
|