User:AskApache/raid-backup-log

From ArchWiki
< User:AskApache
Revision as of 05:30, 20 October 2012 by AskApache (Talk | contribs) (created first version as placeholder until figure out where it should go)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

RAID Recovery Planning

RAID is often used for critical stuff for the purpose of keeping data safe and having redundancy to prevent data from being lost if a drive fails. But problems do come up, and when/if they do it is vital that you have everything you need in order to get it fixed and back online.

Throughout this page are commands used to create logs of information on your system and RAID setup, and backups of important files and information.

The following settings are used for all the commands on this page.

DEVS="sdb sdc sdd sde sdf sdg"
PARTS="sdb1 sdc1 sdd1 sde1 sdf1 sdg1"
ARRAY="md0"
BKDIR="${HOME}/raid-backup-log-`date +%m-%d-%Y`"

Create the backup directory and cd into it.

# mkdir -pv $BKDIR && cd $BKDIR
Warning: Make sure any/all filesystems on the raid array are NOT mounted. The array should be assembled and active.

Unmount array

# unmount /dev/${ARRAY}


Backup Partitions and MBR

Backup partition table/mbr for devices

# for d in $DEVS; do dd if=/dev/${d} of=mbr-${d}.bin bs=512 count=1; done

Backup partition tables in reusable sfdisk form

# for d in $DEVS; do sfdisk -d /dev/${d} > sfdisk-table-${d}.dump; done


Disk and Partition Info

Create record of disk and partitions

# blkid -c /dev/null > blkid.log
# command lsblk -a -f -b -m -t > lsblk.log
# fdisk -l -u=sectors > fdisk-S.log
# fdisk -l -u=cylinders > fdisk-C.log
# sfdisk -R -l -u S > sfdisk-S.log
# sfdisk -R -l -u C > sfdisk-C.log
# sfdisk -R -l -u B > sfdisk-B.log



Backup Files

# cp -vf /etc/mdadm.conf etc-mdadm.conf
# cp -vf /etc/fstab etc-fstab
# cp -vf /etc/mkinitcpio.conf etc-mkinitcpio.conf
# dmesg > dmesg.log



RAID Logs

Log running arrays

# mdadm -Dv --scan > mdadm-detail-scan.log

Create record of each partition/device in array

# for p in $PARTS; do mdadm -E /dev/${p} > mdadm-examine-${p}.log; done

Backup raid sysfs info

# for f in `find -H /sys/block/${ARRAY} -type f ! -empty`; do echo -e "[ $f ]"; cat $f; done > sys-block-${ARRAY}.log

Backup raid udev info

# for d in $DEVS; do udevadm info -a -p `udevadm info -q path -n /dev/${d}*` > udev-info-${d}.log; done



Hardware Logs

Create record of system

# command lspci -vvvqq > lspci.log
# command lsusb -vvvv > lsusb.log

Log of hard-drive info

# for d in $DEVS; do hdparm -I /dev/${d} 2>&1 > hdparm-${d}.log; done

Log of smartctl info

# for d in $DEVS; do smartctl -a /dev/${d} 2>&1 > smartctl-${d}.log; done



File System Logs

Create record of filesystem built on array

# dumpe2fs /dev/${ARRAY} > dumpe2fs-${ARRAY}.log
# tune2fs -l /dev/${ARRAY} > tune2fs-${ARRAY}.log

Create record of mounts

# mount -l|sort|column -t > mounts.log

Create record of filesytem usage

# command df -aTh > df-usage.log



Shell Script

~/raid-backup.sh
## LOG DISK AND PARTITIONS

# create record of disk and partitions
blkid -c /dev/null > blkid.log
command lsblk -a -f -b -m -t > lsblk.log
fdisk -l -u=sectors > fdisk-S.log
fdisk -l -u=cylinders > fdisk-C.log
sfdisk -R -l -u S > sfdisk-S.log
sfdisk -R -l -u C > sfdisk-C.log
sfdisk -R -l -u B > sfdisk-B.log




## BACKUP FILES

cp -vf /etc/mdadm.conf etc-mdadm.conf
cp -vf /etc/fstab etc-fstab
cp -vf /etc/mkinitcpio.conf etc-mkinitcpio.conf
dmesg > dmesg.log




## LOG MDADM RAID INFO

# log running arrays
mdadm -Dv --scan > mdadm-detail-scan.log

# create record of each partition/device in array
for p in $PARTS; do mdadm -E /dev/${p} > mdadm-examine-${p}.log; done

# backup raid sysfs info
for f in `find -H /sys/block/${ARRAY} -type f ! -empty`; do echo -e "\n[ $f ]"; cat $f; done > sys-block-${ARRAY}.log

# backup raid udev info
for d in $DEVS; do udevadm info -a -p `udevadm info -q path -n /dev/${d}*` > udev-info-${d}.log; done




## LOG HARDWARE INFO

# create record of system
command lspci -vvvqq > lspci.log
command lsusb -vvvv > lsusb.log

# log of hard-drive info
for d in $DEVS; do hdparm -I /dev/${d} 2>&1 > hdparm-${d}.log; done

# log of smartctl info
for d in $DEVS; do smartctl -a /dev/${d} 2>&1 > smartctl-${d}.log; done




## LOG FILESYSTEM INFO

# create record of filesystem built on array
dumpe2fs /dev/${ARRAY} > dumpe2fs-${ARRAY}.log
tune2fs -l /dev/${ARRAY} > tune2fs-${ARRAY}.log

# create record of mounts
mount -l|sort|column -t > mounts.log

# create record of filesytem usage
command df -aTh > df-usage.log