#!/usr/bin/env bash
# Resume a batch extraction — skips inodes whose destination already exists.
# Equivalent to batch_recover.sh --skip-existing but kept separate for clarity.
set -euo pipefail

DEST="/mnt/recovered/apr30"
DB="inodes.db"
INPUT="orphan_roots.txt"
JOBS=10

mkdir -p "$DEST"

while read -r inum rest; do
    [[ -z "$inum" || "$inum" == \#* ]] && continue
    python3 extract_tree.py \
        --db "$DB" \
        --dest "$DEST" \
        --skip-existing \
        "$inum" &
    while (( $(jobs -r | wc -l) >= JOBS )); do
        wait -n 2>/dev/null || sleep 0.2
    done
done < "$INPUT"

wait
echo "All done"
