System Image .bat script - allow multiple images - WindowsImageBackup


  1. Posts : 450
    Windows 7
       #1

    System Image .bat script - allow multiple images - WindowsImageBackup


    UPDATE:

    New attachments added 01/19/2012. sysimage.bat updated to clean up a few bugs.

    sysimout.txt is an example run of a simulation (no oldest system image delete, no system image).

    sysimbkp.txt is an example of a real run to an external drive.

    See sysimage.bat or .txt prolog for thorough explanation and examples.

    *******************************************

    Now has complete space management, round-robin drive selection space option parm file usage. You can now use a parm file that contains all the drives you want images to go to, how many to take consecutively for a single drive before moving to next drive, along with the usual /S-like space management options for each drive (to control deletion of the oldest system image on the target drive just-used for the just-taken system image).

    --------------------------------------------------------

    WIB abbreviation represents WindowsImageBackup folder.


    This script (attached below) will allow multiple System Images to be kept in the prechosen (by Win7) location of:

    drive:\WindowsImageBackup\

    Multiple images are accommodated by renaming the next node (\computername\) to append the date and time pulled from the \Backup folder in the next node after that node.

    Hence, the original Win7 folder naming convention such as:

    drive:\WindowsImageBackup\joe_computer\Backup 2011-12-05 012345

    would become (propogating the date/time part to the prior directory node name):

    drive:\WindowsImageBackup\joe_computer_2011-12-05_012345\Backup 2011-12-05 012345

    Because we are monkeying with the folder name, Win7 System Image backup will do a full backup of the system drive(S) so it will take the usual (full) elapsed time, vs. a "compare" of a prior system image backup that runs much more quickly.

    The Windows Recovery Environment (RE) should see all system image folders (WindowsImageBackup):

    - on any fixed or removable (external HARD drive)

    - as long as the matching shadow entry is in the Shadow Storage area (System Volume Information folder on the MATCHING drive - see WBADMIN part of output of script)

    - and the WindowsImageBackup folder is currently on the original target drive from when the system image was taken.

    As far as Win7 is concerned, these system images are from different computers and are using the same target drive and WindowsImageBackup folder (as if 2 PCs had system images written to a single, external USB drive).

    NOTE: On the Backup and Restore "Manage Space" GUI panel, it will show no system images found (and tile greyed out/unselectable) because the computer name in the WIB folder no longer matches your computer name as it has been appended with the date and time.


    Invocation:

    Must be run from an elevated command prompt (Administrator - find cmd.exe via start orb search, right-click on cmd.exe and select "run as Administrator").

    For Task Scheduler, must be Run As Administrator (SECURITY options on the GENERAL tab, lower part - USE THE FOLLOWING ACCT and also the checkbox "run with highest privileges").

    NOTE: I have not tested via task scheduler yet.


    Parm options

    /I x
    x = N - Default=N. Potentially delete oldest folder and potentially perform a system image.
    x = Y - information only. No delete, no system image backup performed, no folders renamed.
    ...................... Y is effectively a simulation run

    /T x
    x - target drive letter (no :). Only needed if /M IMAGE (backup) is specified. /T and /S spaceoptionfile are mutually exclusive parm options.

    /S x
    x = n - Default 999 number of system images to keep for target drive before deleting oldest one
    x = nG - keep n GIGABYTES of system images on target drive before deleting oldest one
    x = "drive:\fullpathname\...spaceoptionsfile.txt" - contains sequence of drives and disk space mgmt options

    format of each entry:
    D.C.S

    NOTE: Volume name must be in double-quotes if there are embedded spaces.

    D = drive letter OR Volume name Or Volume Serial (latter 2 as shown via -fsutil fsinfo volumetype Driveletter:).

    C = # Consecutive system images to store on this drive until moving to next (potential) drive

    S = typical space parm - n = number of images, nG = Gigabytes of images

    contents example:
    D.2.46G "Iomega HDD".4.6 Scatch.1.3

    When a System Image needs to be deleted, the oldest one is chosen (amongst System Images found for the target drive). An image will only be deleted if a new image is to take place (/M IMAGE).

    Multiple older System Images may be deleted to get the target drive under the specified space threshold. This could occur, for example, the first time you use sysimage.bat but you have, let's say, 3 System Images on drive H. For the space management for H, you have the maximum images set to 2. So, to prepare for the newest System Image that's about to occur, 2 older images would have to be deleted such that the newest one will become the 2nd on on H.


    /M x
    x = NOIMAGE - Default=NOIMAGE. Do not perform a System Image.
    x = IMAGE - Perform a system image to either /Target drive or drive from space options file parm.

    /W x
    x = Your Custom WIB Folder - used to just rename or to test
    - even if you specify this, the (potential) System Image (/M IMAGE parm option) will still go to /T targetdrive (or target drive via Space Options File):\WindowsImageBackup


    Examples

    Assume script resides in D:\Scripts\sysimage.bat.

    SYNTAX:

    D:\Scripts\sysimage.bat /I Y/N /T targetdrive /S max#maxG /M IMAGE/NOIMAGE /W WIBfoldername

    In the examples shown below, we will start with basic, informational-only processing and slowly work our parm options to full-blown processing.

    - show System Image information only

    D:\Scripts\sysimage.bat /I Y


    - show System Image information for standard WindowsImageBackup folders and also a custom WIB folder

    D:\Scripts\sysimag.bat /I Y /W testwib


    - rename WindowsImagebackup folders only (no simulation can rename WIB folders, but NOIMAGE default is used)

    D:\Scripts\sysimage.bat /I N


    - simulate execution of a System Image to be stored on target drive F - keep 999 (default) images on F

    D:\Scripts\sysimage.bat /I Y /M IMAGE /T F


    - simulate execution of a System Image using target drive and space info from a parm file

    D:\Scripts\sysimage.bat /I Y /M IMAGE /S "D:\Scripts\SI parms.txt"


    - perform a System Image to target Drive G keeping 55 Gigabytes of images on drive G

    D:\Scripts\sysimage.bat /M IMAGE /T G /S 55g


    See sysimage.bat script prolog for more examples.


    For runs via Task Scheduler, it is recommended to save output to file. Use a fully-qualified path as if you invoke from Task Scheduler, the default directory at bat script initiation is c:\Windows\System32.

    D:\Scripts\sysimage.bat /parm1 X /parm2 Y /parm3 Z.... > drive:\directory...\...\sysimage.txt


    Processing flow:

    - Process parms

    - Get all fixed and removable partitions that are mounted/currently live.

    - validate parms

    - display drive information (fixed/removable)

    - Find all \Backup folders in WindowsImageBackup (standard) or user-specified /W WIB folder structure on all mounted fixed/removable disk drives.

    - TAKEOWN (ownership to admins) of all WindowsImageBackup folders on all currently-attached drives (or user-specified /W WIB)

    - Rename any \WindowsImageBackup\computername\ folders to append _YYYY-MM-DD_HHMMSS

    - List shadow storage (vssadmin command). This information can help show how much Shadow storage is used as it could prevent multiple System Images from being held/contained at one time as some Shadow Storage is used for each system image backup. Shadow storage is also shared with Restore Points. Set the shadow storage high enough via Control Panel > System > System Protection. Highlight a drive and click CONFIGURE to set the maximum disk space for a given partition's Shadow storage.

    - list System Image event information from Event Viewer

    - Display wbadmin GET VERSIONS (includes shadow information) - lists each System Image
    - display wbadmin GET ITEMS for specific version (tells what drives were backed up for this system image)
    - display any matching \Backup folder, if present in WindowsImageBackup/user /W WIB folder structure, for each System Image represented by an individual Shadow copy entry.
    - display shadow-specific information (vssadmin list Shadows /Shadow=)

    If you have an existing (via Shadow information) System Image that was written to a drive/partition that is not currently mounted, a warning message will be issued to advise you of such. Warning messages will also be displayed for orphaned (no matching Shadow entry) or wrong drive (Shadow info says System Image stored on target drive Q but a WIB entry was found on a drive other than Q).

    - Show disk spaced used for all WindowsImageBackup/user /W WIB folders and subfolders (to help manage /S option setting appropriately) and also aggregate disk space per drive

    - Potentially delete a WindowsImageBackup/user /W WIB \Backup folder (depends on /S space parm setting) provided Backup was specified via /M IMAGE parm option. The oldest of all System Images found on the just-used target drive is chosen for deletion. If /M NOIMAGE was specified (or defaulted), no delete is necessary as no impending System Image will occur.

    - Start wbadmin backup for only critical volumes (reserved and C: usually but may include drives that USER folders reside upon)

    - Verify backup complete via wbadmin GET STATUS (should return an ERROR saying none running)

    - Rename newest (e.g. just created) \WindowsImagebackup\computername\ folder to append _YYYY-MM-DD_HHMMSS

    - Update space parm option file (if so used)

    - Provide final listing showing all attached drives and any System Image folders found for those drives and their respective statuses.

    Files attached below...
    System Image .bat script - allow multiple images - WindowsImageBackup Attached Files
    Last edited by JimLewandowski; 21 Jan 2012 at 20:12.
      My Computer


  2. Posts : 450
    Windows 7
    Thread Starter
       #2

    Update for those so inclined.....
      My Computer


  3. Posts : 1
    64 windows 7 enterprise
       #3

    awesome work!
      My Computer


  4. Posts : 1
    Windows Home Premium 8.1 x64
       #4

    thanks
      My Computer


  5. Posts : 82
    Windows 7 Ultimate 64-bit
       #5

    Not working:

    **************************************
    DRIVES 0 currently mounted/active drives
    **************************************

    COMMAND fsutil fsinfo drives
    While normally they are shown:

    C:\>fsutil fsinfo drives

    Dyski: C:\ D:\ E:\ F:\ Z:\
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 13:58.
Find Us