@echo off
rem a batch script to perform a full/normal backup
rem syneticon GbR
rem Last changed 2003-04-11
rem result from an "rsm view" call:
rem Free Media 14902267A48A4F64A0321999F5B4B7DF
rem +- 4mm DDS A563A5483A8342E3BE5515C73DE4656D
rem Imported Media 194D1B4BDC2D48A9A514DE2BB284BCCF
rem Unrecognized Media 9A0573B536604A3BA98CD92ECB7C6ADF
rem +- 4mm DDS 353A1F180D5F4C549FAC0AA7102B4417
rem Backup 1E2BF9E8F1224027A7E0A664F493FEEF
rem +- 4mm DDS 00545AD84D8D43A08A11E44F33781772
rem +- Inkremental 9F7EBB9D3B16462C97E9E97C9EE972DF
rem +- Full 231A05D4268A4BF08336001B59E907EF
rem result from rsm view /Tlibrary
rem Offline Media 0122057F04EC4D178F1445E405AB115D
rem SAMSUNG CD-ROM SN-124 2322C88AE24B4907AEF4CD803070FA2E
rem ARCHIVE Python 06408-XXX SCSI Sequential Device ADF7B38BB64E4D17BB1DD58255C6268B
rem +- Drive 0 9DF22E179A9248679D88DC72CF441B09
rem set some values first
rem the GUID of our Tape Library / Tape Drive
SET TapeLibGUID=ADF7B38BB64E4D17BB1DD58255C6268B
rem the GUID of the "Free Media\4mm DDS" pool
SET FreeMediaGUID=A563A5483A8342E3BE5515C73DE4656D
rem the GUID of the "Unrecognized Media\4mm DDS" pool
SET UnrecMediaGUID=353A1F180D5F4C549FAC0AA7102B4417
rem the GUID of the "Backup\Incremental" pool
SET IncrementalGUID=9F7EBB9D3B16462C97E9E97C9EE972DF
rem the GUID of the "Backup\Full" pool
SET FullGUID=231A05D4268A4BF08336001B59E907EF
rem The directory which we write our log files to.
SET OurLogDir=C:\Backup
rem the mail address to send status mail to
SET BackupOperator=BackupOperator@syneticon.de
rem full path to the backup selection file
SET BackupSelection=C:\Backup\Backup.bks
rem fetch the actual date and reformat it to yyyy-mm-dd
rem (Be sure to get that changed according to your date format.
rem If you do not live in Europe, you probably will have to change
rem both - the delimeters and the order of the parameters)
FOR /f "tokens=2-4 delims=. " %%i in ('date /t') do SET date=%%k-%%j-%%i
rem Determine the expected / desired name for the media
SET MediaName="Full %date%"
rem set the name of our log file
SET logfile=%OurLogDir%\messages-%date%.log
rem Guess the directory, where NTBACKUP will save its log files
rem It is a subdirectory of LocalAppData
rem Change this to whatever is appropiate to your system
SET BackupLogDir=%userprofile%\Lokale Einstellungen\Anwendungsdaten\Microsoft\Windows NT\NTBACKUP\data
:start
rem force a library refresh
rsm.exe refresh /LG%TapeLibGUID%
rem rem wait for completion
sleep 30
rem determine the name and guid of the media inserted
FOR /F " usebackq delims==" %%i IN (`rsm view /Tphysical_media /CG%TapeLibGUID% /B /GUIDDISPLAY`) DO set medGUID=%%i
FOR /F " usebackq delims==" %%i IN (`rsm view /Tphysical_media /CG%TapeLibGUID% /B`) DO set medName=%%i
echo INFO: Full Backup procedure %date% started >> %logfile%
rem do we have a tape at all?
IF "%medGUID%"=="" GOTO NoMedia
rem is the inserted media part of the "\free media\4mm DDS" pool?
FOR /F " usebackq delims==" %%i IN (`rsm view /Tphysical_media /GUIDDISPLAY /CG%FreeMediaGUID% /B`) DO IF %%i==%medGUID% GOTO Free
rem is it an unrecognized media?
FOR /F " usebackq delims==" %%i IN (`rsm view /Tphysical_media /GUIDDISPLAY /CG%UnrecMediaGUID% /B`) DO IF %%i==%medGUID% GOTO Unrecognized
rem is the inserted media part of the "\backup\incremental" pool?
FOR /F " usebackq delims==" %%i IN (`rsm view /Tphysical_media /GUIDDISPLAY /CG%IncrementalGUID% /B`) DO IF %%i==%medGUID% GOTO Incremental
rem is the inserted media part of the "\backup\full" pool?
FOR /F " usebackq delims==" %%i IN (`rsm view /Tphysical_media /GUIDDISPLAY /CG%FullGUID% /B`) DO IF %%i==%medGUID% GOTO Full
rem if none of the above, handle it appropiately
goto SomeOther
:NoMedia
echo ERROR: No media present in tape drive >> %logfile%
echo ERROR: Backup process aborted, no data was backed up >> %logfile%
goto end
:Free
rem Everything's fine, log and proceed
echo INFO: Media "%medName%" taken from the "Free Media" pool >> %logfile%
goto doBackup
:Unrecognized
rem Everything's fine, although media is unrecognized. Log & proceed
echo INFO: Media "%medName%" taken from the "Unrecognized Media" pool >> %logfile%
goto doBackup
:Full
rem Everything's fine, tape is rotating, log and proceed
echo INFO: Media "%medName%" taken from the "Backup\Full" pool >> %logfile%
goto doBackup
:SomeOther
rem Log that the inserted tape was in the wrong media pool and exit
echo ERROR: The media "%medName%" is already allocated to another pool. >> %logfile%
echo ERROR: Backup process aborted, no data was backed up. >> %logfile%
goto end
:Incremental
rem Log that the inserted tape was in the wrong media pool and exit
echo ERROR: The media "%medName%" is an incremental media. >> %logfile%
echo ERROR: Backup process aborted, no data was backed up. >> %logfile%
goto end
:doBackup
rem start the backup process
echo INFO: backup process starting >> %logfile%
echo INFO: The inserted media "%medName%" is empty or already used for a full backup >> %logfile%
echo INFO: It will be re-initialized as "%MediaName%" >> %logfile%
echo INFO: It will be assigned to the media pool Backup\Full >> %logfile%
start /wait C:\WINNT\system32\NTBACKUP.EXE backup "@%BackupSelection%" /d "Set %date%" /v:yes /r:no /rs:no /hc:on /m normal /j "Full" /l:s /p "Full" /UM
if errorlevel 1 goto backuperror
rem log success
echo INFO: backup process terminated gracefully >> %logfile%
goto endbackup
:backuperror
rem log errors
echo ERROR: backup process has thrown errors, inspect the backup log >> %logfile%
goto endbackup
:endbackup
rem log eject & eject
echo INFO: ejecting media >> %logfile%
rsm eject /PG%medGUID% /ASTART >> %logfile%
goto end
:end
rem determine the log file with the latest change
FOR /F "tokens=*" %%i IN ('dir /B /OD /TW "%BackupLogDir%\*.log"') DO set backuplog=%%i
rem send logfiles to responsible operators
blat %logfile% -to %BackupOperator% -s "%date% backup report (full)" -attacht "%BackupLogDir%\%backuplog%"