{"id":276,"date":"2005-12-14T00:49:00","date_gmt":"2005-12-14T08:49:00","guid":{"rendered":"https:\/\/kb.terabyteunlimited.com\/kb-articles\/batch-file-sample-for-maintaining-a-rotating-backup-with-ifd-ifw\/"},"modified":"2021-09-06T23:09:35","modified_gmt":"2021-09-07T06:09:35","slug":"batch-file-sample-for-maintaining-a-rotating-backup-with-ifd-ifw","status":"publish","type":"lsvr_kba","link":"https:\/\/www.terabyteunlimited.com\/kb\/kb-articles\/batch-file-sample-for-maintaining-a-rotating-backup-with-ifd-ifw\/","title":{"rendered":"Batch File Sample for Maintaining a Rotating Backup with IFD\/IFW"},"content":{"rendered":"The batch file code below is self-documented.&nbsp; 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 <strong>.BAT<\/strong> extension (e.g. <strong>ABC.BAT<\/strong>).&nbsp; The batch file begins with the line <strong>@echo off<\/strong> and ends with the line <strong>:: End of batch script<\/strong>.<br \/><br \/>If you wish to image more than one partition using this batch script, please refer to the section near the bottom titled <strong>Using the Batch File for Multiple Partitions<\/strong>.<br \/><br \/><strong><font color=\"#ff0000\">Note:<\/font><\/strong>&nbsp; If you receive the error <strong>Out of environment space<\/strong> while running this batch file, please see the following Microsoft support article:&nbsp; <strong><a href=\"http:\/\/support.microsoft.com\/kb\/230205\/\" target=\"_blank\" rel=\"noopener\">Out of Environment Space Error Message in MS-DOS Program<\/a><\/strong>.<br \/><br \/><font face=\"Courier New\">@echo off<br \/><br \/>:: Copyright (C) 2005, TeraByte Unlimited.&nbsp; All rights reserved.<br \/><br \/>:: This batch file maintains multiple iterations of a particular backup.&nbsp; Each<br \/>:: time the batch file is run, a backup will be created according to the next<br \/>:: letter in sequence.&nbsp; For example, the first time the batch file is run,<br \/>:: &lt;file name&gt;A will be created.&nbsp; On subsequent runs, &lt;file name&gt;B will be used,<br \/>:: followed by &lt;file name&gt;C, then back to &lt;file name&gt;A, and so on.&nbsp; If a<br \/>:: &lt;file name&gt;X backup already exists (where X is A, B, or C), it will be<br \/>:: overwritten automatically.<br \/>::<br \/>:: To keep track of which letter in sequence to use next, the batch file<br \/>:: creates a file named &quot;LastBkID.X&quot;, where X is A, B, or C.&nbsp; This file must<br \/>:: remain in place for the batch file to work as expected.&nbsp; If no &quot;LastBkID.X&quot;<br \/>:: file is found, &lt;file name&gt;A will be assumed as the next backup to be created.<br \/>::<br \/>:: If you will be using this batch file with IFD, please note that IMAGE.EXE<br \/>:: will be expected to reside in the current directory of the DOS environment.<br \/>::<br \/>:: There are three settings you need to specify below (four, if you will be<br \/>:: using this batch file with IFW).&nbsp; Each one is preceded by the &quot;set&quot; command.<br \/><br \/>:: ---------------------------------------------------------------------------<br \/><br \/>:: Specify the directory where backup files will be saved.&nbsp; If using IFD,<br \/>:: the MS-DOS 8.3 naming convention applies.&nbsp; In all cases, omit the<br \/>:: trailing backslash, even for root directories (e.g. C: or D:).<br \/>::<br \/>:: Example: set TBIBase=D:&#92;Backups<br \/><br \/>set TBIBase=<br \/><br \/>:: Specify the desired backup file name below.&nbsp; If using IFD, the maximum<br \/>:: length is 7 characters, and no spaces are allowed.&nbsp; In all cases, omit<br \/>:: the file extension.<br \/>::<br \/>:: Example: set TBIName=Backup<br \/><br \/>set TBIName=Backup<br \/><br \/>:: Specify the parameters that should be used by IFD or IFW below.&nbsp; This is<br \/>:: where you specify the source drive and partition for the backup.<br \/>::<br \/>:: Example: set TBIParms=\/c00x10vb<br \/><br \/>set TBIParms=<br \/><br \/>:: Specify the path to IMAGEW.EXE, if you will be using this batch file with<br \/>:: IFW.&nbsp; Omit quotation marks and the trailing backslash.<br \/>::<br \/>:: Example: set TBIPath=C:&#92;Program Files&#92;Image for Windows<br \/><br \/>set TBIPath=C:&#92;Program Files&#92;Image for Windows<br \/><br \/>:: ---------------------------------------------------------------------------<br \/><br \/>set Error=X<br \/>set Letter1=X<br \/>set Letter2=X<br \/>set OpEnv=X<br \/><br \/>if &quot;%Error%&quot;==&quot;&quot;&nbsp;&nbsp; goto :EnvSpErr<br \/>if &quot;%Letter1%&quot;==&quot;&quot; goto :EnvSpErr<br \/>if &quot;%Letter2%&quot;==&quot;&quot; goto :EnvSpErr<br \/>if &quot;%OpEnv%&quot;==&quot;&quot;&nbsp;&nbsp; goto :EnvSpErr<br \/><br \/>set OpEnv=Win9x<br \/>if &quot;%OS%&quot;==&quot;Windows_NT&quot; set OpEnv=WinNT<br \/>if &quot;%WinDir%&quot;==&quot;&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set OpEnv=DOS<br \/><br \/>if &quot;%TBIBase%&quot;==&quot;&quot;&nbsp; echo No TBIBase parameter supplied.&nbsp; Please edit: %0<br \/>if &quot;%TBIBase%&quot;==&quot;&quot;&nbsp; goto :End<br \/>if &quot;%TBIName%&quot;==&quot;&quot; echo No TBIName parameter supplied.&nbsp; Please edit: %0<br \/>if &quot;%TBIName%&quot;==&quot;&quot; goto :End<br \/>if &quot;%TBIParms%&quot;==&quot;&quot; echo No TBIParms parameter supplied.&nbsp; Please edit: %0<br \/>if &quot;%TBIParms%&quot;==&quot;&quot; goto :End<br \/><br \/>if &quot;%OpEnv%&quot;==&quot;Win9x&quot; goto :Windows<br \/>if &quot;%OpEnv%&quot;==&quot;WinNT&quot; goto :Windows<br \/>if &quot;%OpEnv%&quot;==&quot;DOS&quot;&nbsp;&nbsp; goto :DOS<br \/><br \/>:: ---------------------------------------------------------------------------<br \/><br \/>:DOS<br \/><br \/>if not exist image.exe echo Image for DOS (IMAGE.EXE) not found.<br \/>if not exist image.exe goto :End<br \/><br \/>for %%x in (A,B,C) do if exist %TBIBase%&#92;LastBkID.%%x set Letter1=%%x<br \/>del %TBIBase%&#92;LastBkID.%Letter1%<br \/>if &quot;%Letter1%&quot;==&quot;A&quot; set Letter2=B<br \/>if &quot;%Letter1%&quot;==&quot;B&quot; set Letter2=C<br \/>if &quot;%Letter1%&quot;==&quot;C&quot; set Letter2=A<br \/>if &quot;%Letter1%&quot;==&quot;X&quot; set Letter2=A<br \/>echo This file is created and required by: %0&gt;%TBIBase%&#92;LastBkID.%Letter2%<br \/><br \/>echo.<br \/>echo Now running the following command:<br \/>echo image.exe %TBIParms% %TBIBase%&#92;%TBIName%%Letter2%<br \/>image.exe %TBIParms% %TBIBase%&#92;%TBIName%%Letter2%<br \/><br \/>goto :PostBkup<br \/><br \/>:: ---------------------------------------------------------------------------<br \/><br \/>:Windows<br \/><br \/>if &quot;%TBIPath%&quot;==&quot;&quot; echo No TBIPath parameter supplied.&nbsp; Please edit: %0<br \/>if &quot;%TBIPath%&quot;==&quot;&quot; goto :End<br \/>if not exist &quot;%TBIPath%&#92;imagew.exe&quot; echo Invalid TBIPath parameter supplied.&nbsp; Please edit: %0<br \/>if not exist &quot;%TBIPath%&#92;imagew.exe&quot; goto :End<br \/><br \/>for %%x in (A,B,C) do if exist &quot;%TBIBase%&#92;LastBkID.%%x&quot; set Letter1=%%x<br \/>del &quot;%TBIBase%&#92;LastBkID.%Letter1%&quot;<br \/>if &quot;%Letter1%&quot;==&quot;A&quot; set Letter2=B<br \/>if &quot;%Letter1%&quot;==&quot;B&quot; set Letter2=C<br \/>if &quot;%Letter1%&quot;==&quot;C&quot; set Letter2=A<br \/>if &quot;%Letter1%&quot;==&quot;X&quot; set Letter2=A<br \/>echo This file is created and required by: %0&gt;&quot;%TBIBase%&#92;LastBkID.%Letter2%&quot;<br \/><br \/>echo.<br \/>echo Now running the following command:<br \/>echo &quot;%TBIPath%&#92;imagew.exe&quot; %TBIParms% &quot;%TBIBase%&#92;%TBIName%%Letter2%&quot;<br \/>if &quot;%OpEnv%&quot;==&quot;Win9x&quot; start \/wait &quot;%TBIPath%&#92;imagew.exe&quot; %TBIParms% &quot;%TBIBase%&#92;%TBIName%%Letter2%&quot;<br \/>if &quot;%OpEnv%&quot;==&quot;WinNT&quot; start &quot;&quot; \/wait &quot;%TBIPath%&#92;imagew.exe&quot; %TBIParms% &quot;%TBIBase%&#92;%TBIName%%Letter2%&quot;<br \/><br \/>goto :PostBkup<br \/><br \/>:: ---------------------------------------------------------------------------<br \/><br \/>:PostBkup<br \/><br \/>if ErrorLevel&nbsp;&nbsp; 1 set Error=1&nbsp;&nbsp; #<br \/>if ErrorLevel&nbsp;&nbsp; 2 set Error=2&nbsp;&nbsp; #<br \/>if ErrorLevel&nbsp;&nbsp; 3 set Error=3&nbsp;&nbsp; #<br \/>if ErrorLevel&nbsp;&nbsp; 4 set Error=4&nbsp;&nbsp; #<br \/>if ErrorLevel&nbsp;&nbsp; 5 set Error=5&nbsp;&nbsp; #<br \/>if ErrorLevel&nbsp;&nbsp; 6 set Error=6&nbsp;&nbsp; #<br \/>if ErrorLevel&nbsp;&nbsp; 7 set Error=7&nbsp;&nbsp; #<br \/>if ErrorLevel&nbsp;&nbsp; 8 set Error=8&nbsp;&nbsp; #<br \/>if ErrorLevel&nbsp;&nbsp; 9 set Error=9&nbsp;&nbsp; #<br \/>if ErrorLevel&nbsp; 11 set Error=11&nbsp; #<br \/>if ErrorLevel&nbsp; 12 set Error=12&nbsp; #<br \/>if ErrorLevel&nbsp; 13 set Error=13&nbsp; #<br \/>if ErrorLevel&nbsp; 17 set Error=17&nbsp; #<br \/>if ErrorLevel&nbsp; 18 set Error=18&nbsp; #<br \/>if ErrorLevel&nbsp; 60 set Error=60&nbsp; #<br \/>if ErrorLevel&nbsp; 61 set Error=61&nbsp; #<br \/>if ErrorLevel&nbsp; 62 set Error=62&nbsp; #<br \/>if ErrorLevel&nbsp; 63 set Error=63&nbsp; #<br \/>if ErrorLevel&nbsp; 64 set Error=64&nbsp; #<br \/>if ErrorLevel&nbsp; 65 set Error=65&nbsp; #<br \/>if ErrorLevel&nbsp; 66 set Error=66&nbsp; #<br \/>if ErrorLevel&nbsp; 67 set Error=67&nbsp; #<br \/>if ErrorLevel&nbsp; 68 set Error=68&nbsp; #<br \/>if ErrorLevel 200 set Error=200 #<br \/>if ErrorLevel 201 set Error=201 #<br \/>if ErrorLevel 202 set Error=202 #<br \/>if ErrorLevel 203 set Error=203 #<br \/>if ErrorLevel 204 set Error=204 #<br \/>echo.<br \/>echo #########################################<br \/>if not &quot;%Error%&quot;==&quot;X&quot; echo # The following error was reported: %Error%<br \/>if not ErrorLevel 1 echo # No errors were reported.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #<br \/>echo #########################################<br \/>echo.<br \/><br \/>goto :End<br \/><br \/>:: ---------------------------------------------------------------------------<br \/><br \/>:EnvSpErr<br \/><br \/>echo.<br \/>echo Potential &quot;Out of environment space&quot; condition detected.<br \/>echo Please refer to the following Microsoft support article:<br \/>echo http:\/\/support.microsoft.com\/kb\/230205\/<br \/>echo.<br \/><br \/>goto :End<br \/><br \/>:: ---------------------------------------------------------------------------<br \/><br \/>:End<br \/><br \/>set Error=<br \/>set Letter1=<br \/>set Letter2=<br \/>set OpEnv=<br \/>set TBIBase=<br \/>set TBIName=<br \/>set TBIParms=<br \/>set TBIPath=<br \/><br \/>:: End of batch script<br \/><\/font><br \/><strong>Using the Batch File for Multiple Partitions<\/strong><br \/><br \/>If you wish to run this batch file for more than one partition, proceed as follows:<br \/>\r\n  <ol>\r\n    <li>Configure a copy of the batch file for each partition you wish to image.&nbsp; Give each batch file a unique name, and save them all in a single directory.<br \/><br \/><\/li>\r\n    <li>Create a new batch file, and add a <font face=\"Courier New\">CALL<\/font> statement for each batch file to be run.&nbsp; For example, assuming we wanted to image two different partitions, and had corresponding batch files named <font face=\"Courier New\">MAINOS.BAT<\/font> and <font face=\"Courier New\">DATA.BAT<\/font>, this new batch file would contain:<br \/>\r\n      <blockquote><font face=\"Courier New\">@echo off<\/font><br \/><font face=\"Courier New\">call mainos.bat<\/font><br \/><font face=\"Courier New\">call data.bat<\/font><br \/><\/blockquote>\r\n    <\/li>\r\n    <li>Save the new batch file in the same directory as the other batch files, or else fully qualify the paths in your <font face=\"Courier New\">CALL<\/font> statements:<br \/>\r\n      <blockquote><font face=\"Courier New\">@echo off<\/font><br \/><font face=\"Courier New\">call d:&#92;backups&#92;mainos.bat<\/font><br \/><font face=\"Courier New\">call d:&#92;backups&#92;data.bat<\/font><br \/><\/blockquote>\r\n    <\/li>\r\n    <li>When you want to image the partitions, run this batch file, which will in turn run the others, in succession.<\/li>\r\n  <\/ol>","protected":false},"excerpt":{"rendered":"<p>The batch file code below is self-documented.&nbsp; 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).&nbsp; The batch file begins with the line @echo off and ends with the line [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"lsvr_kba_cat":[1818],"lsvr_kba_tag":[2118],"class_list":["post-276","lsvr_kba","type-lsvr_kba","status-publish","hentry","lsvr_kba_cat-ifd-ifl-ifw-version-1-archive","lsvr_kba_tag-archived"],"_links":{"self":[{"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba\/276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba"}],"about":[{"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/types\/lsvr_kba"}],"author":[{"embeddable":true,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/comments?post=276"}],"version-history":[{"count":1,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba\/276\/revisions"}],"predecessor-version":[{"id":5975,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba\/276\/revisions\/5975"}],"wp:attachment":[{"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/media?parent=276"}],"wp:term":[{"taxonomy":"lsvr_kba_cat","embeddable":true,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba_cat?post=276"},{"taxonomy":"lsvr_kba_tag","embeddable":true,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba_tag?post=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}