Fix reorg-backup.sh camera scoping — prevent 2026/ dir misidentified as cam
Restructure find loop to iterate known CAMERAS+sunrise in the main shell so cam_name is visible in the while body. Previously the for loop ran in a process substitution subshell, making cam_name unavailable and causing top-level year dirs (e.g. 2026/) to be treated as camera names. https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
This commit is contained in:
+57
-57
@@ -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:
|
||||
# <backup_root>/astro-YEAR/<cam>/<Season>/Mvt<N>/<filename>
|
||||
# Source path is:
|
||||
# <backup_root>/<cam>/<Season>/Mvt<N>/<filename>
|
||||
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 "────────────────────────────────────────"
|
||||
|
||||
Reference in New Issue
Block a user