|
|
|
Knowledge Base
.: Products
.: Shared Issues
.: Batch File Sample for Maintaining a Rotating Backup with IFD/IFW
|
Batch File Sample for Maintaining a Rotating Backup with IFD/IFW
The batch file code below is self-documented. You can use this code by copying it in its entirety, pasting it into a new file using a text editor such as Notepad, and saving the file with the .BAT extension (e.g. ABC.BAT). The batch file begins with the line @echo off and ends with the line :: End of batch script. If you wish to image more than one partition using this batch script, please refer to the section near the bottom titled Using the Batch File for Multiple Partitions. Note: If you receive the error Out of environment space while running this batch file, please see the following Microsoft support article: Out of Environment Space Error Message in MS-DOS Program. @echo off
:: Copyright (C) 2005, TeraByte Unlimited. All rights reserved.
:: This batch file maintains multiple iterations of a particular backup. Each :: time the batch file is run, a backup will be created according to the next :: letter in sequence. For example, the first time the batch file is run, :: <file name>A will be created. On subsequent runs, <file name>B will be used, :: followed by <file name>C, then back to <file name>A, and so on. If a :: <file name>X backup already exists (where X is A, B, or C), it will be :: overwritten automatically. :: :: To keep track of which letter in sequence to use next, the batch file :: creates a file named "LastBkID.X", where X is A, B, or C. This file must :: remain in place for the batch file to work as expected. If no "LastBkID.X" :: file is found, <file name>A will be assumed as the next backup to be created. :: :: If you will be using this batch file with IFD, please note that IMAGE.EXE :: will be expected to reside in the current directory of the DOS environment. :: :: There are three settings you need to specify below (four, if you will be :: using this batch file with IFW). Each one is preceded by the "set" command.
:: ---------------------------------------------------------------------------
:: Specify the directory where backup files will be saved. If using IFD, :: the MS-DOS 8.3 naming convention applies. In all cases, omit the :: trailing backslash, even for root directories (e.g. C: or D:). :: :: Example: set TBIBase=D:\Backups
set TBIBase=
:: Specify the desired backup file name below. If using IFD, the maximum :: length is 7 characters, and no spaces are allowed. In all cases, omit :: the file extension. :: :: Example: set TBIName=Backup
set TBIName=Backup
:: Specify the parameters that should be used by IFD or IFW below. This is :: where you specify the source drive and partition for the backup. :: :: Example: set TBIParms=/c00x10vb
set TBIParms=
:: Specify the path to IMAGEW.EXE, if you will be using this batch file with :: IFW. Omit quotation marks and the trailing backslash. :: :: Example: set TBIPath=C:\Program Files\Image for Windows
set TBIPath=C:\Program Files\Image for Windows
:: ---------------------------------------------------------------------------
set Error=X set Letter1=X set Letter2=X set OpEnv=X
if "%Error%"=="" goto :EnvSpErr if "%Letter1%"=="" goto :EnvSpErr if "%Letter2%"=="" goto :EnvSpErr if "%OpEnv%"=="" goto :EnvSpErr
set OpEnv=Win9x if "%OS%"=="Windows_NT" set OpEnv=WinNT if "%WinDir%"=="" set OpEnv=DOS
if "%TBIBase%"=="" echo No TBIBase parameter supplied. Please edit: %0 if "%TBIBase%"=="" goto :End if "%TBIName%"=="" echo No TBIName parameter supplied. Please edit: %0 if "%TBIName%"=="" goto :End if "%TBIParms%"=="" echo No TBIParms parameter supplied. Please edit: %0 if "%TBIParms%"=="" goto :End
if "%OpEnv%"=="Win9x" goto :Windows if "%OpEnv%"=="WinNT" goto :Windows if "%OpEnv%"=="DOS" goto :DOS
:: ---------------------------------------------------------------------------
:DOS
if not exist image.exe echo Image for DOS (IMAGE.EXE) not found. if not exist image.exe goto :End
for %%x in (A,B,C) do if exist %TBIBase%\LastBkID.%%x set Letter1=%%x del %TBIBase%\LastBkID.%Letter1% if "%Letter1%"=="A" set Letter2=B if "%Letter1%"=="B" set Letter2=C if "%Letter1%"=="C" set Letter2=A if "%Letter1%"=="X" set Letter2=A echo This file is created and required by: %0>%TBIBase%\LastBkID.%Letter2%
echo. echo Now running the following command: echo image.exe %TBIParms% %TBIBase%\%TBIName%%Letter2% image.exe %TBIParms% %TBIBase%\%TBIName%%Letter2%
goto :PostBkup
:: ---------------------------------------------------------------------------
:Windows
if "%TBIPath%"=="" echo No TBIPath parameter supplied. Please edit: %0 if "%TBIPath%"=="" goto :End if not exist "%TBIPath%\imagew.exe" echo Invalid TBIPath parameter supplied. Please edit: %0 if not exist "%TBIPath%\imagew.exe" goto :End
for %%x in (A,B,C) do if exist "%TBIBase%\LastBkID.%%x" set Letter1=%%x del "%TBIBase%\LastBkID.%Letter1%" if "%Letter1%"=="A" set Letter2=B if "%Letter1%"=="B" set Letter2=C if "%Letter1%"=="C" set Letter2=A if "%Letter1%"=="X" set Letter2=A echo This file is created and required by: %0>"%TBIBase%\LastBkID.%Letter2%"
echo. echo Now running the following command: echo "%TBIPath%\imagew.exe" %TBIParms% "%TBIBase%\%TBIName%%Letter2%" if "%OpEnv%"=="Win9x" start /wait "%TBIPath%\imagew.exe" %TBIParms% "%TBIBase%\%TBIName%%Letter2%" if "%OpEnv%"=="WinNT" start "" /wait "%TBIPath%\imagew.exe" %TBIParms% "%TBIBase%\%TBIName%%Letter2%"
goto :PostBkup
:: ---------------------------------------------------------------------------
:PostBkup
if ErrorLevel 1 set Error=1 # if ErrorLevel 2 set Error=2 # if ErrorLevel 3 set Error=3 # if ErrorLevel 4 set Error=4 # if ErrorLevel 5 set Error=5 # if ErrorLevel 6 set Error=6 # if ErrorLevel 7 set Error=7 # if ErrorLevel 8 set Error=8 # if ErrorLevel 9 set Error=9 # if ErrorLevel 11 set Error=11 # if ErrorLevel 12 set Error=12 # if ErrorLevel 13 set Error=13 # if ErrorLevel 17 set Error=17 # if ErrorLevel 18 set Error=18 # if ErrorLevel 60 set Error=60 # if ErrorLevel 61 set Error=61 # if ErrorLevel 62 set Error=62 # if ErrorLevel 63 set Error=63 # if ErrorLevel 64 set Error=64 # if ErrorLevel 65 set Error=65 # if ErrorLevel 66 set Error=66 # if ErrorLevel 67 set Error=67 # if ErrorLevel 68 set Error=68 # if ErrorLevel 200 set Error=200 # if ErrorLevel 201 set Error=201 # if ErrorLevel 202 set Error=202 # if ErrorLevel 203 set Error=203 # if ErrorLevel 204 set Error=204 # echo. echo ######################################### if not "%Error%"=="X" echo # The following error was reported: %Error% if not ErrorLevel 1 echo # No errors were reported. # echo ######################################### echo.
goto :End
:: ---------------------------------------------------------------------------
:EnvSpErr
echo. echo Potential "Out of environment space" condition detected. echo Please refer to the following Microsoft support article: echo http://support.microsoft.com/kb/230205/ echo.
goto :End
:: ---------------------------------------------------------------------------
:End
set Error= set Letter1= set Letter2= set OpEnv= set TBIBase= set TBIName= set TBIParms= set TBIPath=
:: End of batch script Using the Batch File for Multiple PartitionsIf you wish to run this batch file for more than one partition, proceed as follows:
- Configure a copy of the batch file for each partition you wish to
image. Give each batch file a unique name, and save them all in a single
directory.
- Create a new batch file, and add a CALL
statement for each batch file to be run. For example, assuming we
wanted to image two different partitions, and had corresponding batch
files named MAINOS.BAT and DATA.BAT, this new batch file would contain:
@echo off call mainos.bat call data.bat
- Save the new batch file in the same directory as the other batch files, or else fully qualify the paths in your CALL statements:
@echo off
call d:\backups\mainos.bat
call d:\backups\data.bat
- When you want to image the partitions, run this batch file, which will in turn run the others, in succession.
|
Related Articles
User Comments
No comments have been posted.
|
|
|