Jump to content

NTBackup Interactive script


Recommended Posts

Hi Guys,

I've written a couple of scripts to try and tame NTBackup running on Windows Server 2003 (SP2). I have a single SDLT drive attached to my backup server, and the only way I can reliably get NTBackup to perform Normal (Full) backups is to run them interactively. This seems to be because NTBackup (& RSM) was designed to work with tape autoloaders. Therefore when you run a Full NTBackup job as a scheduled task, it fails when the backup requests a second tape.

Having worked through all of the MS recommendations on the relevant KB articles, I decided that I'd try my hand at writing an AutoIt script to help me out.

Please see the following scripts:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.2.0
 Author:         Greg Nottage

 Script Function:
    Automate NTBackup Media Overwrite prompts.

#ce ----------------------------------------------------------------------------

; Script Start

;Set AutoIt options
AutoItSetOption("TrayIconDebug", 1); Show debug info in tray icon
AutoItSetOption("WinTitleMatchMode", 2); 2 = Match any substring in title
AutoItSetOption("TrayIconHide", 0); 0 = do not hide, 1 = hide tray icon

;Run in a permanent loop waiting for conditions to exist
While 1
    
    Select

;Check if the NTBackup media warning message is present
        Case WinExists ("Backup Utility", "There is no free media available")
    ;Pause for half a second
            Sleep(500)
            ControlClick("Backup Utility", "There is no free media available", 6); Click the Yes button

;Check if the NTBackup Replace Data warning message is present
        Case WinExists ("Replace Data", "Warning: All of the data will be replaced")
    ;Pause for half a second
            Sleep(500)
            ControlClick("Replace Data", "Warning: All of the data will be replaced", 6); Click the Yes button

    EndSelect

WEnd

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.2.0
 Author:         Greg Nottage

 Script Function:
    Interactively runs NTBackup and performs a Normal (Full) Backup job

 Usage: requires jobname to be set as a paramater when running the script
    i.e.: NTBackup_Full.au3 "Weekly_Full"

#ce ----------------------------------------------------------------------------

;Script Start

;Set AutoIt options
AutoItSetOption("TrayIconDebug", 1); Show debug info in tray icon
AutoItSetOption("WinTitleMatchMode", 2); 2 = Match any substring in title
AutoItSetOption("TrayIconHide", 0); 0 = do not hide, 1 = hide tray icon

;Set Variables
$NTB =@SystemDir & "\ntbackup.exe"
$JobPath = "C:\Backup Jobs\Full_Backup.bks"
$JobName = $cmdline[1]

;Run NTBackup and start the backup
Run($NTB, "", @SW_MAXIMIZE);Shows NTBackup Maximised
WinWait("Backup Utility -", "Untitled");Pause script until NTBackup window is visible
WinActivate("Backup Utility -", "Untitled"); Ensure the NTBackup window has the focus
Send("^{TAB}"); Sends a Ctrl+TAB to switch to backup tab
WinActivate("Backup Utility -", "Untitled"); Ensure the NTBackup window has the focus
Send("!j"); Open the Job menu
Send("l"); Open the load job dialogue box
WinWait("Open","")
Send($JobPath); Insert the full path to the NTBackup job file
Sleep(500); Pause for half a second
Send("!o"); Click the Open button
WinActivate("Backup Utility -", "Full_Backup.bks"); Ensure the NTBackup window has the focus
Send("!s"); Click the Start Backup button
WinWait("Backup Job Information", "&Start Backup"); Pause script until the Start Backup dialogue appears
ControlSetText("Backup Job Information", "&Start Backup", 4045, $JobName); Set the job description
ControlSetText("Backup Job Information", "&Start Backup", 4044, $JobName); Set the media label
; Ensure backup type is set to Normal (i.e. Full backup of all files)
ControlClick("Backup Job Information", "&Start Backup", 1274); Click the Advanced button
WinWait("Advanced Backup Options", "OK"); Pause script until the Advanced Backup Options dialogue appears
ControlSend("Advanced Backup Options", "OK", 1284, "n"); Ensure Normal job type selected in combobox
ControlClick("Advanced Backup Options", "OK", 1); Click the OK button
ControlClick("Backup Job Information", "&Start Backup", 1); Click the Start Backup button

;Script End

I've compiled them both into standalone exe's. The first script I have running all the time so that it takes care of the NTBackup tape messages whenever they appear. The second script I have setup as a scheduled task that runs only when I'm logged in.

I have a couple of questions regarding improvements to the above scripts. Firstly, is it possible to combine the scripts into one single script? I don't know if you can have the loop running in the background waiting for the NTBackup tape messages whilst the main part of the script runs the backup?

Also, is there a less processor intensive way of performing the loop, rather than a while 1 loop? This seems to demand a lot of processor cycles on my backup server and I wondered if there was a more efficient way of doing it? I had thought about removing the while 1 statement, and then running that script as a scheduled task every so often?

Please let me know if you can suggest some improvements to my scripts and the above solution.

Many thanks,

Greg.

Edited by gregnottage
Link to comment
Share on other sites

@gregnottage

I run this command on an WIN 2003 R02 Server and no problem.

Try to run this script first in a .Bat file before automating it in AU3. See if it works.

start  /wait C:\WINDOWS\system32\NTBACKUP.EXE backup "@C:\Admin\Backup.bks" /n "Full Backup" /d "Full Backup - SRVPLSK03" /v:no /r:no /rs:no /hc:on /m normal /j "Backup" /l:f /p "SDLT" /UM

There is a NOT DOCUMENTED switch you can use called /UM.

This is the statement of Microsoft about it

"Microsoft strongly recommends that you use managed media. Unmanaged media is still supported in Windows Server 2003,

but Microsoft removed the documentation for it from the help file so they must feel pretty strongly about it."

Enjoy !!

ptrex

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...