System Image .bat script - allow multiple images - WindowsImageBackup

JimLewandowski

New member
Guru
Local time
1:24 PM
Messages
450
Location
Raleigh, NC
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...
 

Attachments

Last edited:

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom
OS
Windows 7
CPU
AMD Phenom II X2 (dual-core)
Motherboard
GA-MA785GM-US2H
Memory
4G
Graphics Card(s)
integrated ATI HD 4200
Sound Card
integrated
Monitor(s) Displays
Samsung 24"
Screen Resolution
1920x1080
Hard Drives
1 SSD - Samsung 840 - 500 GB - OS and DATA partitions
1 SSD - Intel 320 - 120 GB (used for backups) - Misc/BACKUP
1 SATA HD - WD, 500 GB - BACKUP
PSU
Ultra X4 500W
Case
Ultra X-blaster
Keyboard
Microsoft Digital Media Pro
Mouse
Logitech WIRED!
Internet Speed
15 Mbps FIOS
Update for those so inclined.....
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom
OS
Windows 7
CPU
AMD Phenom II X2 (dual-core)
Motherboard
GA-MA785GM-US2H
Memory
4G
Graphics Card(s)
integrated ATI HD 4200
Sound Card
integrated
Monitor(s) Displays
Samsung 24"
Screen Resolution
1920x1080
Hard Drives
1 SSD - Samsung 840 - 500 GB - OS and DATA partitions
1 SSD - Intel 320 - 120 GB (used for backups) - Misc/BACKUP
1 SATA HD - WD, 500 GB - BACKUP
PSU
Ultra X4 500W
Case
Ultra X-blaster
Keyboard
Microsoft Digital Media Pro
Mouse
Logitech WIRED!
Internet Speed
15 Mbps FIOS
awesome work!
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
leveno
OS
64 windows 7 enterprise
thanks
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP
OS
Windows Home Premium 8.1 x64
CPU
Intel Core i3-3110M @2.40GHz
Motherboard
HP
Graphics Card(s)
Intel HD 4000 Graphics
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

Computer Manufacturer/Model Number
Apple Mac Pro 3,1 (Model 2008)
OS
Windows 7 Ultimate 64-bit
CPU
2x Intel Xeon E5472 3.0 GHz
Motherboard
Apple - Foxconn
Memory
32 GB DDR2 FB-DIMM Micron/Hynix
Graphics Card(s)
2xATI Radeon HD5770 1 GB DDR5 XFX + Apple genuine
Sound Card
Realtek High Definition Audio
Monitor(s) Displays
Apple Cinema Display 23"
Hard Drives
1x Kingston SSDNow 40 GB
4x Kingston SSDNow S100 SS100S2/16G
2x Samsung HD502HJ 500 GB
1x Seagate ST3500418AS 500 GB
Areca ARC-1210 RAID Controller
PSU
Delta Electronics 980W
Case
Stock
Cooling
Stock
Back
Top