Solved

Create ScheduleTasks for SystemStateData backup on remote servers

Posted on 2011-09-22
9
394 Views
Last Modified: 2012-08-13
I have a simple batch file [named SSDBackup.bat which will execute System State Data backup of the server and overwrite it. Now I need a Script or Batch file which I can use to copy this batch file to C:\AdminTasks of remote servers and create a schedule task Called "SystemStateData_Backup" to run at 03:30 AM Daily.
0
Comment
Question by:getazhar
  • 5
  • 4
9 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 36581197
Create a list of those servers, called Computers.txt, then run the following
@echo off
for /f %%a in (C:\Computers.txt) do call :process %%a
goto :eof

:process
set srv=%1
if not exist \\%srv%\c$\AdminTasks md \\%srv%\c$\AdminTasks
copy C:\MyBatFile.bat  \\%srv%\c$\AdminTasks\ /y
schtasks /create /ru system /sc daily /st 03:30:00 /tn SystemStateData_Backup /tr "cmd /c C:\AdminTasks\MyBatFile.bat"

Open in new window

0
 

Author Comment

by:getazhar
ID: 36581392
Can you add error handling & output redirecting to check whether script has executed successfully or not ?
0
 

Author Comment

by:getazhar
ID: 36715558
copying part is working fine.. I think there is something needs to be corrected on below line.

schtasks /create /ru system /sc daily /st 03:30:00 /tn SystemStateData_Backup /tr "cmd /c C:\AdminTasks\MyBatFile.bat"

it's creating the task local server from where i am executing this batch file.. I have modified it as below but still not creating the schedule task on remote servers.

schtasks /s %srv% /create /ru system /sc daily /st 03:30:00 /tn SystemStateData_Backup /tr "cmd /c C:\AdminTasks\MyBatFile.bat"
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 67

Expert Comment

by:sirbounty
ID: 36717002
getazhar, try preceeding the %srv% with \\

schtasks /s \\%srv% /create /ru system /sc daily /st 03:30:00 /tn SystemStateData_Backup /tr "cmd /c C:\AdminTasks\MyBatFile.bat"
0
 

Author Comment

by:getazhar
ID: 36717034
I tried.. but failed.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 36717722
Try this version - let me know the output.  If the script pauses, there should be at least some sort of determination presented as to why...
Are you a domain admin on the target devices?
@echo off
for /f %%a in (C:\Computers.txt) do call :process %%a
goto :eof

:process
set srv=%1
echo.  Processing %srv%
if not exist \\%srv%\c$\AdminTasks md \\%srv%\c$\AdminTasks
if exist \\%srv%\c$\AdminTasks (
  echo. AdminTasks exists on %srv%
) else (
  echo. AdminTasks not present on %srv%
  pause
)
copy C:\MyBatFile.bat  \\%srv%\c$\AdminTasks\ /y
if exist \\%srv%\c$\AdminTasks\MyBatFile.Bat (
  echo. MyBatFile.bat created on %srv%
) else (
  echo.  MyBatFile.bat not found on %srv%
  pause
)

schtasks /create /s \\%srv% /ru system /sc daily /st 03:30:00 /tn SystemState_Backup /tr "cmd /c C:\AdminTasks\MyBatFile.bat"
if exist \\%srv%\Admin$\Tasks\SystemState_Backup.job (
  echo.  SystemState Backup scheduled on %srv%
) else (
  echo.  SystemState Backup not scheduled on %srv%
  pause
)

Open in new window

0
 

Author Comment

by:getazhar
ID: 36814960
Works great but only thing pending is Error handling... if you could redirect the Successfully copied file & Created the task to an output.txt would be great.. and of course it should echo the server name where it has failed or successful to copy and to create the schedule task.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 36815403
This should do it.
@echo off
for /f %%a in (C:\Computers.txt) do call :process %%a
goto :eof

:process
set srv=%1
echo.  Processing %srv% >> output.txt
if not exist \\%srv%\c$\AdminTasks md \\%srv%\c$\AdminTasks
if exist \\%srv%\c$\AdminTasks (
  echo. AdminTasks exists on %srv% >> output.txt
) else (
  echo. AdminTasks not present on %srv% >> output.txt
)
copy C:\MyBatFile.bat  \\%srv%\c$\AdminTasks\ /y
if exist \\%srv%\c$\AdminTasks\MyBatFile.Bat (
  echo. MyBatFile.bat created on %srv% >> output.txt
) else (
  echo.  MyBatFile.bat not found on %srv% >> output.txt
)

schtasks /create /s \\%srv% /ru system /sc daily /st 03:30:00 /tn SystemState_Backup /tr "cmd /c C:\AdminTasks\MyBatFile.bat"
if exist \\%srv%\Admin$\Tasks\SystemState_Backup.job (
  echo.  SystemState Backup scheduled on %srv% >>output.txt
) else (
  echo.  SystemState Backup not scheduled on %srv% >> output.txt
)
echo. >> output.txt

Open in new window

0
 

Author Closing Comment

by:getazhar
ID: 37005230
Good Solution..
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question