Wednesday, March 12, 2014

Backup script for IIS 7.5

1. Copy below script in notepad and save it something like backup-iis.cmd

@echo off
cls

pushd "%WinDir%\System32\inetsrv"

echo.| date | find /i "current">datetime1.tmp
echo.| time | find /i "current">datetime2.tmp

for /f "tokens=1,2,3,4,5,6" %%i in (datetime1.tmp) do (
  echo %%n>datetime1.tmp
)
for /f "tokens=1,2,3,4,5,6" %%i in (datetime2.tmp) do (
  echo %%m>datetime2.tmp
)
for /f "delims=/ tokens=1,2,3" %%i in (datetime1.tmp) do (
  set TMPDATETIME=%%k%%i%%j
)
for /f "delims=:. tokens=1,2,3,4" %%i in (datetime2.tmp) do (
  set TMPDATETIME=D%TMPDATETIME%T%%i%%j%%k%%l
)

appcmd add backups %TMPDATETIME%

del datetime1.tmp
del datetime2.tmp

set TMPDATETIME=

popd
echo.

2. Schedule it using task scheduler.

Source:http://blogs.msdn.com/b/robert_mcmurray/archive/2008/03/08/automating-iis-7-backups.aspx

Task Scheduler - C:\Windows\SYSTEM32\cmd.exe" with return code 255

Task Scheduler successfully completed task "\Run Monthly scipt" . action "C:\Windows\SYSTEM32\cmd.exe" with return code 255

You may face this error when you try to configure scheduled task using domain account. 

Resolution:

Try to run the task using local account preferably 'System'