Files
claudetools/UPDATE.BAT
Mike Swanson 925a769786 fix: Replace NUL device references with DOS 6.22 compatible tests
Critical fix for DOS 6.22 compatibility - NUL is a reserved device name
in both DOS and Windows and cannot be used as a file/directory name.

Problem:
- "T: 2>NUL" attempts to create a file called "NUL" (not allowed)
- "IF NOT EXIST T:\NUL" tests for NUL device (unreliable)
- "IF NOT EXIST path\NUL" treats NUL as filename (invalid)

Solution - Replaced with proper DOS 6.22 tests:
- "T: 2>NUL" → "DIR T:\ >nul" (test drive access via directory listing)
- "IF NOT EXIST T:\NUL" → "IF NOT EXIST T:\*.*" (test for any files)
- "IF NOT EXIST path\NUL" → "IF NOT EXIST path\*.*" (test directory)

Note: Using lowercase "nul" for output redirection is acceptable as
it redirects to the NUL device, but NUL as a filename/path is invalid.

Files updated:
- DEPLOY.BAT: Fixed drive and directory tests
- UPDATE.BAT: Fixed drive and directory tests
- NWTOC.BAT: Fixed drive and directory tests
- CTONW.BAT: Fixed drive and directory tests
- CHECKUPD.BAT: Fixed drive and directory tests
- DOSTEST.BAT: Fixed drive and directory tests

Created fix-nul-references.ps1:
- Automated script to find and fix NUL references
- Preserves CRLF line endings
- Updates all BAT files consistently

Created monitoring scripts:
- monitor-sync-status.ps1: Periodic sync monitoring
- quick-sync-check.ps1: Quick AD2-to-NAS sync status check

Verification:
- All BAT files maintain CRLF line terminators
- File sizes increased slightly (4-8 bytes) due to pattern changes
- DOS 6.22 compatible wildcard tests (*.*) used throughout

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 16:41:31 -07:00

211 lines
5.0 KiB
Batchfile

@ECHO OFF
REM UPDATE.BAT - Backup Dataforth test machine to network storage
REM Usage: UPDATE [machine-name]
REM Example: UPDATE TS-4R
REM
REM If machine-name not provided, uses MACHINE environment variable
REM from AUTOEXEC.BAT
REM
REM Version: 2.0 - Fixed for DOS 6.22
REM Last modified: 2026-01-19
REM ==================================================================
REM STEP 1: Determine machine name
REM ==================================================================
IF NOT "%1"=="" GOTO USE_PARAM
IF NOT "%MACHINE%"=="" GOTO USE_ENV
:NO_MACHINE
ECHO.
ECHO [ERROR] Machine name not specified
ECHO.
ECHO Usage: UPDATE machine-name
ECHO Example: UPDATE TS-4R
ECHO.
ECHO Or set MACHINE variable in AUTOEXEC.BAT:
ECHO SET MACHINE=TS-4R
ECHO.
PAUSE Press any key to exit...
GOTO END
:USE_PARAM
SET MACHINE=%1
GOTO CHECK_DRIVE
:USE_ENV
REM Machine name from environment variable
GOTO CHECK_DRIVE
REM ==================================================================
REM STEP 2: Verify T: drive is accessible
REM ==================================================================
:CHECK_DRIVE
ECHO Checking network drive T:...
REM Method 1: Try to switch to T: drive
REM Save current drive
SET OLDDRV=%CD:~0,2%
IF "%OLDDRV%"=="" SET OLDDRV=C:
REM Test T: drive access
DIR T:\ >nul
IF ERRORLEVEL 1 GOTO NO_T_DRIVE
REM Drive exists, switch back
%OLDDRV%
REM Method 2: Double-check with NUL device test
IF NOT EXIST T:\*.* GOTO NO_T_DRIVE
ECHO [OK] T: drive accessible
GOTO START_BACKUP
:NO_T_DRIVE
ECHO.
ECHO [ERROR] T: drive not available
ECHO.
ECHO Network drive T: must be mapped to \\D2TESTNAS\test
ECHO.
ECHO Run STARTNET.BAT to map network drives:
ECHO C:\NET\STARTNET.BAT
ECHO.
ECHO Or map manually:
ECHO NET USE T: \\D2TESTNAS\test /YES
ECHO.
PAUSE Press any key to exit...
GOTO END
REM ==================================================================
REM STEP 3: Create backup directory structure
REM ==================================================================
:START_BACKUP
ECHO.
ECHO ==============================================================
ECHO Backup: Machine %MACHINE%
ECHO ==============================================================
ECHO Source: C:\
ECHO Target: T:\%MACHINE%\BACKUP
ECHO.
REM Create machine directory if it doesn't exist
IF NOT EXIST T:\%MACHINE%\NUL MD T:\%MACHINE%
REM Create backup directory
IF NOT EXIST T:\%MACHINE%\BACKUP\NUL MD T:\%MACHINE%\BACKUP
REM Check if backup directory was created successfully
IF NOT EXIST T:\%MACHINE%\BACKUP\*.* GOTO BACKUP_DIR_ERROR
ECHO [OK] Backup directory ready
ECHO.
REM ==================================================================
REM STEP 4: Perform backup
REM ==================================================================
ECHO Starting backup...
ECHO This may take several minutes depending on file count.
ECHO.
REM XCOPY options:
REM /S = Copy subdirectories (except empty ones)
REM /E = Copy subdirectories (including empty ones)
REM /Y = Suppress prompts (auto-overwrite)
REM /D = Copy only files that are newer
REM /H = Copy hidden and system files
REM /K = Copy attributes
REM /C = Continue on errors
REM /Q = Quiet mode (don't show filenames)
XCOPY C:\*.* T:\%MACHINE%\BACKUP /S /E /Y /D /H /K /C /Q
REM Check XCOPY error level
REM 0 = Files copied OK
REM 1 = No files found to copy
REM 2 = User terminated (Ctrl+C)
REM 4 = Initialization error (insufficient memory, invalid path, etc)
REM 5 = Disk write error
IF ERRORLEVEL 5 GOTO DISK_ERROR
IF ERRORLEVEL 4 GOTO INIT_ERROR
IF ERRORLEVEL 2 GOTO USER_ABORT
IF ERRORLEVEL 1 GOTO NO_FILES
ECHO.
ECHO [OK] Backup completed successfully
ECHO.
ECHO Files backed up to: T:\%MACHINE%\BACKUP
GOTO END
REM ==================================================================
REM ERROR HANDLERS
REM ==================================================================
:BACKUP_DIR_ERROR
ECHO.
ECHO [ERROR] Could not create backup directory
ECHO Target: T:\%MACHINE%\BACKUP
ECHO.
ECHO Check:
ECHO - T: drive is writable
ECHO - Sufficient disk space on T:
ECHO - Network connection is stable
ECHO.
PAUSE Press any key to exit...
GOTO END
:DISK_ERROR
ECHO.
ECHO [ERROR] Disk write error
ECHO.
ECHO Possible causes:
ECHO - Target drive is full
ECHO - Network connection lost
ECHO - Permission denied
ECHO.
PAUSE Press any key to exit...
GOTO END
:INIT_ERROR
ECHO.
ECHO [ERROR] Backup initialization failed
ECHO.
ECHO Possible causes:
ECHO - Insufficient memory
ECHO - Invalid path
ECHO - Target drive not accessible
ECHO.
PAUSE Press any key to exit...
GOTO END
:USER_ABORT
ECHO.
ECHO [WARNING] Backup terminated by user (Ctrl+C)
ECHO.
ECHO Backup may be incomplete!
ECHO.
PAUSE Press any key to exit...
GOTO END
:NO_FILES
ECHO.
ECHO [WARNING] No files found to copy
ECHO.
ECHO This may indicate:
ECHO - All files are already up to date (/D option)
ECHO - Source drive is empty
ECHO.
PAUSE Press any key to exit...
GOTO END
REM ==================================================================
REM CLEANUP AND EXIT
REM ==================================================================
:END
REM Clean up environment variables (DOS has limited space)
SET OLDDRV=