File size: 1,248 Bytes
427b327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
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"