Saturday, June 11, 2011

if you hate tape backups and need to vault (externalize), this script is for you !

If you are an happy owner of a decent RAID HBA like 3Ware, and you cannot stand tape backups, there are options : USB2 drives, ok, too slow. let's wait for USB3 compliant servers. The other option are e-SATA drives, faster, but somewhat big (the enclosure), and such a chore to take it with you.

Instead, you can choose a DTD backup (disk to disk) with the externalized set of disks manage by your internal HBA (of course you need a disk in a tray, hot pluggable) the majority of entry and middle servers have it so it should not be a problem.

So the strategy is : Backup at non production hours (if possible) to a RAID5 array.
Create a duplication job to a RAID0 1TB or 2TB disk (only one disk)
After the duplication is finished, issue a windows command to unmount the disk.
When it is done, issue a HBA CLI command to REMOVE the single RAID0 disk (not DELETE) The following script also manages rotation on five disks to ensure that the correct disk is inserted based on day.

Works well on Windows 2003 R1 R2, but on some servers i had an issue : the disk GUID would not change after replacing a disk, so test it well in you environment !
PS : tested with Symantec backup Exec

Here comes the code :



GUID_Lundi = "\\?\Volume{b33c7f05-0faa-497b-be6c-27e9be089cea}\"
GUID_Mardi = "\\?\Volume{5530f634-8fa9-11dd-99e0-40001abd57ea}\"
GUID_Mercredi = "\\?\Volume{5530f641-8fa9-11dd-99e0-40001abd57ea}\"
GUID_Jeudi = "\\?\Volume{e2a17ddf-955a-11dd-8103-4000a7d5a89c}\"
GUID_Vendredi = "\\?\Volume{e2a17de9-955a-11dd-8103-4000a7d5a89c}\"

Set ofso = createobject("scripting.filesystemobject")
set oshell = createobject("wscript.shell")
set ofile = ofso.opentextfile("c:\scripts\log.txt",8,true)



Dim Day

Day = DatePart("w", now)

ofile.writeline "script start, inventory of disks - day " & Day & " of week"
oshell.run "c:\scripts\tw_cli.exe maint rescan c0" , 0 , true
ofile.writeline "rescan controller done, waiting 30 secs"

wscript.sleep 30000

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_Volume")



For Each objItem In colItems



ofile.writeline "Found disk:"

ofile.Writeline "Device ID: " & objItem.DeviceID

ofile.Writeline "Drive Letter: " & objItem.DriveLetter

ofile.Writeblanklines 1

Select case objItem.DeviceID

Case Guid_Lundi


if day = 2 then


oshell.run "mountvol E: " & Guid_Lundi

ofile.Writeline "monday disk found - mount attempted"

wscript.sleep 30000

oshell.run "label E: BACKUP-LUNDI"

ofile.Writeline "labelling disk BACKUP-LUNDI"

Else


oshell.run "mountvol E: " & Guid_Lundi & " /d"

ofile.Writeline "wrong disk found - unmount attempted"
wscript.sleep 30000

oshell.run "c:\scripts\tw_cli.exe maint remove c0 u2",0, true

ofile.Writeline "wrong disk found - remove disk command executed"

End if



Case Guid_Mardi

if day = 3 then


oshell.run "mountvol E: " & Guid_Mardi

ofile.Writeline "tuesday disk found - mount attempted"


wscript.sleep 30000

oshell.run "label E: BACKUP-MARDI"

ofile.Writeline "labelling disk BACKUP-MARDI"

Else

oshell.run "mountvol E: " & Guid_Mardi & " /d"

ofile.Writeline "wrong disk found - unmount attempted"


wscript.sleep 30000

oshell.run "c:\scripts\tw_cli.exe maint remove c0 u2",0, true

ofile.Writeline "wrong disk found - remove disk command executed"


End if


Case Guid_Mercredi


if day = 4 then


oshell.run "mountvol E: " & Guid_Mercredi

ofile.Writeline "wednesday disk found - mount attempted"


wscript.sleep 30000

oshell.run "label E: BACKUP-MERCREDI"

ofile.Writeline "labelling disk BACKUP-MERCREDI"


Else


oshell.run "mountvol E: " & Guid_Mercredi & " /d"

ofile.Writeline "wrong disk found - unmount attempted"


wscript.sleep 30000

oshell.run "c:\scripts\tw_cli.exe maint remove c0 u2",0, true

ofile.Writeline "wrong disk found - remove disk command executed"


End if

Case Guid_Jeudi

if day = 5 then


oshell.run "mountvol E: " & Guid_Jeudi

ofile.Writeline "thursday disk found - mount attempted"


wscript.sleep 30000

oshell.run "label E: BACKUP-JEUDI"

ofile.Writeline "labelling disk BACKUP-JEUDI"


Else


oshell.run "mountvol E: " & Guid_Jeudi & " /d"

ofile.Writeline "wrong disk found - unmount attempted"


wscript.sleep 30000

oshell.run "c:\scripts\tw_cli.exe maint remove c0 u2",0, true

ofile.Writeline "wrong disk found - remove disk command executed"


End if


Case Guid_Vendredi



if day = 6 then

oshell.run "mountvol E: " & Guid_Vendredi

ofile.Writeline "friday disk found - mount attempted"

wscript.sleep 30000

oshell.run "label E: BACKUP-VENDREDI"

ofile.Writeline "labelling disk BACKUP-VENDREDI"

Else


oshell.run "mountvol E: " & Guid_Vendredi & " /d"

ofile.Writeline "wrong disk found - unmount attempted"

wscript.sleep 30000

oshell.run "c:\scripts\tw_cli.exe maint remove c0 u2",0, true

ofile.Writeline "wrong disk found - remove disk command executed"


End if


Case Else


ofile.writeline "not a listed removable backup drive, ignoring"

End Select


Next
ofile.close

No comments:

Post a Comment

Fell free to comment : share your opinion and experienced, provide feedback, help me to correct mistakes, and ask for help if you need any !