| set -Eeuo pipefail | |
| # Usage: | |
| # | |
| # JOBS=8 ./restore.sh \ | |
| # /path/to/downloaded/shards \ | |
| # /data/aic/shared/artifacts/1fps360 | |
| # | |
| # Defaults: | |
| # archive dir = current directory | |
| # destination = ./1fps360 | |
| ARCHIVE_DIR="${1:-.}" | |
| DEST="${2:-./1fps360}" | |
| JOBS="${JOBS:-8}" | |
| mkdir -p "$DEST" | |
| mapfile -t SHARDS < <( | |
| find "$ARCHIVE_DIR" \ | |
| -maxdepth 1 \ | |
| -type f \ | |
| -name 'shard-*.tar' \ | |
| -print \ | |
| | sort | |
| ) | |
| if [[ "${#SHARDS[@]}" -eq 0 ]]; then | |
| echo "ERROR: no shard-*.tar files found in:" | |
| echo " $ARCHIVE_DIR" | |
| exit 1 | |
| fi | |
| echo "Restoring ${#SHARDS[@]} TAR shards..." | |
| echo "Destination: $DEST" | |
| echo "Parallel jobs: $JOBS" | |
| echo | |
| extract_one() { | |
| local shard="$1" | |
| local dest="$2" | |
| echo "→ $(basename "$shard")" | |
| tar \ | |
| --no-same-owner \ | |
| -xf "$shard" \ | |
| -C "$dest" | |
| } | |
| export -f extract_one | |
| printf '%s\0' "${SHARDS[@]}" \ | |
| | xargs \ | |
| -0 \ | |
| -P "$JOBS" \ | |
| -I '{}' \ | |
| bash -c \ | |
| 'extract_one "$1" "$2"' \ | |
| _ '{}' "$DEST" | |
| echo | |
| echo "Restore completed." | |
| COUNT="$( | |
| find "$DEST" \ | |
| -mindepth 1 \ | |
| -maxdepth 1 \ | |
| -type d \ | |
| | wc -l | |
| )" | |
| echo "Video directories: $COUNT" | |