| By product |
| Other |
|
Knowledgebase Tips and How-to Articles for ApexSQL Tools How to schedule CLI command execution with Windows Scheduler Description This article describes how to create Windows batches (.bat files) that enable scheduling ApexSQL product tasks to run unattended, overnight, etc Solution The following steps describe creating a Scheduled Task in Windows XP In this example, a task to run Monday through Friday at 2:00 AM is scheduled 1. Create a batch (*.bat) file containing the ApexSQL CLI command For example: CODE: APEXSQLPRODUCT.COM /S:TESTSERVER /D:TESTDB / SQL:<FULL PATH>\RESULT.SQL /EXCLUDE_SYSTEM_TABLES /VERBOSE Save this statement as a batch file (.bat) 2. Open Scheduled Tasks in the Windows Control Panel 3. Click Add Scheduled Task 4. Click Next in the first wizard step 5. Click Browse in the next step ![]() 6. Browse to the batch file created in step #1 and select it 7. Specify scheduled task name and set to perform this task daily ![]() Click Next 8. In the next step, set the start time and set task to be performed on weekdays ![]() Click Next 9. Enter the user name and password for the user that will execute the scheduled task ![]() Click Next 10. Check Open advanced properties for this task when I click Finish and click Finish ![]() 11. Review the task settings and verify The following steps describe creating a Scheduled Task in Windows 7, Windows Vista, Windows Server 2008 and Windows Server 2008 R2 In this example, a task is scheduled to run daily at 11:59:00 PM 1. Create a batch (*.bat) file containing the ApexSQL CLI command For example: apexsqllog.com /S:DELL\SQL2008 /D:AdvewntureWorks2008 /SQL D:\backup\RESULT_%date:~10,4%-%date:~4,2%-%date:~7,2%.sql /EXCLUDE_SYSTEM_TABLES Save this statement as a batch file (.bat) The file name specified as RESULT_%date:~10,4%-%date:~4,2%-%date:~7,2%.sql will create a file named RESULT_<YY-MM-DD> (e.g. RESULT_2010-11-15.sql) In case the task is run several times a day, use the time stamp for the file name, too. Instead of RESULT_%date:~10,4%-%date:~4,2%-%date:~7,2%.sql use the following for the file name: RESULT_%date:~10,4%-%date:~4,2%-%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.sql The file created will be named RESULT_<YY-MM-DD_HHMMSS> (e.g. RESULT_2010-11-25_194923.sql) 2. In the Windows Control Panel, open Administrative Tools, Task Scheduler 3. Click Create Basic Task or Create Task ![]() 4. Enter the task name and description ![]() Click Next 5. Select the task trigger ![]() Click Next 6. Set the task starting time and reoccurrence ![]() Click Next 7. Select Start a program ![]() Click Next 8. Select a batch file to run and specify the ApexSQL product installation folder to start the program in ![]() Click Next 9. Select Open the Properties dialog for this task when I click Finish ![]() Click Finish 10. The Task Summary, General tab is opened Please note that the account used needs enough SQL Server privileges as well as the Write permission on the folder where the script will be saved. If your account doesn’t have the necessary privileges, the task will fail. To curtail this problem change the User or Group under which the task will be run To ensure that the task will complete properly, make sure that Run with highest privileges option is selected Also, select Run whether user is logged on or not so the task will be executed even if the user selected to execute it is not logged on ![]() If the batch file will be executed against a database on a remote server, the Task must be configured for the remote server Operating System 11. In the Conditions tab, select Wake the computer to run this task, if the computer is configured to sleep after some period of inactivity Click OK to close the Task properties Last updated November 24, 2011 Labels: General |




















