?
Solved

Create ScheduleTasks for SystemStateData backup on remote servers

Posted on 2011-09-22
9
Medium Priority
?
400 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

752 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