Immediate Solutions


Managing NTBackup

The NTBackup utility supports multiple switches for performing backups from the command line. Here is a list of the available switches:

  • /A ”Appends backups

  • /D " label " ”Specifies a backup set label

  • /DS " server " ”Backs up the Microsoft Exchange directory service for the specified server name

  • /F " name " ”Specifies full path and file name of the backup file

  • /G " tapeID " ”Specifies to overwrite or append to the tape based on the specified tape id

  • / HC: x ”Controls hardware compression where x is ON or OFF

  • /IS " server " ”Backs up the Microsoft Exchange information store for the specified server name

  • /J " job " ”Specifies a descriptive job name to record in the log file

  • / L: x ”specifies the type of log file where x is:

    • F ”Complete logging

    • S ”Summary logging

    • N ”No logging

  • /M: x ”Specifies the backup type where x is:

    • copy ”Back up files and do not clear their archive flag

    • daily ”Back up today's changed files and do not clear their archive flag

    • differential ”Back up changed files and do not clear their archive flag

    • incremental ”Back up changed files then clear their archive flag

    • normal ”Back up files then clear their archive flag

    • /N " name " ”Specifies a new name to give the tape

    • /P " name " ”Specifies the name of the media pool to use

    • /R: x ”Restricts tape access to the tape owner or administrators, where x is YES or NO

    • /RS x ”Specifies to back up the removable storage database, where x is YES or NO

    • /T " tapename " ”Specifies to overwrite or append to the tape based on the specified tape name

    • /UM ”Specifies to find and format the find media available

    • /V: x ” Performs backup verification, where x is YES or NO

Running NTBackup with Shell Scripting

To automate a full backup using NTBackup and shell scripting, proceed as follows :

  1. Create a new directory to store all files included in this example.

  2. Select StartRun and enter " scriptfile .bat."

Here, scriptfile is the full path and file name of a script file that contains the following:

 @Echo Off Set  BList  =  folders  Set  BFile  =  backupfile  Set  BComment  =  BackupComment    fullpath  \NTBACKUP.EXE Backup  %BList%  /d "  %BComment%  " /l:F /F "  %BFile%  " /V:YES  Set  BList  = Set  BFile  = Set  BComment  = 
Note  

The highlighted code above must be placed on one line.

Here, folders are the folders to back up; backupfile is the complete path and file name of the backup file to create (typically stored with a BKS extension); BackupComment is the comment to give the backup; and fullpath is the complete path to the NTBackup utility.

Running NTBackup with KiXtart

To automate a full backup using NTBackup and KiXtart, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and extract the latest version of KiXtart, from http://www.kixtart.org, to the new directory.

  3. Select StartRun and enter "kix32 scriptfile ."

Here, scriptfile is the full path of the new directory from step 1 and file name of a script file that contains the following:

 $BList = "  folders  "  $BFile  = "  backupfile  "  $BComment  = "  BackupComment  "   $BCommand  = "  fullpath  \NTBACKUP.EXE Backup  $BList  /d " +   chr(34) + "  $BComment  " + chr(34) + " /l:F /F " +   chr(34) + "  $BFile  " + chr(34) + " /V:YES"  Run  $Bcommand  
Note  

The highlighted code above must be placed on one line. Chr(34) translates the ASCII code character 34 into a quotation mark ("). This is necessary when you are using the Run command with long file names .

Here, folders are the folders to back up; backupfile is the complete path and file name of the backup file to create (typically stored with a BKS extension); BackupComment is the comment to give the backup; and fullpath is the complete path to the NTBackup utility.

Running NTBackup with Windows Script Host

To automate a full backup using NTBackup and Windows Script Host, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and install the latest version of Windows Script Host, from http://www.microsoft.com, to the new directory.

  3. Select StartRun and enter "cscript scriptfile .vbs."

Here, scriptfile is the full path and file name of a script file that contains the following:

 On Error Resume Next Set  Shell  = CreateObject("Wscript.Shell")  BList  = "  folders  "  BFile  = "  backupfile  "  BComment  = "  BackupComment  "  BCommand  = "  fullpath  \NTBACKUP.EXE Backup " & _  BList  & " /d " & chr(34) &  BComment  & chr(34) & _   " /l:F /F " & chr(34) &  BFile  & chr(34) & " /V:YES"  Shell  .Run  BCommand  , 0, TRUE 
Note  

You cannot completely hide the NTBackup process with Windows Script Host.

Here, folders are the folders to back up; backupfile is the complete path and file name of the backup file to create (typically stored with a BKS extension); BackupComment is the comment to give the backup; and fullpath is the complete path to the NTBackup utility.

Backing Up the IIS Metabase Using Windows Script Host

The Internet Information Server Metabase is a database like structure used to store IIS configuration settings. To automate a backup of the IIS metabase using Windows Script Host, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and install the latest version of Windows Script Host, from http://www.microsoft.com, to the new directory.

  3. Select StartRun and enter "cscript scriptfile .vbs."

Here, scriptfile is the full path and file name of a script file that contains the following:

 On Error Resume Next  NextVersion  = &HFFFFFFFF BackupFlags = 0 Set objComputer = GetObject("IIS://" &  ComputerName  )  objComputer  .Backup  backupfile  ,  NextVersion  ,  BackupFlags  

Here, computername is the name of the IIS server and backupfile is the name of the backup file to create.

Restoring the IIS Metabase Using Windows Script Host

To restore the most recent backup of the IIS metabase using Windows Script Host, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and install the latest version of Windows Script Host, from http://www.microsoft.com, to the new directory.

  3. Select StartRun and enter "cscript scriptfile .vbs."

Here, scriptfile is the full path and file name of a script file that contains the following:

 On Error Resume Next  HighestVersion  = &HFFFFFFFE  BackupFlags  = 0 Set  objComputer  = GetObject("IIS://" &  ComputerName  )  objComputer  .Restore  backuplocation, HighestVersion, BackupFlags  

Here, computername is the name of the IIS server and backuplocation is the complete path where the IIS metabase backup is stored.

Controlling Backup Exec from the Command Line

Backup Exec is a complete backup solution from Veritas (http://www.veritas.com) that includes advanced backup functionality, such as virus scanning. The BackupExec executable (BKUPEXEC.EXE) allows you to run a scheduled job from the command line. The basic syntax of BKUPEXEC is as follows:

 BkupExec /J:"  jobname  " 

Here, /J indicates to run BackupExec in command-line mode, and jobname is the name of the scheduled backup job.

Note  

If the BackupExec program is running or the jobname does not exist, the BkupExec command will not work.

Consolidating BackUp Exec Logs

Whenever BackUp Exec performs a task, it records the progress in an individual log file stored in the program's data directory. Call me lazy, but I hate having to go to the server room, log onto multiple servers, and then check the job status. To remotely consolidate these log files to a central Excel spreadsheet (right from your desk), proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and install the latest version of Windows Script Host, from http://www.microsoft.com, to the new directory.

  3. Select StartRun and enter "cscript scriptfile .vbs."

Here, scriptfile is the full path and file name of a script file that contains the following:

 On Error Resume Next Set  FSO  = CreateObject("Scripting.FileSystemObject") Set  objXL  = CreateObject("Excel.Application")  BEPath  = "  logpath  "  Server  = "  servername  "  SDays  = InputBox("Please enter the number of days to report")  SDays  = Int(  SDays  ) - 1  Column  = 1  Row  = 1 SetupXL 'Setup Excel Sheet  BEFolder  = "\" &  Server  & "\" &  BEPath  ChkBkUp  BEFolder  Wscript.Echo "Complete." Wscript.Quit Sub SetupXL 'Setup and format Excel Sheet  objXL  .Workbooks.Add  objXL  .Columns(1).ColumnWidth = 20  objXL  .Columns(2).ColumnWidth = 10  objXL  .Columns(3).ColumnWidth = 15  objXL  .Columns(4).ColumnWidth = 10  objXL  .Columns(5).ColumnWidth = 15  objXL  .Columns(6).ColumnWidth = 10  objXL  .Cells(1,  Column  ).Value = "Server"  objXL  .Cells(1,  Column  +1).Value = "Job"  objXL  .Cells(1,  Column  +2).Value = "Type"  objXL  .Cells(1,  Column  +3).Value = "Start Date"  objXL  .Cells(1,  Column  +4).Value = "Start Time"  objXL  .Cells(1,  Column  +5).Value = "Status"  objXL  .Cells(1,  Column  +6).Value = "Size"  objXL  .Range("A1:K1").Select  objXL  .Selection.Font.Bold = True 'Bold top row  objXL  .Selection.Interior.ColorIndex = 1  objXL  .Selection.Interior.Pattern = 1  objXL  .Selection.Font.ColorIndex = 2 End Sub Sub ChkBkUp(  BEFolder  ) 'Check if log folder exists  If  FSO  .FolderExists(  BEFolder  ) Then     Set  objDirectory  =  FSO  .GetFolder(  BEFolder  )     Set  DirFiles  =  objDirectory  .Files     ExcelSheet(  DirFiles  )   Else     Wscript.echo "Could not access folder: " &  BEFolder  End If End Sub Sub ExcelSheet(DirFiles) 'Enter info to Excel sheet   For Each  objFile  in  DirFiles     objXL  .Visible = True  FEXT  =  FSO  .GetExtensionName(  objFile  .Path)  fDate  = DateDiff("d",  objFile  .DateCreated, Date)     'Check if log date is within the search days specified     If (LCase(  FEXT  ) = "txt") AND ((  fDate  <=  SDays  ) AND _     (  fDate  > 0)) Then  Verify  = 0  strSize  = 0      'Open log and transfer data to Excel sheet      Set  ts  =  FSO  .OpenTextFile(  objFile  , 1)      Do while  ts  .AtEndOfStream <> true  s  =  ts  .ReadLine      If InStr(  s  , "Job server: ") <> 0 Then  Row  =  Row  + 1  objXL  .Cells(  Row  ,  Column  ).Value = Mid(  s  , 13)      ElseIf InStr(  s  , "Job type: ") <> 0 Then  objXL  .Cells(  Row  ,  Column  +1).Value = Mid(  s  , 11)      ElseIf InStr(  s  , "Job name: ") <> 0 Then  objXL  .Cells(  Row  ,  Column  +2).Value = Mid(  s  , 11)      ElseIf InStr(  s  , "Job started: ") <> 0 Then  dTemp  = InStr(  s  , ", ")  tTemp  = InStr(  s  , " at ")  dTemp  =  dTemp  + 2  dEnd  =  tTemp  -  dTemp   objXL  .Cells(  Row  ,  Column  +3).Value = Mid(  s  ,  dTemp  ,  dEnd  )  tTemp  =  tTemp  + 4  objXL  .Cells(  Row  ,  Column  +4).Value = Mid(  s  ,  tTemp  )      ElseIf  S  = "Job Operation - Verify" Then  Verify  = 1      ElseIf (  Verify  = 1) AND _      InStr(  s  , "Processed ") <> 0 Then  myarray  = Split(  s  )       If IsNumeric(  myarray  (1)) Then  strSize  =  strSize  + _         (LEFT((  myarray  (1)/1073741824),6))/1      End If       ElseIf InStr(  s  , "Job completion status: ") <> 0  Verify  = 0  objXL  .Cells(  Row  ,  Column  +6).Value =  strSize        objXL  .Cells(  Row  ,  Column  +5).Value = Mid(  s  , 24)        'If backup failed, bold and highlight red       If LCase(Mid(  s  , 24)) = LCase("Failed") Then  tRange  = "A" &  Row  & ":G" &  Row       objXL  .Range(  tRange  ).Select  objXL  .Selection.Font.Bold = True  objXL  .Selection.Font.ColorIndex = 3      'If backup not successful, bold      ElseIf LCase(Mid(  s  , 24)) <> LCase("Successful") Then  tRange  = "A" & Row & ":G" & Row  objXL  .Range(  tRange  ).Select  objXL  .Selection.Font.Bold = True      End If     End If       Loop  ts  .Close 'Close log file        End If       Next      End Sub 

Here, servername is the name of the server to connect to, and logpath is the administrative share and complete path where the logs are stored (typically c$\Program Files\Veritas\Backup Exec\NT\Data).

Related solution:

Found on page:

Creating Detailed Spreadsheets in Microsoft Excel

103

Controlling ARCserve 2000 from the Command Line

ARCserve 2000 is an advanced backup utility from Computer Associates (http://www.cai.com). ARCbatch, included with ARCserve, is a command-line utility that runs backup script files or templates. The basic syntax of the ARCbatch command is as follows:

 ARCbatch /H=  server  /S=  script  

Here, server is the name of the server to run the specified script . Script is the full name and path to the ARCbatch script or template file. ARCbatch scripts have an ASX extension and are created with the ARCserve manager. ARCbatch templates are INI files you can create to perform or schedule backups and restores . To immediately run a full backup using ARCbatch, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Start a command prompt and enter " fullpath\ ARCbatch H= server /S= template. "

Here, fullpath is the full path to the ARCbatch utility; server is the name of the server to run the specified script ; and template is the full path and file name of a template file that contains the following:

 [GENERAL] HOST=* JOBTYPE=BACKUP JOBDESCRIPTION=  description  [SOURCE_BACKUP] NODE_NUM=1 BKMETHOD=1 VERIFICATION=2 [NODE_1] DOMAINNAME=* NODENAME=$HOST$ NODETYPE=NTAGENT [DESTINATION_BACKUP] TAPENAME=  tape  GROUPNAME=  group  [MEDIA_OPTIONS] FIRSTTAPEOPTIONS=2 

Here, description is the comment to add to the job; tape is the name of the tape; and group is the name of the device group.

Tip  

ARCbatch templates support numerous entries. Visit http://www.cai.com for more information.

Scheduling Tasks with the AT Command

The AT command allows you to schedule tasks from the command line. The basic syntax of the AT command is as follows:

 AT \  remote ID /COMMANDS  "  fullpath  " 
Tip  

To display a list of schedule tasks from the command line, start a command prompt and enter "AT."

Here, remote is an optional name of a remote system of which tasks to control; ID specifies a task ID to modify; fullpath is the complete path and file name of the item to schedule; and the available commands are as follows:

  • /DELETE ”Removes a scheduled job.

  • /YES ”Combined with /DELETE , suppresses all jobs cancellation prompt.

  • /INTERACTIVE ”Sets the job to interact with the desktop. This switch must be set if you want the user to have any interactivity with the scheduled task.

  • / EVERY: x ”Recurrently runs the command on the specified day ( x ).

  • /NEXT: x ”Runs the command on the next specified date ( x ).

To schedule a script file to run at a specified time every work day, start a command prompt and enter the following:

 AT \  remote time  /interactive /every:M,T,W,TH,F  scriptfile  

Here, remote is the name of the system to store the scheduled task; time is the time to run the task; and scriptfile is the full path and name of the script to run.

Tip  

You can use the Windows 2000 Resource Kit Utility WINAT to graphically control and view scheduled tasks.

Creating Tasks Using SCHTASKS

SCHTASKS is a Windows XP/2003 command line utility that allows you to create, delete, or view scheduled tasks. To create a scheduled daily task using SCHTASKS, start a command prompt and enter the following:

 schtasks /create /tn "  taskname  " /tr  fullpath  /sc daily /st  miltime  

Here, taskname is the name of the task to create; fullpath is the full path and file name of the program to execute; and miltime is the time to schedule a task to run (in military format).

Listing Tasks Using SCHTASKS

To list tasks on a remote system using SCHTASKS, start a command prompt and enter the following:

 schtasks /query /s  computer  

Here, computer is the name of the computer to query.

Deleting Tasks Using SCHTASKS

To delete a scheduled task on a remote system using SCHTASKS, start a command prompt and enter the following:

 schtasks /delete /tn "  taskname  " /s  computer  

Here, taskname is the name of the task to delete and computer is the name of the remote system.

Tip  

You can use the /tn * parameter to delete all scheduled tasks.

Creating Tasks with WMI

The Win32_ScheduledJob class allows you to create, delete, or view scheduled tasks. This class is extremely limited in functionality, incorrectly documented, and difficult to work with. There is no method to modify an existing task and there are only a few available parameters when creating a task. This class also only recognizes and can create tasks compatible with the AT command. For whatever reason, to create a scheduled task using WMI, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and install the latest version of Windows Script Host, from http://www.microsoft.com, to the new directory.

  3. Select StartRun and enter "cscript scriptfile .vbs."

Here, scriptfile is the full path and file name of a script file that contains the following:

 On Error Resume Next  DTime  =  MilTime   Set  TZone  = GetObject("winmgmts:{impersonationLevel= impersonate}!\  computer  \root\cimv2").ExecQuery ("select * from Win32_TimeZone")  For each  Zone  in  TZone   TBias  =  Zone  .bias + 60 'Compensates for daylight savings Next  STime  = "********" &  DTime  & "00.000000" &  TBias   Set  ScheduledJob  = GetObject("winmgmts:{impersonationLevel= impersonate}!\  computer  \root\cimv2:Win32_ScheduledJob")  Set  method  = ScheduledJob.Methods_("Create")   Set  inParam  =  method  .inParameters.SpawnInstance_()  inParam  .Command = "  fullpath  "  inParam  .StartTime =  STime     inParam  .RunRepeatedly =  rp     inParam  .DaysOfWeek =  dow  Set  outParam  =  ScheduledJob  .ExecMethod_("Create",  inParam  ) 
Note  

The highlighted code above must be placed on one line.

Here, miltime is the time to schedule a task to run (in military format); fullpath is the full path and file name of the program to execute; rp is a binary entry (0 or 1) that specifies whether to create a reoccurring task; and dow are the days of the week to run the task. Dow does not accept abbreviated day names (M,T,W, ), but must be entered in binary format where the days of the week are as follows:

  • Monday ”1

  • Tuesday ”2

  • Wednesday ”4

  • Thursday ”8

  • Friday ”16

  • Saturday ”32

  • Sunday ”64

To schedule a task to run on a specific day, simply add up the day values and enter the total. For example, to run a task on Tuesday, Friday, and Saturday, you would enter 50 (2+16+32).

Listing Tasks in Internet Explorer Using WMI

The Win32_ScheduledJob class can retrieve and display information on any task previously created using the Win32_ScheduledJob class or AT command. To list these scheduled tasks within a formatted Internet Explorer window, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and install the latest version of WMI and Windows Script Host, from http://www.microsoft.com, to the new directory.

  3. Select StartRun and enter "cscript scriptfile .vbs."

Here, scriptfile is the full path and file name of a script file that contains the following:

 On Error Resume Next Set  FSO  = CreateObject("Scripting.FileSystemObject") Set  MSIE  = CreateObject("InternetExplorer.Application")  Set  ScheduledJob  = GetObject("winmgmts:{impersonationLevel= impersonate}!\  computer  \root\cimv2").ExecQuery("select * from Win32_ScheduledJob")  SetupMSIE  MSIE  .Document.Write "<HTML><TITLE>Scheduled Jobs" & _   "</TITLE><BODY bgcolor=#ffffff><FONT FACE=ARIAL>"  MSIE  .Document.Write "<B>Displaying tasks created " & _   "with WMI or the AT command:</B><BR><BR>" & _   "<table border=0 width=100% cellspacing=0 " & _   "cellpadding=0>"   For each  ejob  in  ScheduledJob  IEWrite "Caption",  EJob  .Caption     IEWrite "Command",  EJob  .Command     IEWrite "Days Of Month",  EJob  .DaysOfMonth     IEWrite "Days Of Week",  EJob  .DaysOfWeek     IEWrite "Description",  EJob  .Description     IEWrite "Install Date" ,  EJob  .InstallDate     IEWrite "Interact With Desktop",  EJob  .InteractWithDesktop     IEWrite "Job ID",  EJob  .JobID     IEWrite "Job Status",  EJob  .JobStatus     IEWrite "Name",  EJob  .Name     IEWrite "Notify",  EJob  .Notify     IEWrite "Owner",  EJob  .Owner     IEWrite "Priority",  EJob  .Priority     IEWrite "Run Repeatedly",  EJob  .RunRepeatedly     IEWrite "Start Time",  EJob  .StartTime     IEWrite "Status",  EJob  .Status     IEWrite "Time Submitted",  EJob  .TimeSubmitted     IEWrite "Until Time",  EJob  .UntilTime     IEWrite " ", " "   Next  MSIE  .Document.Write "</table><BR><B>End of List</B>" & _     "</FONT></BODY>"   Sub SetupMSIE  MSIE  .Navigate "About:Blank"  MSIE  .ToolBar = False  MSIE  .StatusBar = False  MSIE  .Resizable = False     Do     Loop While  MSIE  .Busy  SWidth  =  MSIE  .Document.ParentWindow.Screen.AvailWidth  SHeight  =  MSIE  .Document.ParentWindow.Screen.AvailHeight  MSIE  .Width =  SWidth  /2  MSIE  .Height =  SHeight  /2  MSIE  .Left = (  SWidth  - MSIE.Width)/2  MSIE  .Top = (SHeight - MSIE.Height)/2  MSIE  .Visible = True   End Sub   Sub IEWrite(  Caption,Prop  )  MSIE  .Document.Write "<tr><td>" &  Caption  & "</td>" & _         "<td>&nbsp;</td><td align=right>" &  Prop  & _         "</td></tr>"   End Sub 
Note  

The highlighted code above must be placed on one line.

Here, computer is the name of the computer containing the tasks to list.

Related solution:

Found on page:

Using Microsoft Internet Explorer as a Display Tool

100

Deleting Tasks Using WMI

The Win32_ScheduledJob class can delete any task previously created with the Win32_ScheduledJob class or AT command. To delete all of these scheduled tasks using WMI, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and install the latest version of WMI and Windows Script Host, from http://www.microsoft.com, to the new directory.

  3. Select StartRun and enter "cscript scriptfile .vbs."

Here, scriptfile is the full path and file name of a script file that contains the following:

 On Error Resume Next  Set  ScheduledJob  = GetObject("winmgmts:{impersonationLevel= impersonate}!\  computer  \root\cimv2").ExecQuery ("select * from Win32_ScheduledJob")  For each  ejob  in  ScheduledJob   ejob  .Delete() Next 
Note  

The highlighted code above must be placed on one line.

Here, computer is the name of the computer containing the tasks to delete.




Windows Admin Scripting Little Black Book
Windows Admin Scripting Little Black Book (Little Black Books (Paraglyph Press))
ISBN: 1933097108
EAN: 2147483647
Year: 2004
Pages: 89

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net