File size: 970 Bytes
2b0b6db | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #!/bin/bash
# Extract every archive in MANIFEST.json (shards and linked archives with an extract_to) into <ROOT>, then verify.
# bash restore.sh <ROOT> [parallel jobs, default 8]
# Download the repo into <ROOT> itself (hf download ... --local-dir <ROOT>) so weight folders are already in place.
set -euo pipefail
repo=$(cd "$(dirname "$0")" && pwd)
root=${1:?usage: restore.sh <ROOT> [jobs]}
mkdir -p "$root"
root=$(cd "$root" && pwd)
jobs=${2:-8}
python3 - "$repo" <<'EOF' > "$repo/.restore_list"
import json, sys
m = json.load(open(sys.argv[1] + '/MANIFEST.json'))
for item in m['shards'] + [l for l in m['links'] if 'extract_to' in l]:
print(item['path'] + '\t' + item['extract_to'])
EOF
while IFS=$'\t' read -r path dest; do
mkdir -p "$root/$dest"
printf '%s\0%s\0' "$repo/$path" "$root/$dest"
done < "$repo/.restore_list" | xargs -0 -n 2 -P "$jobs" sh -c 'tar -xf "$0" -C "$1" && echo "extracted $0"'
python3 "$repo/verify_restore.py" "$repo" "$root"
|