L'utilitaire 'mdadm' de Linux est manquant par défaut sous Windows

Vous trouverez sur le net quantité de fiches explicatives sur les bienfaits d'une infrastructure RAID 1 pour protéger ses données d'une éventuelle faille d'un disque dur. Un RAID 1 logiciel se paramètre très facilement sous Linux et le petit outil 'mdadm' permet régulièrement de vérifier l'état du RAID et, en cas d'état dégradé, d'effectuer toute action pour prévenir l'administrateur.



Sous Windows 7 Pro, la situation est un peu différente. La mise en place du RAID se fait sans trop de difficultés, mais en revanche il est impossible d'effectuer un monitoring du RAID ! Autrement dit, par défaut, impossible d'être prévenu si une panne de l'un des disques RAID est survenue... Fonction pourtant essentielle à toute personne soucieuse de l'intégrité de ses données et qui changera un disque défectueux dès que possible. Cette absence de 'monitoring du RAID' est bien dommage... ah qu'il est plaisant d'être sous Linux !

Enfin, sans se laisser démonter, il est possible d'écrire un petit script afin de pallier cette fonctionnalité (diablement importante) manquante. Voici un petit script qui ne se veut ni original ni parfait, mais qui, j'espère, aidera certains d'entre vous à être prévenus des éventuelles failles de vos disques durs.

' Software RAID status check script

Dim WshShell, oExec
Dim Line, RE0, RE1, RE2, RE3
Dim Failed

Failed = -1
' Simple variable to display status of all volumes:
' 0 = Healthy
' 1 = Rebuilding
' 2 = Failed
' 3 = Unknown

Set WshShell = WScript.CreateObject("WScript.Shell")

' Execute the DISKPART program and grab the output
set objShell = WScript.CreateObject("WScript.Shell")
set objExec = objShell.Exec("diskpart.exe")
strOutput = ExecuteDiskPartCommand("list volume")

WScript.StdOut.WriteLine(strOutput)

' Set up some regular expression objects
Set RE0 = New RegExp
Set RE1 = New RegExp
Set RE2 = New RegExp
Set RE3 = New RegExp

RE0.Pattern = "Sain"
RE1.Pattern = "Volume"
RE2.Pattern = "chou"
RE3.Pattern = "Reconstui"

        Line = strOutput

        ' Tests for Mirrored or RAID-5 volumes
        If RE1.Test(Line) Then

          ' Tests for Healthy volumes
          If RE0.Test(Line) Then
            If Failed = -1 Then Failed = 0
          End If

          If RE3.Test(Line) Then
            Failed = 1
          End If

          ' Tests for Failed RAID volumes
          If RE2.Test(Line) Then
            If Failed < 2 Then Failed = 2
          End If
        End If

' If Failed is still -1, something bad has happened, or there is no RAID
If Failed = -1 Then Failed = 3

' Print out the appropriate test result
Select Case Failed
    Case 0
      WScript.StdOut.WriteLine("RAID OK: All volumes Healthy")
    Case 1
      WScript.StdOut.WriteLine("RAID WARNING: Volume(s) Rebuilding")
    MsgBox "Le RAID est en reconstruction.",vbExclamation
    Case 2
      WScript.StdOut.WriteLine("RAID CRITICAL: Volume(s) have Failed")
    MsgBox "Il semble que le RAID soit en panne !!! ATTENTION ATTENTION !!",vbExclamation
    Case 3
      WScript.StdOut.WriteLine("UNKNOWN !")
    MsgBox "Il n'est pas possible d'évaluer l'état du RAID - une vérification manuelle s'impose !",vbExclamation
End Select

ExitDiskPart
WScript.Quit(Failed)

Function ExecuteDiskPartCommand (strCommand)

    ' Run the command we want
    objExec.StdIn.Write strCommand & VbCrLf

    ' If we read the output now, we will get the one from previous command (?). As we will always
    ' run a dummy command after every valid command, we can safely ignore this

    Do While True
        IgnoreThis = objExec.StdOut.ReadLine & vbcrlf
        ' Command finishes when diskpart prompt is shown again
        If InStr(IgnoreThis, "DISKPART>") <> 0 Then Exit Do
    Loop

    ' Run a dummy command, so the next time we call this function and try to read output,
    ' we can safely ignore the result
    objExec.StdIn.Write VbCrLf

    ' Read command's output
    ExecuteDiskPartCommand = ""
    Do While True
        ExecuteDiskPartCommand = ExecuteDiskPartCommand & objExec.StdOut.ReadLine & vbcrlf
        ' Command finishes when diskpart prompt is shown again
        If InStr(ExecuteDiskPartCommand, "DISKPART>") <> 0 Then Exit Do
    Loop
End Function


Sub ExitDiskPart
    ' Run exit command to exit the tool
    objExec.StdIn.Write "exit" & VbCrLf
End Sub