#!/bin/bash

backup_file='/root/raid-backup.cfg';

# Set log and storcli_bin lnd lspci ocations
if [[ -x /usr/local/eig_zabbix/sbin/raidcheck/bin/storcli64 ]]; then
	storcli_bin='/usr/local/eig_zabbix/sbin/raidcheck/bin/storcli64';
else
	echo "Cannot find storcli; Exiting."
	exit 1;
fi;
if [[ -x /sbin/lspci ]]; then
	lspci_bin='/sbin/lspci';
elif [[ -x /usr/bin/lspci ]]; then
	lspci_bin='/usr/bin/lspci';
else
	echo "Cannot find lspci; Exiting."
	exit 1;
fi;

# Check for MegaRAID hardware
if ! ${lspci_bin} | grep -q MegaRAID;then
        exit 1;
fi

# Backup raid configuration
for controller in $(${storcli_bin} /call/eall/sall show all | grep -oP 'Controller = \d+' | awk '{print $3}'); do
	${storcli_bin} /c${controller} get config file=${backup_file}.c${controller}
done
