diff --git a/reorg-backup.sh b/reorg-backup.sh index 58ba053..7b73c2c 100755 --- a/reorg-backup.sh +++ b/reorg-backup.sh @@ -49,67 +49,67 @@ moved=0 skipped=0 errors=0 -# Find all mp4 files in Season/MvtN directories (not already in astro-* dirs) -while IFS= read -r -d '' src_file; do - filename="$(basename "$src_file")" +# Iterate over known cameras only — avoids stray season-shaped paths elsewhere +# in the backup (e.g. a top-level 2026/ dir that would be mistaken for a cam). +for cam_name in "${CAMERAS[@]}" sunrise; do + src_root="$BACKUP_ROOT/$cam_name" + [ -d "$src_root" ] || continue + echo "--- $cam_name ---" - # Extract date: handles YYYY-MM-DD_ (underscore) prefix - date_str="${filename%%_*}" - if ! [[ "$date_str" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then - echo "SKIP (unrecognised filename): $src_file" - (( skipped++ )) || true - continue - fi + while IFS= read -r -d '' src_file; do + filename="$(basename "$src_file")" - # Get ASTRO_YEAR for this date - _info="$(python3 "$SCRIPT_DIR/season_info.py" "$date_str" 2>/dev/null)" || { - echo "SKIP (season_info.py failed for $date_str): $filename" - (( skipped++ )) || true - continue - } - eval "$_info" - - # Reconstruct target path: - # /astro-YEAR///Mvt/ - # Source path is: - # ///Mvt/ - rel_path="${src_file#$BACKUP_ROOT/}" # e.g. north/Winter/Mvt1/2025-01-06_... - cam_and_below="${rel_path#*/}" # e.g. Winter/Mvt1/2025-01-06_... (strip cam) - cam_name="${rel_path%%/*}" # e.g. north - - dest_dir="$BACKUP_ROOT/astro-${ASTRO_YEAR}/$cam_name/$(dirname "$cam_and_below")" - dest_file="$dest_dir/$filename" - - if [ "$src_file" = "$dest_file" ]; then - (( skipped++ )) || true - continue - fi - - if [ -f "$dest_file" ]; then - echo "EXISTS — skip: astro-${ASTRO_YEAR}/$cam_name/$cam_and_below" - (( skipped++ )) || true - continue - fi - - echo "MOVE astro-${ASTRO_YEAR}/$cam_name/$cam_and_below" - - if ! $DRY_RUN; then - mkdir -p "$dest_dir" - if mv "$src_file" "$dest_file"; then - (( moved++ )) || true - else - echo " ERROR: mv failed" - (( errors++ )) || true + # Extract date from YYYY-MM-DD_ prefix + date_str="${filename%%_*}" + if ! [[ "$date_str" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then + echo "SKIP (unrecognised filename): $filename" + (( skipped++ )) || true + continue fi - else - (( moved++ )) || true - fi -done < <(find "$BACKUP_ROOT" \ - -not -path "*/astro-*" \ - -regextype posix-extended \ - -regex ".*/[A-Z][a-z]+/Mvt[0-9]+/[0-9]{4}-[0-9]{2}-[0-9]{2}_.*\.mp4" \ - -print0 | sort -z) + # Get ASTRO_YEAR for this date + _info="$(python3 "$SCRIPT_DIR/season_info.py" "$date_str" 2>/dev/null)" || { + echo "SKIP (season_info.py failed for $date_str): $filename" + (( skipped++ )) || true + continue + } + eval "$_info" + + rel_path="${src_file#$src_root/}" # e.g. Winter/Mvt1/2025-01-06_... + dest_dir="$BACKUP_ROOT/astro-${ASTRO_YEAR}/$cam_name/$(dirname "$rel_path")" + dest_file="$dest_dir/$filename" + + if [ "$src_file" = "$dest_file" ]; then + (( skipped++ )) || true + continue + fi + + if [ -f "$dest_file" ]; then + echo "EXISTS — skip: astro-${ASTRO_YEAR}/$cam_name/$rel_path" + (( skipped++ )) || true + continue + fi + + echo "MOVE astro-${ASTRO_YEAR}/$cam_name/$rel_path" + + if ! $DRY_RUN; then + mkdir -p "$dest_dir" + if mv "$src_file" "$dest_file"; then + (( moved++ )) || true + else + echo " ERROR: mv failed" + (( errors++ )) || true + fi + else + (( moved++ )) || true + fi + + done < <(find "$src_root" \ + -not -path "*/astro-*" \ + -regextype posix-extended \ + -regex ".*/[A-Z][a-z]+/Mvt[0-9]+/[0-9]{4}-[0-9]{2}-[0-9]{2}_.*\.mp4" \ + -print0 | sort -z) +done echo "" echo "────────────────────────────────────────"