KB

Ntbackup Script 1

Source: http://www.tek-tips.com/viewthread.c...55160&page=713

@echo off
rem Info from various sources, including Windows & .NET Magazine and Microsoft

set tapeguid=""
set partguid=""
set logguid=""
set t1=""

rem Set the GUID of the tape drive, must be determined manually
rem Use: rsm view /tlibrary /guiddisplay /desc
set drvguid=FA1C9246A009449BB9527E6CA7C9414A

rem Refresh the RSM library
start /wait rsm refresh /lf"Compaq DDS4 20/40 GB DAT Drive"

rem Get the physical GUID of the tape in the drive
FOR /F "usebackq delims==" %%i IN (`rsm view /tphysical_media /cg%drvguid% /guiddisplay /b`) DO set tapeguid=%%i
rem Check to make sure there was a tape in the drive
if %tapeguid%=="" goto notape

rem Get the partition GUID of the tape
FOR /F "usebackq delims==" %%i IN (`rsm view /tpartition /cg%tapeguid% /guiddisplay /b`) DO set partguid=%%i
rem Get the logical media GUID of the partition; needed by NTBackup
FOR /F "usebackq delims==" %%i IN (`rsm view /tlogical_media /cg%partguid% /guiddisplay /b`) DO set logguid=%%i

rem If the tape is new, logguid will contain
rem this string: Unable to view information for all objects.
rem Due to some command-line oddities we take just the first 6 characters of
rem logguid to make the comparison
set t1=%logguid:~0,6%
if /i %t1% neq Unable goto oldtape

:newtape
rem Make sure the tape is in the Free Media pool
start /wait rsm freemedia /lg%drvguid%

rem Start the backup
start /wait %systemroot%\system32\ntbackup.exe backup "@C:\backup\full1.bks" /n "%computername%" /d "daily" /v:no /r:no /rs:no /hc:on /m normal /j "daily" /l:s /p "4mm DDS"

goto backend

:oldtape
rem Format the logical GUID as needed by NTBackup
set p1=%logguid:~0,8%
set p2=%logguid:~8,4%
set p3=%logguid:~12,4%
set p4=%logguid:~16,4%
set p5=%logguid:~20,12%
set bkguid=%p1%-%p2%-%p3%-%p4%-%p5%

rem Start the backup
start /wait %systemroot%\system32\ntbackup.exe backup "@C:\backup\full1.bks" /n "%computername%" /d "daily" /v:no /r:no /rs:no /hc:on /m normal /j "daily" /l:s /g "%bkguid%"

:backend
rem Eject the tape
start /wait rsm eject /PF"%computername% - 1" /astart
goto end1

:notape
echo No tape in the drive

:end1
exit

And the following comment:

One additional thing that helped our servers was adding the SLEEP command after the RSM REFRESH, like this:

rem Refresh the RSM library
start /wait rsm refresh /lf"Compaq DDS4 20/40 GB DAT Drive"
sleep 10

or some server/tape drive combinations prefer

 

rem Refresh the RSM library
start /wait rsm inventory /lf"Compaq DDS4 20/40 GB DAT Drive" /afull
sleep 10

(I'm not sure why on some a refresh will work, whereas on others a full inventory is required.) Since adding that we haven't had a backup failure unless the tape was brand new and not prepared. The SLEEP command is available in the Windows Server 2003 Resource Kit.

This is not original with me. I saw it somewhere in these forums, but have not been able to find the original post; if I could I would give that poster a star.