I'm abit stuck with this backup script I have been writing. The goal of the script is to:
Wake-up a sleeping PC on my LAN
Run Microsofts Synctoy(cmd version) to sync all of the paired folders that I have setup and output results to log file.
If there is an error, it should write it to the log file and then send an email to me via the mailsend.exe.
The batch file is set to run every night with Windows 7's Scheduled tasks.
Contents of batch file:
@ECHO OFF
SET /a RETRY=0
SET /a RETRIES=5
SET MAC=000c76******
SET IP=192.168.0.8
SET SUBNET=255.255.255.0
SET PORT=7
ECHO %date% - %time% - Started sync.
:CHECK
PING -n 1 %IP% | find "bytes=">NUL
IF %ERRORLEVEL%==0 (
GOTO SYNC
)
IF %ERRORLEVEL%==1 (
GOTO WAKE
)
:WAKE
SET /a RETRY=%RETRY%+1
IF %RETRY% GEQ 6 (
SET ERR_VAL=RETRY
GOTO ERROR
)
ECHO Waking up \\NAS Attempt %RETRY%\5...
START C:\sync\wolcmd.exe %MAC% %IP% %SUBNET% %PORT%
timeout /T 30 /NOBREAK>NUL
GOTO CHECK
:SYNC
ECHO SyncToy is running...
"C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" -R>C:\sync\synctoy_log.txt
IF %ERRORLEVEL% == 0 (
ECHO %date% - %time% - Success: Sync completed.>>C:\sync\synctoy_error_log.txt
GOTO END
) ELSE (
SET ERR_LEV=%ERRORLEVEL%
SET ERR_VAL=SYNC
GOTO ERROR
)
:ERROR
IF %ERR_VAL%==RETRY (
ECHO Error: Failed to sync, retries exceeded.
ECHO %date% - %time% - Error: Failed to sync, retries exceeded.>>C:\sync\synctoy_error_log.txt
)
IF %ERR_VAL%==SYNC (
ECHO Error: SyncToy error (%ERR_LEV%).
ECHO %date% - %time% - Error: SyncToy error (%ERR_LEV%).>>C:\sync\synctoy_error_log.txt
)
START C:\sync\mailsend.exe -to example.email@googlemail.com -from example.email@gmail.com -ssl -attach synctoy_error_log.txt,text/plain,i -smtp smtp.googlemail.com -port 465 -sub SyncToy_log +cc +bc -v -auth-login -user example.email@gmail.com -pass examplepass
GOTO END
:END
EXIT
Contents of synctoy_error_log.txt
18/02/2013 - 6:02:16.40 - Success: Sync completed.
20/02/2013 - 6:05:25.71 - Success: Sync completed.
21/02/2013 - 6:07:14.27 - Success: Sync completed.
22/02/2013 - 6:02:56.34 - Success: Sync completed.
24/02/2013 - 6:01:49.97 - Success: Sync completed.
25/02/2013 - 6:01:35.14 - Success: Sync completed.
As you can see there has been a couple of days where the log was not written. The PC with the scheduled task running and the PC I want to wake up should have been accesible at this time.
Is there anything that I am doing wrong here in my error checking or something?
I don't get an email saying there was a problem either, but if I disconnect the sleeping PC from the LAN and force the script to start, I do get an email saying it couldn't wake it up.
Thanks for any advice you can give me it's greatly appriciated. I know this isn't the most efficient script, but I've been trying to pick up everything I can to get by.