Untitled

Anonymous
Plain Text
10/27/2025 2:33 PM
2.2 KB
14
Indexable
Never
@echo off
:: ==================================================================
::  Mirror Script - Safe Incremental Backup using Robocopy
::  Source:      D:\Documents
::  Destination: \\DST\Backup\script_test
::  Author:      N/A
:: ==================================================================

:: === Configuration ===
set SRC=D:\Documents
set DST=\\DST\Backup\script_test
set LOGDIR=D:\mirror_documents\logs
if not exist "%LOGDIR%" mkdir "%LOGDIR%"

:: Create a dated and timed log file (e.g., mirror_2025-10-27_13-45.log)
set LOGFILE=%LOGDIR%\mirror_%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%_%TIME:~0,2%-%TIME:~3,2%.log

echo =============================================================== >> "%LOGFILE%"
echo Backup started at %DATE% %TIME% >> "%LOGFILE%"
echo =============================================================== >> "%LOGFILE%"

:: === Robocopy Options ===
:: /MIR      - Mirror source to destination (add/remove to match)
:: /COPY:DAT - Copy Data, Attributes, Timestamps (NOT permissions)
:: /DCOPY:T  - Preserve directory timestamps
:: /R:3      - Retry 3 times on failed copies
:: /W:5      - Wait 5 seconds between retries
:: /MT:16    - Multithreaded copy (adjust threads for load)
:: /TEE      - Show output on screen and log simultaneously
:: /LOG+:    - Append to the log file
:: /NP       - No progress percentages (reduces log size)
:: /NFL /NDL - No file/folder listing (optional – cleaner log)

robocopy "%SRC%" "%DST%" /MIR /COPY:DAT /DCOPY:T /R:3 /W:5 /MT:16 /TEE /LOG+:"%LOGFILE%"

:: === Post Summary ===
echo. >> "%LOGFILE%"
echo =============================================================== >> "%LOGFILE%"
echo Backup completed at %DATE% %TIME% >> "%LOGFILE%"
echo =============================================================== >> "%LOGFILE%"
echo. >> "%LOGFILE%"

:: Optional: summarize results (extract key info)
for /f "tokens=*" %%i in ('findstr /c:"Files :" "%LOGFILE%"') do echo %%i
for /f "tokens=*" %%i in ('findstr /c:"Dirs :" "%LOGFILE%"') do echo %%i
for /f "tokens=*" %%i in ('findstr /c:"Bytes :" "%LOGFILE%"') do echo %%i
for /f "tokens=*" %%i in ('findstr /c:"Times :" "%LOGFILE%"') do echo %%i

echo Log saved to: %LOGFILE%
exit /b 0
Editor is loading...
Leave a Comment