Re: Script to save array info

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jun 20, 2012 at 07:21:49PM -0400, Wakko Warner wrote:
> After reading some of the stories about lost metadata, I was wondering if
> anyone had a script that would output the member info for each device with
> the device's physical serial number.
> 
> For a crude one I did this while in /sys/block:
> for x in sd*;do
> 	echo /dev/$x
> 	/lib/udev/scsi_id --export --page=0x80 --whitelisted /dev/$x
> 	mdadm -E /dev/$x
> done
> 
> And saved the output.  It works for me because all but 3 of my raid members
> are full disks.
> 

I made a script for myself, that collects the information by
inspecting /sys instead of doing mdadm -E.  The script see all mdraid
devices and all devices that belong to a mdraid.  I would like to know
if the script works or not.  It works for me.



#!/bin/bash

# $1 - procfile
# $2 - File to log
function cat-file () {
    echo $1 >> $2
    if [ -e $1 ] ; then
        ${CAT} $1 >> $2
    else
        echo "$1 don't exist" >> $2
    fi
    echo >> $2
}


FILEMD=md-list

echo "Get slot positions of the devices in mdraid" >> ${FILEMD}
for file in /sys/block/md* ; do
    echo $file    >> ${FILEMD}
    for dev in $file/md/rd* ; do
        echo $dev    >> ${FILEMD}
        ls -alF $dev >> ${FILEMD}
    done
    echo >> ${FILEMD}
done

echo "Get more info about devices in mdraid" >> ${FILEMD}
# get info about all devices that are in a mdraid.
# similar to mdadm --examine ?
for file in /sys/block/md* ; do
    echo $file    >> ${FILEMD}
    for dev in $file/md/rd* ; do
        echo $dev    >> ${FILEMD}
        ls -alF $dev >> ${FILEMD}
        for fi in $dev/* ; do
            if test `basename $fi` = "block"; then
                ls -alF $fi >> ${FILEMD}
            else
                cat-file $fi ${FILEMD}
            fi
        done
        echo >> ${FILEMD}
    done
    echo >> ${FILEMD}
done



-- 
--

     Jose Calhariz

A coisa mais difícil de entender no mundo é o imposto de renda

--Albert Einstein

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux