Incremental Rotate based on count for V3

User discussion and information resource forum for scripting of TeraByte products using script lanugages such as TBScript, VBScript, Batch Files, and more.
Post Reply
Panagiotis
Posts: 40
Joined: Fri Mar 02, 2012 8:28 pm

Incremental Rotate based on count for V3

Post by Panagiotis »

Bellow is an updated version of my previous script for v3 (works fine with v2 also).
The first one is registry based = finds the name of the image to use as base from the registry
The second one is based:
- on the timestamps of the full,incrementals and will always use the latest created image as its base.
- or on a txt file if you also define the additional settings
set TBIBasetxt=
set TBINametxt=
if those are defined it has the same functionality with the registry based script but instead of using the registry it uses the txt


Registry Based for x86

[code]
@echo off

:: Copyright (C) 2011-2012, TeraByte Unlimited. All rights reserved.
:: version 1.2

:: This batch file maintains multiple iterations of a particular backup. Each
:: time the batch file is run, a backup will be created. The filename will
:: include the date and time. For example, the first time the batch file is run,
:: <file name>_2010-04-18-2315__FULL.tbi will be created. On the next run,
:: <file name>_2010-04-19-2315__FULL.tbi will be created. (Assuming it's run the
:: next day at the same time.) Once the number of backups reaches the number
:: specified, the oldest backup (or backup set) is deleted.
::
::
:: There are several settings you need to specify below.
:: Each one is preceded by the "set" command.

:: ---------------------------------------------------------------------------

:: Specify the folder where backup files will be saved. In all cases, omit the
:: trailing backslash, even for root directories (e.g. C: or D:). Folder
:: path can include spaces.
::
:: A UNC path can also be specified for this variable. NOTE: Make sure the share
:: is accessible or IFWRotate and/or Image for Windows may not function as expected.
:: If necessary, use the TBILogin variable below to specify the network share
:: login details. If IFWRotate cannot access the path it will be unable to count the
:: previous image backups, which will result in only Full images being created and
:: no images being deleted. In this case, it may be necessary to add credentials
:: for the share to the user account running IFWRotate.
::
:: Example: set TBIBase=D:\My Backups
::
:: Example: set TBIBase=\\server\backups\mybackups

set TBIBase=



:: Specify the desired backup filename below. In all cases, omit
:: the file extension. Filename can include spaces. This is the "base"
:: filename used for creating the Full and Incremental filenames.
::
:: Backup images will have the same "base" name as the specified TBIName value
:: with the date, time, and "__FULL" appended (for Full images) or "__INCR_", date,
:: and time appended (for Incremental images).
::
:: Created Full image filename example: WorkComputer_2010-04-20-1754__FULL.tbi
::
:: Created Incremental image filename example: WorkComputer_2010-04-20-1754__INCR_2010-04-21-1754.tbi
::
:: Example: set TBIName=WorkComputer

set TBIName=



:: Specify the parameters that should be used by IFW below. This is
:: where you specify the source drive and partition for the backup. Do not
:: include the "/f" option. It will be included automatically.
::
:: Note: If you need to use the Image for Windows "/login" option to access a network share,
:: use the TBILogin script variable below instead of specifying /login here.
::
:: Example: set TBIParms=/b /d:w0
::
:: Example: set TBIParms=/b /d:w0@0x1,0x2 /max:4GiB /v /log:0 /hash /usemd
::
:: Example: set TBIParms=/b /d:#0x77BDFF70@0x1,0x2 /max:4GiB /v /log:0 /hash /usemd

set TBIParms=



:: Specify the path to Image for Windows (imagew.exe).
:: Note: Set this path only if not using the default installation path.
:: Do not include a trailing backslash. Do not include any spaces before or after the equals sign.
:: Omit quotation marks and the trailing backslash.
::
:: Example: set TBIPath=C:\Program Files (x86)\TeraByte Drive Image Backup and Restore Suite

set TBIPath=



:: Specify the maximum number of Full image files to be saved. The oldest
:: Full image file (along with any associated Incremental images) will be
:: deleted when this value is exceeded. Number must be between 2 and 99.
::
:: Note: If the number of existing backup sets (Fulls or Fulls + Incrementals) exceed
:: the number specified, the older sets will be deleted when a new Full is created.
:: This may result in multiple sets being deleted. For example, if you had a previous
:: maximum of 7 and changed it to 3, the oldest sets will be deleted to bring
:: the count down to the new maximum of 3 when a new Full is created.
::
:: Example: Set TBIMaxFullCnt=4

set TBIMaxFullCnt=



:: Specify the maximum number of Incremental image backups to be created for
:: each Full backup. A setting of 0 (zero) will create only Full image backups.
:: If you want to create Incremental backups, set the value to 1 or higher (max. 99).
::
:: Example: set TBIMaxINCRCnt=6

set TBIMaxINCRCnt=



:: Specify any parameters needed when creating a Incremental backup. Don't
:: include the "/b", "/base", or "/f" options as those are automatically
:: included. For example, you may want to verify the image after it's created.
::
:: Note: If you need to use the Image for Windows "/login" option to access a network share,
:: use the TBILogin script variable below instead of specifying /login here.
::
:: Example: set TBIIncParms=/v
::
:: Example: set TBIIncParms=/max:4GiB /v /log:0 /hash /usemd
::

set TBIIncParms=



:: Specify the network login details (if needed to access a network share). Do not set
:: if network login is not required.
::
:: If you include the login details here, don't include them in TBIParms or TBIIncParms.
:: See the Image for Windows manual for details using the /login parameter.
::
:: Note: When this variable is used the script must be run with administrator privileges.
::
:: Example: set TBILogin=/login:"\\server\share*username*password"
:: Example: set TBILogin=/login:"\\BackupServer\Win7Backups*JohnSmith*mypassword"

set TBILogin=



:: ====================================================
:: Command line options for this script file
:: ====================================================
::
:: /f Forces a new Full image to be created. Rotation rules for the
:: maximum number of Full images will still be enforced.
::
:: /d Forces a new Incremental image to be created. Using this option
:: will create an Incremental image even if it will exceed the maximum
:: number specified.
::
:: Note: The Incremental image will be based on the newest Full image or in the newest Incremental image.
:: If no Full image exists, a Full image will be created instead.
::
::

:: ###########################################################################
:: #
:: # NO CHANGES SHOULD BE NEEDED PAST THIS POINT
:: #
:: ###########################################################################

:: Check for Windows 2000 or later

if not "%OS%"=="Windows_NT" goto :NoWin

:: ---------------------------------------------------------------------------

:: Init vars

setlocal enableextensions enabledelayedexpansion

if "%INCRotate%"=="" for /f "usebackq tokens=2,*" %%G in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\TeraByte Unlimited\Image\ExternVars" 2^> nul ^| find "INCRotate"`) do set INCRotate=%%H
set Error=X
set Number1=X
set Number2=X
set TBICmd=X
set TBIOldest=X
set TBINewest=X

if %TBIMaxFullCnt% LSS 2 set /a TBIMaxFullCnt=2
if %TBIMaxFullCnt% GTR 99 set /a TBIMaxFullCnt=99
if %TBIMaxINCRCnt% LSS 0 set /a TBIMaxINCRCnt=0
if %TBIMaxINCRCnt% GTR 99 set /a TBIMaxINCRCnt=99

if not defined TBIBase echo No TBIBase parameter supplied. Please edit: %0 & goto :End
if not defined TBIName echo No TBIName parameter supplied. Please edit: %0 & goto :End
if not defined TBIParms echo No TBIParms parameter supplied. Please edit: %0 & goto :End
if not defined TBIMaxFullCnt echo No TBIMaxFullCnt parameter supplied. Please edit: %0 & goto :End
if not defined TBIMaxINCRCnt echo No TBIMaxINCRCnt parameter supplied. Please edit: %0 & goto :End

:: ---------------------------------------------------------------------------

if "%TBIPath:~0,1%"==" " (set TBIPath=)
if "%TBIPath%"=="" if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set TBIPath=C:\Program Files (x86)\TeraByte Drive Image Backup and Restore Suite
if "%TBIPath%"=="" set TBIPath=C:\Program Files\TeraByte Drive Image Backup and Restore Suite
if not exist "%TBIPath%\imagew.exe" echo Unable to find 'imagew.exe' in the following path: & echo %TBIPath% & echo. & echo Please edit %0 and check TBIPath value. & goto :End

:: ---------------------------------------------------------------------------

:: Log into network share

if "%TBILogin:~0,1%"==" " (set TBILogin=)
if defined TBILogin start "" /min /wait "%TBIPath%\imagew.exe" %TBILogin% /log:0 /quit

:: Get Full image file counts

set /a Number1=0
if exist "%TBIBase%\%TBIName%_*__FULL.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBIName%_*__FULL.tbi" /o-d /b /p /-p /w /-w') do (set TBIOldest=%%a) & (set /a Number1=!Number1!+1) & (if "!TBINewest!"=="X" set TBINewest=%%a)
set TBIFullCnt=%Number1%
echo.
echo Number of Full images found in set: %TBIFullCnt%
if "%TBINewest%"=="X" set TBINewest=(none)
if "%TBIOldest%"=="X" set TBIOldest=(none)
echo Oldest Full image set found: %TBIOldest%
echo Newest Full image set found: %TBINewest%

:: Get INCR image file counts for newest set

set TBINewest=%TBINewest:~0,-10%
set /a Number1=0
if exist "%TBIBase%\%TBINewest%__INCR*.tbi" for /f %%a in ('dir "%TBIBase%\%TBINewest%__INCR*.tbi" /o-d /b /p /-p /w /-w') do (set /a Number1=!Number1!+1)
set TBIINCRCnt=%Number1%
echo.
echo Number of Incremental images found in newest Full set: %TBIINCRCnt% of %TBIMaxINCRCnt%

:: Check which type of backup (Full or INCR) needs to be created

if /i "%1"=="/f" goto :CreateFull
if %TBIFullCnt%==0 goto :CreateFull
if /i "%1"=="/d" goto :CreateINCR
if %TBIINCRCnt% LSS %TBIMaxINCRCnt% goto :CreateINCR
goto :CreateFull

:CreateINCR

echo.
echo Name of the Image to use as base: "%INCRotate%.tbi"
echo.
echo Create Incremental Image
if not exist "%INCRotate%.tbi" goto :CreateFull
call set TBITempName=%%INCRotate:%TBIBase%\=%%
set TBIEndName=%TBITempName:*__=%
call set TBINewName=%%TBITempName:__%TBIEndName%=%%
echo -- Running command: "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"$~INCRotate$" /f:"%TBIBase%\%TBINewName%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$" /savename:INCRotate
start "" /wait "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"$~INCRotate$" /f:"%TBIBase%\%TBINewName%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$" /savename:INCRotate
goto :PostBkup

:CreateFull

if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImage
echo.
echo Number of Full images will exceed %TBIMaxFullCnt%.
echo Deleting oldest Full image set: %TBIOldest% and its incrementals
del "%TBIBase%\%TBIOldest%"
set TBIOldest=%TBIOldest:~0,-10%
if exist "%TBIBase%\%TBIOldest%__INCR*.*" del "%TBIBase%\%TBIOldest%__INCR*.*"
if exist "%TBIBase%\%TBIOldest%__FULL.*" del "%TBIBase%\%TBIOldest%__FULL.*"
:: Check if additional old backup sets need deleted
set /a Number1=0
if exist "%TBIBase%\%TBIName%_*__FULL.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBIName%_*__FULL.tbi" /o-d /b /p /-p /w /-w') do (set TBIOldest=%%a) & (set /a Number1=!Number1!+1)
set TBIFullCnt=%Number1%
if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImage
goto :CreateFull


:CreateFullImage

echo.
echo Create Full Image
echo -- Running command: "%TBIPath%\imagew.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL" /savename:INCRotate
start "" /wait "%TBIPath%\imagew.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL" /savename:INCRotate
goto :PostBkup


:: ---------------------------------------------------------------------------

:PostBkup

set Error=%ERRORLEVEL%

echo.
echo #########################################
if not "%Error%"=="0" echo # The following error was reported: %Error%
if "%Error%"=="0" echo # No errors were reported.
echo #########################################
echo.

goto :End


:: ---------------------------------------------------------------------------

:NoWin

echo.
echo Windows 2000 or later is required for this script.
echo.
goto :End


:: ---------------------------------------------------------------------------

:End

set Error=
set Number1=
set Number2=
set TBIFullCnt=
set TBIINCRCnt=
set TBICmd=
set TBIOldest=
set TBINewest=
set TBITempName=
set TBIEndName=
set TBINewName=

endlocal

set TBIBase=
set TBIName=
set TBIParms=
set TBIPath=
set TBIMaxFullCnt=
set TBIMaxINCRCnt=
set TBIIncParms=
set TBILogin=

:: End of batch script

[/code]
Last edited by Panagiotis on Sun Jul 09, 2017 3:52 pm, edited 4 times in total.
Panagiotis
Posts: 40
Joined: Fri Mar 02, 2012 8:28 pm

Registry Based for x64

Post by Panagiotis »

Registry Based for x64
[code]
@echo off

:: Copyright (C) 2011-2012, TeraByte Unlimited. All rights reserved.
:: version 1.2

:: This batch file maintains multiple iterations of a particular backup. Each
:: time the batch file is run, a backup will be created. The filename will
:: include the date and time. For example, the first time the batch file is run,
:: <file name>_2010-04-18-2315__FULL.tbi will be created. On the next run,
:: <file name>_2010-04-19-2315__FULL.tbi will be created. (Assuming it's run the
:: next day at the same time.) Once the number of backups reaches the number
:: specified, the oldest backup (or backup set) is deleted.
::
::
:: There are several settings you need to specify below.
:: Each one is preceded by the "set" command.

:: ---------------------------------------------------------------------------

:: Specify the folder where backup files will be saved. In all cases, omit the
:: trailing backslash, even for root directories (e.g. C: or D:). Folder
:: path can include spaces.
::
:: A UNC path can also be specified for this variable. NOTE: Make sure the share
:: is accessible or IFWRotate and/or Image for Windows may not function as expected.
:: If necessary, use the TBILogin variable below to specify the network share
:: login details. If IFWRotate cannot access the path it will be unable to count the
:: previous image backups, which will result in only Full images being created and
:: no images being deleted. In this case, it may be necessary to add credentials
:: for the share to the user account running IFWRotate.
::
:: Example: set TBIBase=D:\My Backups
::
:: Example: set TBIBase=\\server\backups\mybackups

set TBIBase=



:: Specify the desired backup filename below. In all cases, omit
:: the file extension. Filename can include spaces. This is the "base"
:: filename used for creating the Full and Incremental filenames.
::
:: Backup images will have the same "base" name as the specified TBIName value
:: with the date, time, and "__FULL" appended (for Full images) or "__INCR_", date,
:: and time appended (for Incremental images).
::
:: Created Full image filename example: WorkComputer_2010-04-20-1754__FULL.tbi
::
:: Created Incremental image filename example: WorkComputer_2010-04-20-1754__INCR_2010-04-21-1754.tbi
::
:: Example: set TBIName=WorkComputer

set TBIName=



:: Specify the parameters that should be used by IFW below. This is
:: where you specify the source drive and partition for the backup. Do not
:: include the "/f" option. It will be included automatically.
::
:: Note: If you need to use the Image for Windows "/login" option to access a network share,
:: use the TBILogin script variable below instead of specifying /login here.
::
:: Example: set TBIParms=/b /d:w0
::
:: Example: set TBIParms=/b /d:w0@0x1,0x2 /max:4GiB /v /log:0 /hash /usemd
::
:: Example: set TBIParms=/b /d:#0x77BDFF70@0x1,0x2 /max:4GiB /v /log:0 /hash /usemd

set TBIParms=



:: Specify the path to Image for Windows (imagew64.exe).
:: Note: Set this path only if not using the default installation path.
:: Do not include a trailing backslash. Do not include any spaces before or after the equals sign.
:: Omit quotation marks and the trailing backslash.
::
:: Example: set TBIPath=C:\Program Files (x86)\TeraByte Drive Image Backup and Restore Suite

set TBIPath=



:: Specify the maximum number of Full image files to be saved. The oldest
:: Full image file (along with any associated Incremental images) will be
:: deleted when this value is exceeded. Number must be between 2 and 99.
::
:: Note: If the number of existing backup sets (Fulls or Fulls + Incrementals) exceed
:: the number specified, the older sets will be deleted when a new Full is created.
:: This may result in multiple sets being deleted. For example, if you had a previous
:: maximum of 7 and changed it to 3, the oldest sets will be deleted to bring
:: the count down to the new maximum of 3 when a new Full is created.
::
:: Example: Set TBIMaxFullCnt=4

set TBIMaxFullCnt=



:: Specify the maximum number of Incremental image backups to be created for
:: each Full backup. A setting of 0 (zero) will create only Full image backups.
:: If you want to create Incremental backups, set the value to 1 or higher (max. 99).
::
:: Example: set TBIMaxINCRCnt=6

set TBIMaxINCRCnt=



:: Specify any parameters needed when creating a Incremental backup. Don't
:: include the "/b", "/base", or "/f" options as those are automatically
:: included. For example, you may want to verify the image after it's created.
::
:: Note: If you need to use the Image for Windows "/login" option to access a network share,
:: use the TBILogin script variable below instead of specifying /login here.
::
:: Example: set TBIIncParms=/v
::
:: Example: set TBIIncParms=/max:4GiB /v /log:0 /hash /usemd
::

set TBIIncParms=



:: Specify the network login details (if needed to access a network share). Do not set
:: if network login is not required.
::
:: If you include the login details here, don't include them in TBIParms or TBIIncParms.
:: See the Image for Windows manual for details using the /login parameter.
::
:: Note: When this variable is used the script must be run with administrator privileges.
::
:: Example: set TBILogin=/login:"\\server\share*username*password"
:: Example: set TBILogin=/login:"\\BackupServer\Win7Backups*JohnSmith*mypassword"

set TBILogin=



:: ====================================================
:: Command line options for this script file
:: ====================================================
::
:: /f Forces a new Full image to be created. Rotation rules for the
:: maximum number of Full images will still be enforced.
::
:: /d Forces a new Incremental image to be created. Using this option
:: will create an Incremental image even if it will exceed the maximum
:: number specified.
::
:: Note: The Incremental image will be based on the newest Full image or in the newest Incremental image.
:: If no Full image exists, a Full image will be created instead.
::
::

:: ###########################################################################
:: #
:: # NO CHANGES SHOULD BE NEEDED PAST THIS POINT
:: #
:: ###########################################################################

:: Check for Windows 2000 or later

if not "%OS%"=="Windows_NT" goto :NoWin

:: ---------------------------------------------------------------------------

:: Init vars

setlocal enableextensions enabledelayedexpansion

if "%INCRotate%"=="" for /f "usebackq tokens=2,*" %%G in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\TeraByte Unlimited\Image\ExternVars" 2^> nul ^| find "INCRotate"`) do set INCRotate=%%H
set Error=X
set Number1=X
set Number2=X
set TBICmd=X
set TBIOldest=X
set TBINewest=X

if %TBIMaxFullCnt% LSS 2 set /a TBIMaxFullCnt=2
if %TBIMaxFullCnt% GTR 99 set /a TBIMaxFullCnt=99
if %TBIMaxINCRCnt% LSS 0 set /a TBIMaxINCRCnt=0
if %TBIMaxINCRCnt% GTR 99 set /a TBIMaxINCRCnt=99

if not defined TBIBase echo No TBIBase parameter supplied. Please edit: %0 & goto :End
if not defined TBIName echo No TBIName parameter supplied. Please edit: %0 & goto :End
if not defined TBIParms echo No TBIParms parameter supplied. Please edit: %0 & goto :End
if not defined TBIMaxFullCnt echo No TBIMaxFullCnt parameter supplied. Please edit: %0 & goto :End
if not defined TBIMaxINCRCnt echo No TBIMaxINCRCnt parameter supplied. Please edit: %0 & goto :End

:: ---------------------------------------------------------------------------

if "%TBIPath:~0,1%"==" " (set TBIPath=)
if "%TBIPath%"=="" if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set TBIPath=C:\Program Files (x86)\TeraByte Drive Image Backup and Restore Suite
if "%TBIPath%"=="" set TBIPath=C:\Program Files\TeraByte Drive Image Backup and Restore Suite
if not exist "%TBIPath%\imagew64.exe" echo Unable to find 'imagew64.exe' in the following path: & echo %TBIPath% & echo. & echo Please edit %0 and check TBIPath value. & goto :End

:: ---------------------------------------------------------------------------

:: Log into network share

if "%TBILogin:~0,1%"==" " (set TBILogin=)
if defined TBILogin start "" /min /wait "%TBIPath%\imagew64.exe" %TBILogin% /log:0 /quit

:: Get Full image file counts

set /a Number1=0
if exist "%TBIBase%\%TBIName%_*__FULL.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBIName%_*__FULL.tbi" /o-d /b /p /-p /w /-w') do (set TBIOldest=%%a) & (set /a Number1=!Number1!+1) & (if "!TBINewest!"=="X" set TBINewest=%%a)
set TBIFullCnt=%Number1%
echo.
echo Number of Full images found in set: %TBIFullCnt%
if "%TBINewest%"=="X" set TBINewest=(none)
if "%TBIOldest%"=="X" set TBIOldest=(none)
echo Oldest Full image set found: %TBIOldest%
echo Newest Full image set found: %TBINewest%

:: Get INCR image file counts for newest set

set TBINewest=%TBINewest:~0,-10%
set /a Number1=0
if exist "%TBIBase%\%TBINewest%__INCR*.tbi" for /f %%a in ('dir "%TBIBase%\%TBINewest%__INCR*.tbi" /o-d /b /p /-p /w /-w') do (set /a Number1=!Number1!+1)
set TBIINCRCnt=%Number1%
echo.
echo Number of Incremental images found in newest Full set: %TBIINCRCnt% of %TBIMaxINCRCnt%

:: Check which type of backup (Full or INCR) needs to be created

if /i "%1"=="/f" goto :CreateFull
if %TBIFullCnt%==0 goto :CreateFull
if /i "%1"=="/d" goto :CreateINCR
if %TBIINCRCnt% LSS %TBIMaxINCRCnt% goto :CreateINCR
goto :CreateFull

:CreateINCR

echo.
echo Name of the Image to use as base: "%INCRotate%.tbi"
echo.
echo Create Incremental Image
if not exist "%INCRotate%.tbi" goto :CreateFull
call set TBITempName=%%INCRotate:%TBIBase%\=%%
set TBIEndName=%TBITempName:*__=%
call set TBINewName=%%TBITempName:__%TBIEndName%=%%
echo -- Running command: "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"$~INCRotate$" /f:"%TBIBase%\%TBINewName%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$" /savename:INCRotate
start "" /wait "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"$~INCRotate$" /f:"%TBIBase%\%TBINewName%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$" /savename:INCRotate
goto :PostBkup

:CreateFull

if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImage
echo.
echo Number of Full images will exceed %TBIMaxFullCnt%.
echo Deleting oldest Full image set: %TBIOldest% and its incrementals
del "%TBIBase%\%TBIOldest%"
set TBIOldest=%TBIOldest:~0,-10%
if exist "%TBIBase%\%TBIOldest%__INCR*.*" del "%TBIBase%\%TBIOldest%__INCR*.*"
if exist "%TBIBase%\%TBIOldest%__FULL.*" del "%TBIBase%\%TBIOldest%__FULL.*"
:: Check if additional old backup sets need deleted
set /a Number1=0
if exist "%TBIBase%\%TBIName%_*__FULL.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBIName%_*__FULL.tbi" /o-d /b /p /-p /w /-w') do (set TBIOldest=%%a) & (set /a Number1=!Number1!+1)
set TBIFullCnt=%Number1%
if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImage
goto :CreateFull


:CreateFullImage

echo.
echo Create Full Image
echo -- Running command: "%TBIPath%\imagew64.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL" /savename:INCRotate
start "" /wait "%TBIPath%\imagew64.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL" /savename:INCRotate
goto :PostBkup


:: ---------------------------------------------------------------------------

:PostBkup

set Error=%ERRORLEVEL%

echo.
echo #########################################
if not "%Error%"=="0" echo # The following error was reported: %Error%
if "%Error%"=="0" echo # No errors were reported.
echo #########################################
echo.

goto :End


:: ---------------------------------------------------------------------------

:NoWin

echo.
echo Windows 2000 or later is required for this script.
echo.
goto :End


:: ---------------------------------------------------------------------------

:End

set Error=
set Number1=
set Number2=
set TBIFullCnt=
set TBIINCRCnt=
set TBICmd=
set TBIOldest=
set TBINewest=
set TBITempName=
set TBIEndName=
set TBINewName=

endlocal

set TBIBase=
set TBIName=
set TBIParms=
set TBIPath=
set TBIMaxFullCnt=
set TBIMaxINCRCnt=
set TBIIncParms=
set TBILogin=

:: End of batch script

[/code]
Last edited by Panagiotis on Sun Jul 09, 2017 3:40 pm, edited 2 times in total.
Panagiotis
Posts: 40
Joined: Fri Mar 02, 2012 8:28 pm

TimeStamp or txt Based for x86

Post by Panagiotis »

TimeStamp or txt Based for x86
[code]
@echo off

:: Copyright (C) 2011-2012, TeraByte Unlimited. All rights reserved.
:: version 1.2

:: This batch file maintains multiple iterations of a particular backup. Each
:: time the batch file is run, a backup will be created. The filename will
:: include the date and time. For example, the first time the batch file is run,
:: <file name>_2010-04-18-2315__FULL.tbi will be created. On the next run,
:: <file name>_2010-04-19-2315__FULL.tbi will be created. (Assuming it's run the
:: next day at the same time.) Once the number of backups reaches the number
:: specified, the oldest backup (or backup set) is deleted.
::
::
:: There are several settings you need to specify below.
:: Each one is preceded by the "set" command.

:: ---------------------------------------------------------------------------

:: Specify the folder where backup files will be saved. In all cases, omit the
:: trailing backslash, even for root directories (e.g. C: or D:). Folder
:: path can include spaces.
::
:: A UNC path can also be specified for this variable. NOTE: Make sure the share
:: is accessible or IFWRotate and/or Image for Windows may not function as expected.
:: If necessary, use the TBILogin variable below to specify the network share
:: login details. If IFWRotate cannot access the path it will be unable to count the
:: previous image backups, which will result in only Full images being created and
:: no images being deleted. In this case, it may be necessary to add credentials
:: for the share to the user account running IFWRotate.
::
:: Example: set TBIBase=D:\My Backups
::
:: Example: set TBIBase=\\server\backups\mybackups

set TBIBase=



:: Specify the desired backup filename below. In all cases, omit
:: the file extension. Filename can include spaces. This is the "base"
:: filename used for creating the Full and Incremental filenames.
::
:: Backup images will have the same "base" name as the specified TBIName value
:: with the date, time, and "__FULL" appended (for Full images) or "__INCR_", date,
:: and time appended (for Incremental images).
::
:: Created Full image filename example: WorkComputer_2010-04-20-1754__FULL.tbi
::
:: Created Incremental image filename example: WorkComputer_2010-04-20-1754__INCR_2010-04-21-1754.tbi
::
:: Example: set TBIName=WorkComputer

set TBIName=



:: Specify the parameters that should be used by IFW below. This is
:: where you specify the source drive and partition for the backup. Do not
:: include the "/f" option. It will be included automatically.
::
:: Note: If you need to use the Image for Windows "/login" option to access a network share,
:: use the TBILogin script variable below instead of specifying /login here.
::
:: Example: set TBIParms=/b /d:w0
::
:: Example: set TBIParms=/b /d:w0@0x1,0x2 /max:4GiB /v /log:0 /hash /usemd
::
:: Example: set TBIParms=/b /d:#0x77BDFF70@0x1,0x2 /max:4GiB /v /log:0 /hash /usemd

set TBIParms=



:: Specify the path to Image for Windows (imagew.exe).
:: Note: Set this path only if not using the default installation path.
:: Do not include a trailing backslash. Do not include any spaces before or after the equals sign.
:: Omit quotation marks and the trailing backslash.
::
:: Example: set TBIPath=C:\Program Files (x86)\TeraByte Drive Image Backup and Restore Suite

set TBIPath=



:: Specify the maximum number of Full image files to be saved. The oldest
:: Full image file (along with any associated Incremental images) will be
:: deleted when this value is exceeded. Number must be between 2 and 99.
::
:: Note: If the number of existing backup sets (Fulls or Fulls + Incrementals) exceed
:: the number specified, the older sets will be deleted when a new Full is created.
:: This may result in multiple sets being deleted. For example, if you had a previous
:: maximum of 7 and changed it to 3, the oldest sets will be deleted to bring
:: the count down to the new maximum of 3 when a new Full is created.
::
:: Example: Set TBIMaxFullCnt=4

set TBIMaxFullCnt=



:: Specify the maximum number of Incremental image backups to be created for
:: each Full backup. A setting of 0 (zero) will create only Full image backups.
:: If you want to create Incremental backups, set the value to 1 or higher (max. 99).
::
:: Example: set TBIMaxINCRCnt=6

set TBIMaxINCRCnt=



:: Specify any parameters needed when creating a Incremental backup. Don't
:: include the "/b", "/base", or "/f" options as those are automatically
:: included. For example, you may want to verify the image after it's created.
::
:: Note: If you need to use the Image for Windows "/login" option to access a network share,
:: use the TBILogin script variable below instead of specifying /login here.
::
:: Example: set TBIIncParms=/v
::
:: Example: set TBIIncParms=/max:4GiB /v /log:0 /hash /usemd
::

set TBIIncParms=



:: Specify the network login details (if needed to access a network share). Do not set
:: if network login is not required.
::
:: If you include the login details here, don't include them in TBIParms or TBIIncParms.
:: See the Image for Windows manual for details using the /login parameter.
::
:: Note: When this variable is used the script must be run with administrator privileges.
::
:: Example: set TBILogin=/login:"\\server\share*username*password"
:: Example: set TBILogin=/login:"\\BackupServer\Win7Backups*JohnSmith*mypassword"

set TBILogin=



:: Specify the folder where the txt file with the last image name will be saved. In all cases,
:: omit the trailing backslash, even for root directories (e.g. C: or D:). Folder
:: path can include spaces.
::
:: NOTE: Place it in one of the partitions that will get backed up.So if you restore the image
:: the script will be able to find the previous incremental that used as base.
:: new
::
:: Example: set TBIBasetxt=C:\My Last Backups
::

set TBIBasetxt=



:: Specify the desired txt filename below.
::
:: Example: set TBINametxt=Last backup
::

set TBINametxt=



:: ====================================================
:: Command line options for this script file
:: ====================================================
::
:: /f Forces a new Full image to be created. Rotation rules for the
:: maximum number of Full images will still be enforced.
::
:: /d Forces a new Incremental image to be created. Using this option
:: will create an Incremental image even if it will exceed the maximum
:: number specified.
::
:: Note: The Incremental image will be based on the newest Full image or in the newest Incremental image.
:: If no Full image exists, a Full image will be created instead.
::
::

:: ###########################################################################
:: #
:: # NO CHANGES SHOULD BE NEEDED PAST THIS POINT
:: #
:: ###########################################################################

:: Check for Windows 2000 or later

if not "%OS%"=="Windows_NT" goto :NoWin

:: ---------------------------------------------------------------------------

:: Init vars

setlocal enableextensions enabledelayedexpansion

set Error=X
set Number1=X
set Number2=X
set TBICmd=X
set TBIOldest=X
set TBINewest=X
set TBIINCRNewest=X

if %TBIMaxFullCnt% LSS 2 set /a TBIMaxFullCnt=2
if %TBIMaxFullCnt% GTR 99 set /a TBIMaxFullCnt=99
if %TBIMaxINCRCnt% LSS 0 set /a TBIMaxINCRCnt=0
if %TBIMaxINCRCnt% GTR 99 set /a TBIMaxINCRCnt=99

if not defined TBIBase echo No TBIBase parameter supplied. Please edit: %0 & goto :End
if not defined TBIName echo No TBIName parameter supplied. Please edit: %0 & goto :End
if not defined TBIParms echo No TBIParms parameter supplied. Please edit: %0 & goto :End
if not defined TBIMaxFullCnt echo No TBIMaxFullCnt parameter supplied. Please edit: %0 & goto :End
if not defined TBIMaxINCRCnt echo No TBIMaxINCRCnt parameter supplied. Please edit: %0 & goto :End

:: ---------------------------------------------------------------------------

if "%TBIPath:~0,1%"==" " (set TBIPath=)
if "%TBIPath%"=="" if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set TBIPath=C:\Program Files (x86)\TeraByte Drive Image Backup and Restore Suite
if "%TBIPath%"=="" set TBIPath=C:\Program Files\TeraByte Drive Image Backup and Restore Suite
if not exist "%TBIPath%\imagew.exe" echo Unable to find 'imagew.exe' in the following path: & echo %TBIPath% & echo. & echo Please edit %0 and check TBIPath value. & goto :End

:: ---------------------------------------------------------------------------

:: Log into network share

if "%TBILogin:~0,1%"==" " (set TBILogin=)
if defined TBILogin start "" /min /wait "%TBIPath%\imagew.exe" %TBILogin% /log:0 /quit

:: Get Full image file counts

set /a Number1=0
if exist "%TBIBase%\%TBIName%_*__FULL.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBIName%_*__FULL.tbi" /o-d /b /p /-p /w /-w') do (set TBIOldest=%%a) & (set /a Number1=!Number1!+1) & (if "!TBINewest!"=="X" set TBINewest=%%a)
set TBIFullCnt=%Number1%
echo.
echo Number of Full images found in set: %TBIFullCnt%
if "%TBINewest%"=="X" set TBINewest=(none)
if "%TBIOldest%"=="X" set TBIOldest=(none)
echo Oldest Full image set found: %TBIOldest%
echo Newest Full image set found: %TBINewest%

:: Get INCR image file counts for newest set

set TBINewest=%TBINewest:~0,-10%
set /a Number1=0
if exist "%TBIBase%\%TBINewest%__INCR*.tbi" for /f %%a in ('dir "%TBIBase%\%TBINewest%__INCR*.tbi" /o-d /b /p /-p /w /-w') do (set /a Number1=!Number1!+1)
set TBIINCRCnt=%Number1%
echo.
echo Number of Incremental images found in newest Full set: %TBIINCRCnt% of %TBIMaxINCRCnt%

:: Check if TBIBasetxt exists

if defined TBIBasetxt goto :TBIBasetxtEnabled

:txtnamenotfound

:: Get last INCR image file name

set TBIINCRNewest=%TBIINCRNewest%
if exist "%TBIBase%\%TBINewest%__INCR*.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBINewest%__INCR*.tbi" /od /b /p /-p /w /-w') do (set TBIINCRNewest=%%a) & (if "!TBIINCRNewest!"=="X" set TBIINCRNewest=%%a)
echo.
echo Name of the last Incremental image found: %TBIINCRNewest%

:: Check which type of backup (Full or INCR) needs to be created

if /i "%1"=="/f" goto :CreateFull
if %TBIFullCnt%==0 goto :CreateFull
if /i "%1"=="/d" goto :CreateINCR
if %TBIINCRCnt% LSS %TBIMaxINCRCnt% goto :CreateINCR
goto :CreateFull

:CreateINCR

echo.
echo Create New Incremental Image
if not exist "%TBIBase%\%TBINewest%__FULL.tbi" goto :CreateFull
if not exist "%TBIBase%\%TBINewest%__INCR*.tbi" goto :Create1stINCR
echo -- Running command: "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBIINCRNewest%" /f:"%TBIBase%\%TBINewest%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
start "" /wait "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBIINCRNewest%" /f:"%TBIBase%\%TBINewest%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
goto :PostBkup

:Create1stINCR

echo.
echo Create 1st Incremental Image
echo -- Running command: "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBINewest%__FULL.tbi" /f:"%TBIBase%\%TBINewest%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
start "" /wait "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBINewest%__FULL.tbi" /f:"%TBIBase%\%TBINewest%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
goto :PostBkup

:CreateFull

if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImage
echo.
echo Number of Full images will exceed %TBIMaxFullCnt%.
echo Deleting oldest Full image set: %TBIOldest% and its incrementals
del "%TBIBase%\%TBIOldest%"
set TBIOldest=%TBIOldest:~0,-10%
if exist "%TBIBase%\%TBIOldest%__INCR*.*" del "%TBIBase%\%TBIOldest%__INCR*.*"
if exist "%TBIBase%\%TBIOldest%__FULL.*" del "%TBIBase%\%TBIOldest%__FULL.*"
:: Check if additional old backup sets need deleted
set /a Number1=0
if exist "%TBIBase%\%TBIName%_*__FULL.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBIName%_*__FULL.tbi" /o-d /b /p /-p /w /-w') do (set TBIOldest=%%a) & (set /a Number1=!Number1!+1)
set TBIFullCnt=%Number1%
if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImage
goto :CreateFull

:CreateFullImage

echo.
echo Create Full Image
echo -- Running command: "%TBIPath%\imagew.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL"
start "" /wait "%TBIPath%\imagew.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL"
goto :PostBkup

:TBIBasetxtEnabled

:: Check if TBINametxt exists

if not defined TBINametxt goto :txtnamenotfound

:: Check which type of backup (Full or INCR) needs to be created

if /i "%1"=="/f" goto :CreateFulltxt
if %TBIFullCnt%==0 goto :CreateFulltxt
if /i "%1"=="/d" goto :CreateINCRtxt
if %TBIINCRCnt% LSS %TBIMaxINCRCnt% goto :CreateINCRtxt
goto :CreateFulltxt

:CreateINCRtxt

echo.
echo Create New Incremental Image
if not exist "%TBIBase%\%TBINewest%__FULL.tbi" goto :CreateFulltxt
if not exist "%TBIBasetxt%\%TBINametxt%.txt" goto :CreateFulltxt
set /p TBITempName=< "%TBIBasetxt%\%TBINametxt%.txt"
set TBIEndName=%TBITempName:*__=%
call set TBINewName=%%TBITempName:__%TBIEndName%=%%
echo.
echo Image to use as base: %TBITempName%
echo.
echo -- Running command: "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBITempName%" /f:"%TBIBase%\%TBINewName%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
start "" /wait "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBITempName%" /f:"%TBIBase%\%TBINewName%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
goto :PostBkuptxt

:CreateFulltxt

if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImagetxt
echo.
echo Number of Full images will exceed %TBIMaxFullCnt%.
echo Deleting oldest Full image set: %TBIOldest% and its incrementals
del "%TBIBase%\%TBIOldest%"
set TBIOldest=%TBIOldest:~0,-10%
if exist "%TBIBase%\%TBIOldest%__INCR*.*" del "%TBIBase%\%TBIOldest%__INCR*.*"
if exist "%TBIBase%\%TBIOldest%__FULL.*" del "%TBIBase%\%TBIOldest%__FULL.*"
:: Check if additional old backup sets need deleted
set /a Number1=0
if exist "%TBIBase%\%TBIName%_*__FULL.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBIName%_*__FULL.tbi" /o-d /b /p /-p /w /-w') do (set TBIOldest=%%a) & (set /a Number1=!Number1!+1)
set TBIFullCnt=%Number1%
if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImagetxt
goto :CreateFulltxt

:CreateFullImagetxt

echo.
echo Create Full Image
echo -- Running command: "%TBIPath%\imagew.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL"
start "" /wait "%TBIPath%\imagew.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL"
goto :PostBkuptxt

:: ---------------------------------------------------------------------------

:PostBkup

set Error=%ERRORLEVEL%

echo.
echo #########################################
if not "%Error%"=="0" echo # The following error was reported: %Error%
if "%Error%"=="0" echo # No errors were reported.
echo #########################################
echo.

goto :End


:: ---------------------------------------------------------------------------

:PostBkuptxt

set Error=%ERRORLEVEL%

echo.
set TBIILast=%TBIILast%
if exist "%TBIBase%\*.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\*.tbi" /od /b /p /-p /w /-w') do (set TBIILast=%%a) & (if "!TBIILast!"=="X" set TBIILast=%%a)
echo.
echo Save the name of the last image in the txt file: %TBIILast%
If not exist "%TBIBasetxt%" md "%TBIBasetxt%"
dir /b "%TBIBase%\%TBIILast%" > "%TBIBasetxt%\%TBINametxt%.txt"
echo.

echo.
echo #########################################
if not "%Error%"=="0" echo # The following error was reported: %Error%
if "%Error%"=="0" echo # No errors were reported.
echo #########################################
echo.

goto :End


:: ---------------------------------------------------------------------------

:NoWin

echo.
echo Windows 2000 or later is required for this script.
echo.
goto :End


:: ---------------------------------------------------------------------------

:End

set Error=
set Number1=
set Number2=
set TBIFullCnt=
set TBIINCRCnt=
set TBICmd=
set TBIOldest=
set TBINewest=
set TBIINCRNewest=
set TBIILast=
set TBITempName=
set TBIEndName=
set TBINewName=

endlocal

set TBIBase=
set TBIName=
set TBIParms=
set TBIPath=
set TBIMaxFullCnt=
set TBIMaxINCRCnt=
set TBIIncParms=
set TBILogin=
set TBIBasetxt=
set TBINametxt=

:: End of batch script

[/code]
Last edited by Panagiotis on Sun Jul 09, 2017 3:44 pm, edited 1 time in total.
Panagiotis
Posts: 40
Joined: Fri Mar 02, 2012 8:28 pm

TimeStamp or txt Based for x64

Post by Panagiotis »

TimeStamp or txt Based for x64
[code]
@echo off

:: Copyright (C) 2011-2012, TeraByte Unlimited. All rights reserved.
:: version 1.2

:: This batch file maintains multiple iterations of a particular backup. Each
:: time the batch file is run, a backup will be created. The filename will
:: include the date and time. For example, the first time the batch file is run,
:: <file name>_2010-04-18-2315__FULL.tbi will be created. On the next run,
:: <file name>_2010-04-19-2315__FULL.tbi will be created. (Assuming it's run the
:: next day at the same time.) Once the number of backups reaches the number
:: specified, the oldest backup (or backup set) is deleted.
::
::
:: There are several settings you need to specify below.
:: Each one is preceded by the "set" command.

:: ---------------------------------------------------------------------------

:: Specify the folder where backup files will be saved. In all cases, omit the
:: trailing backslash, even for root directories (e.g. C: or D:). Folder
:: path can include spaces.
::
:: A UNC path can also be specified for this variable. NOTE: Make sure the share
:: is accessible or IFWRotate and/or Image for Windows may not function as expected.
:: If necessary, use the TBILogin variable below to specify the network share
:: login details. If IFWRotate cannot access the path it will be unable to count the
:: previous image backups, which will result in only Full images being created and
:: no images being deleted. In this case, it may be necessary to add credentials
:: for the share to the user account running IFWRotate.
::
:: Example: set TBIBase=D:\My Backups
::
:: Example: set TBIBase=\\server\backups\mybackups

set TBIBase=



:: Specify the desired backup filename below. In all cases, omit
:: the file extension. Filename can include spaces. This is the "base"
:: filename used for creating the Full and Incremental filenames.
::
:: Backup images will have the same "base" name as the specified TBIName value
:: with the date, time, and "__FULL" appended (for Full images) or "__INCR_", date,
:: and time appended (for Incremental images).
::
:: Created Full image filename example: WorkComputer_2010-04-20-1754__FULL.tbi
::
:: Created Incremental image filename example: WorkComputer_2010-04-20-1754__INCR_2010-04-21-1754.tbi
::
:: Example: set TBIName=WorkComputer

set TBIName=



:: Specify the parameters that should be used by IFW below. This is
:: where you specify the source drive and partition for the backup. Do not
:: include the "/f" option. It will be included automatically.
::
:: Note: If you need to use the Image for Windows "/login" option to access a network share,
:: use the TBILogin script variable below instead of specifying /login here.
::
:: Example: set TBIParms=/b /d:w0
::
:: Example: set TBIParms=/b /d:w0@0x1,0x2 /max:4GiB /v /log:0 /hash /usemd
::
:: Example: set TBIParms=/b /d:#0x77BDFF70@0x1,0x2 /max:4GiB /v /log:0 /hash /usemd

set TBIParms=



:: Specify the path to Image for Windows (imagew64.exe).
:: Note: Set this path only if not using the default installation path.
:: Do not include a trailing backslash. Do not include any spaces before or after the equals sign.
:: Omit quotation marks and the trailing backslash.
::
:: Example: set TBIPath=C:\Program Files (x86)\TeraByte Drive Image Backup and Restore Suite

set TBIPath=



:: Specify the maximum number of Full image files to be saved. The oldest
:: Full image file (along with any associated Incremental images) will be
:: deleted when this value is exceeded. Number must be between 2 and 99.
::
:: Note: If the number of existing backup sets (Fulls or Fulls + Incrementals) exceed
:: the number specified, the older sets will be deleted when a new Full is created.
:: This may result in multiple sets being deleted. For example, if you had a previous
:: maximum of 7 and changed it to 3, the oldest sets will be deleted to bring
:: the count down to the new maximum of 3 when a new Full is created.
::
:: Example: Set TBIMaxFullCnt=4

set TBIMaxFullCnt=



:: Specify the maximum number of Incremental image backups to be created for
:: each Full backup. A setting of 0 (zero) will create only Full image backups.
:: If you want to create Incremental backups, set the value to 1 or higher (max. 99).
::
:: Example: set TBIMaxINCRCnt=6

set TBIMaxINCRCnt=



:: Specify any parameters needed when creating a Incremental backup. Don't
:: include the "/b", "/base", or "/f" options as those are automatically
:: included. For example, you may want to verify the image after it's created.
::
:: Note: If you need to use the Image for Windows "/login" option to access a network share,
:: use the TBILogin script variable below instead of specifying /login here.
::
:: Example: set TBIIncParms=/v
::
:: Example: set TBIIncParms=/max:4GiB /v /log:0 /hash /usemd
::

set TBIIncParms=



:: Specify the network login details (if needed to access a network share). Do not set
:: if network login is not required.
::
:: If you include the login details here, don't include them in TBIParms or TBIIncParms.
:: See the Image for Windows manual for details using the /login parameter.
::
:: Note: When this variable is used the script must be run with administrator privileges.
::
:: Example: set TBILogin=/login:"\\server\share*username*password"
:: Example: set TBILogin=/login:"\\BackupServer\Win7Backups*JohnSmith*mypassword"

set TBILogin=



:: Specify the folder where the txt file with the last image name will be saved. In all cases,
:: omit the trailing backslash, even for root directories (e.g. C: or D:). Folder
:: path can include spaces.
::
:: NOTE: Place it in one of the partitions that will get backed up.So if you restore the image
:: the script will be able to find the previous incremental that used as base.
:: new
::
:: Example: set TBIBasetxt=C:\My Last Backups
::

set TBIBasetxt=



:: Specify the desired txt filename below.
::
:: Example: set TBINametxt=Last backup
::

set TBINametxt=



:: ====================================================
:: Command line options for this script file
:: ====================================================
::
:: /f Forces a new Full image to be created. Rotation rules for the
:: maximum number of Full images will still be enforced.
::
:: /d Forces a new Incremental image to be created. Using this option
:: will create an Incremental image even if it will exceed the maximum
:: number specified.
::
:: Note: The Incremental image will be based on the newest Full image or in the newest Incremental image.
:: If no Full image exists, a Full image will be created instead.
::
::

:: ###########################################################################
:: #
:: # NO CHANGES SHOULD BE NEEDED PAST THIS POINT
:: #
:: ###########################################################################

:: Check for Windows 2000 or later

if not "%OS%"=="Windows_NT" goto :NoWin

:: ---------------------------------------------------------------------------

:: Init vars

setlocal enableextensions enabledelayedexpansion

set Error=X
set Number1=X
set Number2=X
set TBICmd=X
set TBIOldest=X
set TBINewest=X
set TBIINCRNewest=X

if %TBIMaxFullCnt% LSS 2 set /a TBIMaxFullCnt=2
if %TBIMaxFullCnt% GTR 99 set /a TBIMaxFullCnt=99
if %TBIMaxINCRCnt% LSS 0 set /a TBIMaxINCRCnt=0
if %TBIMaxINCRCnt% GTR 99 set /a TBIMaxINCRCnt=99

if not defined TBIBase echo No TBIBase parameter supplied. Please edit: %0 & goto :End
if not defined TBIName echo No TBIName parameter supplied. Please edit: %0 & goto :End
if not defined TBIParms echo No TBIParms parameter supplied. Please edit: %0 & goto :End
if not defined TBIMaxFullCnt echo No TBIMaxFullCnt parameter supplied. Please edit: %0 & goto :End
if not defined TBIMaxINCRCnt echo No TBIMaxINCRCnt parameter supplied. Please edit: %0 & goto :End

:: ---------------------------------------------------------------------------

if "%TBIPath:~0,1%"==" " (set TBIPath=)
if "%TBIPath%"=="" if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set TBIPath=C:\Program Files (x86)\TeraByte Drive Image Backup and Restore Suite
if "%TBIPath%"=="" set TBIPath=C:\Program Files\TeraByte Drive Image Backup and Restore Suite
if not exist "%TBIPath%\imagew64.exe" echo Unable to find 'imagew64.exe' in the following path: & echo %TBIPath% & echo. & echo Please edit %0 and check TBIPath value. & goto :End

:: ---------------------------------------------------------------------------

:: Log into network share

if "%TBILogin:~0,1%"==" " (set TBILogin=)
if defined TBILogin start "" /min /wait "%TBIPath%\imagew64.exe" %TBILogin% /log:0 /quit

:: Get Full image file counts

set /a Number1=0
if exist "%TBIBase%\%TBIName%_*__FULL.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBIName%_*__FULL.tbi" /o-d /b /p /-p /w /-w') do (set TBIOldest=%%a) & (set /a Number1=!Number1!+1) & (if "!TBINewest!"=="X" set TBINewest=%%a)
set TBIFullCnt=%Number1%
echo.
echo Number of Full images found in set: %TBIFullCnt%
if "%TBINewest%"=="X" set TBINewest=(none)
if "%TBIOldest%"=="X" set TBIOldest=(none)
echo Oldest Full image set found: %TBIOldest%
echo Newest Full image set found: %TBINewest%

:: Get INCR image file counts for newest set

set TBINewest=%TBINewest:~0,-10%
set /a Number1=0
if exist "%TBIBase%\%TBINewest%__INCR*.tbi" for /f %%a in ('dir "%TBIBase%\%TBINewest%__INCR*.tbi" /o-d /b /p /-p /w /-w') do (set /a Number1=!Number1!+1)
set TBIINCRCnt=%Number1%
echo.
echo Number of Incremental images found in newest Full set: %TBIINCRCnt% of %TBIMaxINCRCnt%

:: Check if TBIBasetxt exists

if defined TBIBasetxt goto :TBIBasetxtEnabled

:txtnamenotfound

:: Get last INCR image file name

set TBIINCRNewest=%TBIINCRNewest%
if exist "%TBIBase%\%TBINewest%__INCR*.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBINewest%__INCR*.tbi" /od /b /p /-p /w /-w') do (set TBIINCRNewest=%%a) & (if "!TBIINCRNewest!"=="X" set TBIINCRNewest=%%a)
echo.
echo Name of the last Incremental image found: %TBIINCRNewest%

:: Check which type of backup (Full or INCR) needs to be created

if /i "%1"=="/f" goto :CreateFull
if %TBIFullCnt%==0 goto :CreateFull
if /i "%1"=="/d" goto :CreateINCR
if %TBIINCRCnt% LSS %TBIMaxINCRCnt% goto :CreateINCR
goto :CreateFull

:CreateINCR

echo.
echo Create New Incremental Image
if not exist "%TBIBase%\%TBINewest%__FULL.tbi" goto :CreateFull
if not exist "%TBIBase%\%TBINewest%__INCR*.tbi" goto :Create1stINCR
echo -- Running command: "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBIINCRNewest%" /f:"%TBIBase%\%TBINewest%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
start "" /wait "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBIINCRNewest%" /f:"%TBIBase%\%TBINewest%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
goto :PostBkup

:Create1stINCR

echo.
echo Create 1st Incremental Image
echo -- Running command: "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBINewest%__FULL.tbi" /f:"%TBIBase%\%TBINewest%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
start "" /wait "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBINewest%__FULL.tbi" /f:"%TBIBase%\%TBINewest%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
goto :PostBkup

:CreateFull

if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImage
echo.
echo Number of Full images will exceed %TBIMaxFullCnt%.
echo Deleting oldest Full image set: %TBIOldest% and its incrementals
del "%TBIBase%\%TBIOldest%"
set TBIOldest=%TBIOldest:~0,-10%
if exist "%TBIBase%\%TBIOldest%__INCR*.*" del "%TBIBase%\%TBIOldest%__INCR*.*"
if exist "%TBIBase%\%TBIOldest%__FULL.*" del "%TBIBase%\%TBIOldest%__FULL.*"
:: Check if additional old backup sets need deleted
set /a Number1=0
if exist "%TBIBase%\%TBIName%_*__FULL.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBIName%_*__FULL.tbi" /o-d /b /p /-p /w /-w') do (set TBIOldest=%%a) & (set /a Number1=!Number1!+1)
set TBIFullCnt=%Number1%
if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImage
goto :CreateFull

:CreateFullImage

echo.
echo Create Full Image
echo -- Running command: "%TBIPath%\imagew64.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL"
start "" /wait "%TBIPath%\imagew64.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL"
goto :PostBkup

:TBIBasetxtEnabled

:: Check if TBINametxt exists

if not defined TBINametxt goto :txtnamenotfound

:: Check which type of backup (Full or INCR) needs to be created

if /i "%1"=="/f" goto :CreateFulltxt
if %TBIFullCnt%==0 goto :CreateFulltxt
if /i "%1"=="/d" goto :CreateINCRtxt
if %TBIINCRCnt% LSS %TBIMaxINCRCnt% goto :CreateINCRtxt
goto :CreateFulltxt

:CreateINCRtxt

echo.
echo Create New Incremental Image
if not exist "%TBIBase%\%TBINewest%__FULL.tbi" goto :CreateFulltxt
if not exist "%TBIBasetxt%\%TBINametxt%.txt" goto :CreateFulltxt
set /p TBITempName=< "%TBIBasetxt%\%TBINametxt%.txt"
set TBIEndName=%TBITempName:*__=%
call set TBINewName=%%TBITempName:__%TBIEndName%=%%
echo.
echo Image to use as base: %TBITempName%
echo.
echo -- Running command: "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBITempName%" /f:"%TBIBase%\%TBINewName%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
start "" /wait "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBITempName%" /f:"%TBIBase%\%TBINewName%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$"
goto :PostBkuptxt

:CreateFulltxt

if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImagetxt
echo.
echo Number of Full images will exceed %TBIMaxFullCnt%.
echo Deleting oldest Full image set: %TBIOldest% and its incrementals
del "%TBIBase%\%TBIOldest%"
set TBIOldest=%TBIOldest:~0,-10%
if exist "%TBIBase%\%TBIOldest%__INCR*.*" del "%TBIBase%\%TBIOldest%__INCR*.*"
if exist "%TBIBase%\%TBIOldest%__FULL.*" del "%TBIBase%\%TBIOldest%__FULL.*"
:: Check if additional old backup sets need deleted
set /a Number1=0
if exist "%TBIBase%\%TBIName%_*__FULL.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\%TBIName%_*__FULL.tbi" /o-d /b /p /-p /w /-w') do (set TBIOldest=%%a) & (set /a Number1=!Number1!+1)
set TBIFullCnt=%Number1%
if %TBIFullCnt% LSS %TBIMaxFullCnt% goto :CreateFullImagetxt
goto :CreateFulltxt

:CreateFullImagetxt

echo.
echo Create Full Image
echo -- Running command: "%TBIPath%\imagew64.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL"
start "" /wait "%TBIPath%\imagew64.exe" %TBIParms% /f:"%TBIBase%\%TBIName%_$~YYYY$-$~MM$-$~DD$-$~HHMM$__FULL"
goto :PostBkuptxt

:: ---------------------------------------------------------------------------

:PostBkup

set Error=%ERRORLEVEL%

echo.
echo #########################################
if not "%Error%"=="0" echo # The following error was reported: %Error%
if "%Error%"=="0" echo # No errors were reported.
echo #########################################
echo.

goto :End


:: ---------------------------------------------------------------------------

:PostBkuptxt

set Error=%ERRORLEVEL%

echo.
set TBIILast=%TBIILast%
if exist "%TBIBase%\*.tbi" for /f "delims=" %%a in ('dir "%TBIBase%\*.tbi" /od /b /p /-p /w /-w') do (set TBIILast=%%a) & (if "!TBIILast!"=="X" set TBIILast=%%a)
echo.
echo Save the name of the last image in the txt file: %TBIILast%
If not exist "%TBIBasetxt%" md "%TBIBasetxt%"
dir /b "%TBIBase%\%TBIILast%" > "%TBIBasetxt%\%TBINametxt%.txt"
echo.

echo.
echo #########################################
if not "%Error%"=="0" echo # The following error was reported: %Error%
if "%Error%"=="0" echo # No errors were reported.
echo #########################################
echo.

goto :End


:: ---------------------------------------------------------------------------

:NoWin

echo.
echo Windows 2000 or later is required for this script.
echo.
goto :End


:: ---------------------------------------------------------------------------

:End

set Error=
set Number1=
set Number2=
set TBIFullCnt=
set TBIINCRCnt=
set TBICmd=
set TBIOldest=
set TBINewest=
set TBIINCRNewest=
set TBIILast=
set TBITempName=
set TBIEndName=
set TBINewName=

endlocal

set TBIBase=
set TBIName=
set TBIParms=
set TBIPath=
set TBIMaxFullCnt=
set TBIMaxINCRCnt=
set TBIIncParms=
set TBILogin=
set TBIBasetxt=
set TBINametxt=

:: End of batch script

[/code]
Last edited by Panagiotis on Sun Jul 09, 2017 3:47 pm, edited 1 time in total.
TeraByte Support
Posts: 3596
Joined: Thu May 05, 2011 10:37 pm

Re: Incremental Rotate based on count for V3

Post by TeraByte Support »

thanks for scripts


Panagiotis
Posts: 40
Joined: Fri Mar 02, 2012 8:28 pm

Re: Incremental Rotate based on count for V3

Post by Panagiotis »

You are welcome.

I just updated the code for the registry based ones. I replaced all instances of _INCR with __INCR
and replaced the parte of the code
[code]
:CreateINCR

echo.
echo Name of the Image to use as base: "%INCRotate%.tbi"
echo.
echo Create Incremental Image
if not exist "%INCRotate%.tbi" goto :CreateFull
echo -- Running command: "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"$~INCRotate$" /f:"%TBIBase%\%TBINewest%_INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$" /savename:INCRotate
start "" /wait "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"$~INCRotate$" /f:"%TBIBase%\%TBINewest%_INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$" /savename:INCRotate
goto :PostBkup
[/code]
with
[code]
:CreateINCR

echo.
echo Name of the Image to use as base: "%INCRotate%.tbi"
echo.
echo Create Incremental Image
if not exist "%INCRotate%.tbi" goto :CreateFull
call set TBITempName=%%INCRotate:%TBIBase%\=%%
set TBIEndName=%TBITempName:*__=%
call set TBINewName=%%TBITempName:__%TBIEndName%=%%
echo -- Running command: "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"$~INCRotate$" /f:"%TBIBase%\%TBINewName%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$" /savename:INCRotate
start "" /wait "%TBIPath%\imagew.exe" /b %TBIIncParms% /base:"$~INCRotate$" /f:"%TBIBase%\%TBINewName%__INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$" /savename:INCRotate
goto :PostBkup
[/code]
Now when one restores an image and then creates a new incremental its name will still use part of the initial full name instead of using the name of the latest full image. Just pay attention to not use double,triple,etc. _ when selecting a name for your images.
eg.
This_Name_is_ok_to_use
but
This__Name__is___not____good_and_will_confuse_ the_script

Panagiotis
Panagiotis
Posts: 40
Joined: Fri Mar 02, 2012 8:28 pm

Re: Incremental Rotate based on count for V3

Post by Panagiotis »

I modified the timestamp based scripts.
I replaced all instances of _INCR with __INCR

And more important added two more settings
set TBIBasetxt=
set TBINametxt=
to define a txt file for the script to use.
If those are defined the script will use that txt file to save the last taken image name, when a new incremental is performerd it reads the txt to define the base image.
If either of the above two settings are not defined the script reverts its functionality and uses only the timestamps of the tbi's for creating the chains.

Panagiotis
Post Reply