Incremental Rotate Scripts for "Image for Windows"

Discussion in 'backup, imaging & disk mgmt' started by pandlouk, Jul 6, 2017.

  1. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    Bellow I'll post two different scripts for creating Incremental chains for Image for Windows.

    The first one is registry based = finds the name of the image to use as base from the registry
    This one can make IFW to be used as a rollback type, since it can create various branches in a single chain.

    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.

    to use them you must edit the lines
    set TBIBase=
    set TBIName=
    set TBIParms=
    set TBIPath=
    set TBIMaxFullCnt=
    set TBIMaxINCRCnt=
    set TBIIncParms=
    set TBILogin=

    and (if you want to use the txt part of the second script edit also)
    set TBIBasetxt=
    set TBINametxt=

    according to your needs.

    note 1: copy the entire content of the script that you are interested (without the "Code:") and paste it in a txt file and then rename the extention from txt to cmd .
    note 2: if you want to use more than one of registry based scripts you should search and replace all instances of INCRotate with another name; must be different for each script e.g.
    INCRotate01, INCRotate02 and so on...

    Panagiotis
     
    Last edited: Jul 9, 2017
  2. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    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
    
    
    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
    
    
     
    Last edited: Jul 9, 2017
  3. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    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
    
    
    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
    
    
     
    Last edited: Jul 9, 2017
  4. Brian K

    Brian K Imaging Specialist

    Joined:
    Jan 28, 2005
    Posts:
    12,147
    Location:
    NSW, Australia
    Amazing scripts. Thanks.
     
  5. Peter2150

    Peter2150 Global Moderator

    Joined:
    Sep 20, 2003
    Posts:
    20,590
    Many thanks for these Panagiotis. The registry script gave me issues with Appguard, the time based on is working on my 2 desktops. They are working fine.

    What I love about them is they allow the machines be backed up with a single icon click so I can have totally inexperienced users back up my machines.

    Love it.

    Pete
     
  6. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    Glad that you like them guys.:)

    Have fun,
    Panagiotis

    ps.
    The command /wait is not needed (is included in the script)
    The command /comp:14 is not needed for V3.8 (terabyte made it the default compression level), but it is needed for v2 if you prefer Enhanced Speed A compression level.
    In these versions of the scripts I removed the /hash command to give more choices and flexibility. The previous version of the registry based script always added the command /hash even when not used in the TBIParms and TBIIncParms.
     
  7. Peter2150

    Peter2150 Global Moderator

    Joined:
    Sep 20, 2003
    Posts:
    20,590
    Hi Panagiotis

    Could you write a brief tutorial about how to determine the parameter shown.

    :: Example: set TBIParms=/b /d:w0@0x1

    set TBIParms=/b /d:w0 /hash /usemd /comp:14

    The default shown in the commented line didn't work on my system, I had to change it to what is shown in the uncommented line.

    Thanks

    Pete.
     
  8. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    Sure, I'll take some screenshots and I'll update this post...

    update:
    Ok, here we go... I assume that the users have already used IFW so I'll list only the important steps.

    Step 1: Go to the IFW settings. There you must have unchecked the "Simple Operations" box.
    Also for some motherboards that have the bad habit of changing the drive numbers at each start/reboot, it is important to check the box "Output Disk ID to command line".

    1.jpg

    Step 2: After saving the settings proceed through the various steps of performing a full backup until the last step. There check/uncheck all the boxes in the backup options that you need, compression, file size, etc., and click the button "Show Command". Then IFW will pop up a new window named "command line". Check the box "save to file" and press ok.

    2.jpg

    Step 3: In the new edit window right click with the mouse and copy the entire line to a text file.

    3.jpg

    Step 4: In this example the comand line is
    "C:\Program Files (x86)\TeraByte Drive Image Backup and Restore Suite\imagew64.exe" /wait /b /d:w0@0x2 /f:"D:\Terabyte backups\Backup-w0-0x2-$~YYYY$-$~MM$-$~DD$-$~HHMM$" /max:4GiB /v /log:0 /hash /usemd

    We are interested in the parts painted red so the final setting will be in this case the following
    set TBIParms=/b /d:w0@0x2 /max:4GiB /v /log:0 /hash /usemd

    notes:
    - the numbers @0x1,0x2,0x3 after the disk ID or the drive number, display the partitions to be included in the backup.
    - Then you perform the same steps for the "change only backup" and copy those command settings in the section "set TBIIncParms=".
    e.g.
    "C:\Program Files (x86)\TeraByte Drive Image Backup and Restore Suite\imagew64.exe" /wait /b /base:"D:\Terabyte backups\Virtualpc_2017-07-06-2027__FULL" /f:"D:\Terabyte backups\Backup-w0-0x1-chg-$~YYYY$-$~MM$-$~DD$-$~HHMM$" /max:4GiB /hash /usemd

    set TBIIncParms=/max:4GiB /v /log:0 /hash /usemd

    Or if you want to use the same settings for the full and the incremental just copy the settings that you used in the section "set TBIParms=" eliminating the "/b" and the Disk ID (or Drive Number) and partitions part.
    e.g.
    set TBIParms=/b /d:w0@0x2 /max:4GiB /v /log:0 /hash /usemd
    set TBIParms=/max:4GiB /v /log:0 /hash /usemd

    tutorial finished....

    Panagiotis

     
    Last edited: Jul 7, 2017
  9. Peter2150

    Peter2150 Global Moderator

    Joined:
    Sep 20, 2003
    Posts:
    20,590
    Once you do I will explore making it a sticky
     
  10. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    Done.
    Is it ok where it is, or should be moved in the initial post?
     
  11. Peter2150

    Peter2150 Global Moderator

    Joined:
    Sep 20, 2003
    Posts:
    20,590
    It's perfect and explains why in my case I only need w0. Was only one partition.

    Thanks my friend. It's beautiful
     
  12. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    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
    
    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
    
    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
     
  13. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    I just modified/uodated 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 and when a new incremental is performed it reads the txt to define the base image. After the image is taken it updates the content of the txt.

    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
     
  14. Peter2150

    Peter2150 Global Moderator

    Joined:
    Sep 20, 2003
    Posts:
    20,590
    Assume if older script is working fine, leave well enought alone. They are running perfectly here
     
  15. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    Either way will do.
    How it works now:
    searches to see if TBIBasetxt is defined
    - if not, goes to the timestamp part of the script (the only modification there is that instead of _INCR now it names the incremental files as __INCR.
    - if yes searches to see if the TBINametxt option is defined too.
    - if TBINametxt is not defined, goes to the timestamp part of the script.
    - if TBINametxt exists skips the timestamp part and uses only the txt part of the script.

    Just consider this new version of the script as 2 in 1.
    The timestamp part and the txt part are completely separated (the only things that have in common are the initial user settings and the naming schemes of the images).

    Panagiotis
     
  16. n8chavez

    n8chavez Registered Member

    Joined:
    Jul 19, 2003
    Posts:
    3,347
    Location:
    Location Unknown
    The only thing I would changes about the scripts is the naming convention. I prefer -INCR$~MM$-$~DD$-$~YYYY$-$~HHMM$ to _INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$ and -INCR$~MM$-$~DD$-$~YYYY$-$~HHMM$ to -FULL$~YYYY$-$~MM$-$~DD$-$~HHMM$. The issue I've having when I try to make those changes is that now every image I make is always a full image, and I can't for the life of me see where I messed up the timestamp-basedrotate script.
     
  17. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    Can you explain again? You want to change
    _INCR_$~YYYY$-$~MM$-$~DD$-$~HHMM$
    to
    -INCR$~MM$-$~DD$-$~YYYY$-$~HHMM$

    and

    -INCR$~MM$-$~DD$-$~YYYY$-$~HHMM$
    to
    -FULL$~YYYY$-$~MM$-$~DD$-$~HHMM$
    o_O
    You want to rename the incrementals as full backups? o_O
    edit:
    If I understood correctly you should search and replace all occurrences with the following order:
    1.
    Code:
    _*__FULL
    with
    Code:
    -*--FULL
    2.
    Code:
    __FULL
    with
    Code:
    --FULL
    3.
    Code:
    __INCR
    with
    Code:
    --INCR
    and 4.
    Code:
    _$~YYYY$-$~MM$-$~DD$-$~HHMM$
    with
    Code:
    -$~MM$-$~DD$-$~YYYY$-$~HHMM$
     
    Last edited: Apr 1, 2020
  18. Hadron

    Hadron Registered Member

    Joined:
    Apr 1, 2014
    Posts:
    2,138
    I nutted out the IFWRotate script with @Brian K a few months ago in the Image For Windows thread.
    I think the postings start here.

    It's a lovely script.
    It hasn't let me down.

    Thanks again, Brian. :thumb:
     
  19. n8chavez

    n8chavez Registered Member

    Joined:
    Jul 19, 2003
    Posts:
    3,347
    Location:
    Location Unknown
    Hmm. No that's not right. Essentially I just want USA date presentation, not European, where the month is first followed by the day, then year.
     
  20. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    Are you sure you want this. TerabyteUnlimited probably made this naming for easier identifying the image when shorted by name.
    So you want instead of
    $~YYYY$-$~MM$-$~DD$-$~HHMM$
    to use
    $~MM$-$~DD$-$~YYYY$-$~HHMM$
    or
    $~MM$-$~DD$-$~YYYY$
    o_O
    Use the default settings create a full and an incremental. Copy their names, then modify them with those you want and post both the original and modified names here.


    Panagiotis
     
  21. TheRollbackFrog

    TheRollbackFrog Imaging Specialist

    Joined:
    Mar 1, 2011
    Posts:
    4,954
    Location:
    The Pond - USA
    That's exactly why they use "universal" dating rather than the usual USA convoluted method.
     
  22. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    Hi froggie,

    According to wikipedia even US use it on databases.
    https://en.wikipedia.org/wiki/Date_and_time_notation_in_the_United_States
    But if @n8chavez wants to change it I can make a modified one, but I need to know the exact naming he wants. Replacing "__" with "-" is not possible (- and _ are in so many places that will break the search function of the script) unless I introduce/add other symbols, but replacing "__" with "--" can be done.

    Panagiotis
     
  23. n8chavez

    n8chavez Registered Member

    Joined:
    Jul 19, 2003
    Posts:
    3,347
    Location:
    Location Unknown
    It's just really about uniformity. For example, below is my script I use to create full system images on demand:

    Code:
    start /b  /wait "" "C:\Program Files\IFW\imagew64.exe" /b /d:w2@0x1,0x2,0x3 /f:"d:\Backups\System-$~MM$-$~DD$-$~YYYY$-$~HHMM$" /enc:3 /nt /geoa2k /pw:redacted /log:0 /comp:12 /min /hash:0
    It would be nice if both the incremental and full images could use the same naming convention, but with Full- and INCR- instrad of System-, in the rotate script. It's not needed, and working perfectly fine without it. That's just the way I'm used to things.
     
  24. pandlouk

    pandlouk Registered Member

    Joined:
    Jul 15, 2007
    Posts:
    2,976
    Is the following ok?
    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-$~MM$-$~DD$-$~YYYY$-$~HHMM$"
    start "" /wait "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBIINCRNewest%" /f:"%TBIBase%\%TBINewest%--INCR-$~MM$-$~DD$-$~YYYY$-$~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-$~MM$-$~DD$-$~YYYY$-$~HHMM$"
    start "" /wait "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBINewest%--FULL.tbi" /f:"%TBIBase%\%TBINewest%--INCR-$~MM$-$~DD$-$~YYYY$-$~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%-$~MM$-$~DD$-$~YYYY$-$~HHMM$--FULL"
    start "" /wait "%TBIPath%\imagew64.exe" %TBIParms% /f:"%TBIBase%\%TBIName%-$~MM$-$~DD$-$~YYYY$-$~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-$~MM$-$~DD$-$~YYYY$-$~HHMM$"
    start "" /wait "%TBIPath%\imagew64.exe" /b %TBIIncParms% /base:"%TBIBase%\%TBITempName%" /f:"%TBIBase%\%TBINewName%--INCR-$~MM$-$~DD$-$~YYYY$-$~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%-$~MM$-$~DD$-$~YYYY$-$~HHMM$--FULL"
    start "" /wait "%TBIPath%\imagew64.exe" %TBIParms% /f:"%TBIBase%\%TBIName%-$~MM$-$~DD$-$~YYYY$-$~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
    
    ps. Changing the name eg.
    from
    name-date-full.tbi
    name-date-incr-date.tbi
    to
    name-full-date.tbi
    name-incr-date.tbi
    would mess with the script.
    It can be done (initially during the tests I made such a script) but could easily "hit" the wall of 128 charracters command line limit, depending of the options,settings and directory depth... so I opted for a simpler and more robust naming/searching/renaming script.

    Panagiotis
     
    Last edited: Apr 2, 2020
  25. n8chavez

    n8chavez Registered Member

    Joined:
    Jul 19, 2003
    Posts:
    3,347
    Location:
    Location Unknown
    Absolutely awesome! Thank you, Panagiotis. It works perfectly.

    Also, if anyone wants the rotate script to run completely in the background, with no interaction required, just create a .vbs file like the only below:

    Code:
    Set WshShell = CreateObject("WScript.Shell" )
    WshShell.Run chr(34) & "SCRIPT LOCATION\rotate.bat" & Chr(34), 0
    Set WshShell = Nothing 
    Change SCRIPT LOCATION, and the name of your script appropriately. Then just run, or schedule, the .vbs file.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.