Skip to content

Instantly share code, notes, and snippets.

@martok
Created April 17, 2017 22:05
Show Gist options
  • Save martok/b9f0121c4a741978105971071934045e to your computer and use it in GitHub Desktop.
Save martok/b9f0121c4a741978105971071934045e to your computer and use it in GitHub Desktop.
Sync/Backup script based on Robocopy
@echo off
setlocal
echo ************************************************
echo **** Martok's Syncrotron ****
echo ************************************************
echo **** 1: Copy from this machine to exHDD ****
echo **** 2: Copy from exHDD to this machine ****
echo **** anything else: exit ****
echo ************************************************
set /p select="Choose option: "
set action=
if "%select%"=="1" set action=from
if "%select%"=="2" set action=to
if "%action%"=="" goto :error_noaction
set logfile=.\syncrotron_%COMPUTERNAME%_%action%.log
set cfgpath=.\%COMPUTERNAME%\%action%\
if not exist %cfgpath%*.rcj goto :error_nojobs
if exist %logfile% del %logfile%
echo Action: copy %action% this machine
echo Press any key to continue...
pause > nul
for /F "usebackq delims=" %%f in (`dir /ON /B "%cfgpath%*.rcj"`) do robocopy /job:defaults "/job:%cfgpath%%%f" /TEE /LOG+:%logfile%
echo Done.
pause > nul
goto :eof
:error_noaction
echo No (valid) action specified, exiting.
goto :eof
:error_nojobs
echo No job files found in %cfgpath%, exiting.
:eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment