As this script was lost when one of the hamsters went terminal, I have reposted....
The below batch script, put in to Scheduled Tasks to run daily does the following:Checks if remote PC is on
If not sends WOL packet to turn on
Then checks to see if it has powered up (If not assumes it is not connected to home network and exits)
If it has then runs back up and creates log file
Then sends shutdown request, giving 25 seconds notice and option to cancel in case someone has started using it
If remote PC already on, it just runs the backup and logging and does nothing after.
Using the below free software:Sync Toy 2.1 - Microsoft Powertoys
WOL.exe - Gammadyne Corporation
psshutdown.exe - Microsoft Resource Kit
CHANGED: The new version of SyncToy now allows setting up the Sync job via a script, so I have added that change below, if the job already exists then it ignores it, so you don't need to check. Also check the SyncToy documentation for more info on different types of sync (I'm using "echo" below, which mirrors changes in one direction and is the safest option providing you only update the files in one location.)
Everything below with REM in front is a comment for those less familiar with batch files (also name the file backup.bat or similar)
echo off
cls
echo ===================================================
echo Checking Black Media Center Power Status...
echo ===================================================
echo.
REM Ping to see if it is on, if not then turn on using MAC address
ping -n 1 -w 5000 black > nul
if errorlevel 1 goto TURNON
goto ISON
:TURNON
cls
echo.
echo ===================================================
echo Black is not ON, trying to power up...
echo ===================================================
echo.
wol.exe 001FC620ABFA
REM Wait 120 seconds to allow Black to finish loading and settle workaround
ping 1.1.1.1 /n 1 /w 200000 > NUL
REM Is Black on? If not report failure (i.e. if laptop is not connected to home network)
ping -n 1 -w 5000 black > nul
if errorlevel 1 goto BIGFAIL
cls
echo.
echo ===================================================
echo Black is ON, Running Sync...
echo ===================================================
echo.
REM Put time and results in log file
echo Backup last run: > e:\MyDocs\lastbackuplog.txt
echo %date% %time% >> e:\MyDocs\lastbackuplog.txt
echo Result: >> e:\MyDocs\lastbackuplog.txt
"C:\Program Files\SyncToy 2.1\SyncToy.exe" -d(left=e:\MyDocs,right="\\black\Backup$\MyDocs",name="MyDocs",operation=echo)
"C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" -R "My Docs"
cls
echo.
echo ===================================================
echo Sync Complete, Powering Off...
echo ===================================================
echo.
REM Send shutdown command, give 25 seconds notice on the remote PC and option to cancel, incase someone has started using it.
psshutdown \\black -u Administrator -p passwordgoeshere -c -s -t 25 -m "Another user has requested that this machine shutsdown, press Cancel to stop."
echo.
goto END
:ISON
cls
echo.
echo ===================================================
echo Black is already ON, Running Sync...
echo ===================================================
echo.
REM Put time and results in log file
echo Backup last run: > e:\MyDocs\lastbackuplog.txt
echo %date% %time% >> e:\MyDocs\lastbackuplog.txt
echo Result: >> e:\MyDocs\lastbackuplog.txt
"C:\Program Files\SyncToy 2.1\SyncToy.exe" -d(left=e:\MyDocs,right="\\black\Backup$\MyDocs",name="MyDocs",operation=echo)
"C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" -R "My Docs"
cls
echo.
echo ===================================================
echo Sync Complete, Leaving Blacks power ON...
echo ===================================================
echo.
goto END
:BIGFAIL
cls
echo.
echo ===================================================
echo Could not find Black on the network...
echo ===================================================
echo.
goto END
:END
REM Insert pause here if you want the window to remain open with the result