Created
September 24, 2015 16:01
-
-
Save sosnovskyas/68877ff027d68f9ed50c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
################################################################################# | |
# # | |
# Developed by # | |
# Alexey Sosnovsky # | |
# # | |
################################################################################# | |
# 1.0 | |
# - start\stop stendbay | |
# - start\stop enviroment | |
# - recreate snapshot | |
# - recreate VG and mountpoint | |
# - | |
# 1.1 | |
# - add redirect to log | |
# - add variables link to start\stop scripts | |
# VARIABLES | |
# enviroment | |
env_name=ENV_BAK # enviroment name | |
# derictories | |
work_dir="/etc/scripts/" # script working directory full path | |
logdir="/var/log/snapshoter/" # log files directory | |
# configs | |
storage_config_file="${work_dir}xiv.cfg" | |
enviroment_config_file="${work_dir}${env_name}.cfg" # enviroment config file full path | |
# logs and reporting | |
logfile="${logdir}${env_name}_$(date +%Y%m%d_%H%M%S).log" # log file full path | |
recreating_result="OK" | |
report_mail_list="[email protected]" | |
# FUNCTIONS | |
print_msg(){ | |
echo "$(date "+%Y-%m-%d_%H:%M:%S :") $1"; | |
} | |
# INIT | |
# logs | |
if [ -d "$logdir" ]; # checking exist log files directory | |
then | |
exec > $logfile 2>&1; # redirect all printable log into logfile # redirect stdout into logfile | |
else | |
mkdir -p "$logdir"; # creating log files directory | |
exec > $logfile 2>&1; # redirect all printable log into logfile # redirect stdout into logfile | |
fi | |
print_msg "script init start"; # printing status | |
# envireoment config | |
print_msg "checking enviroment config file"; # printing status | |
if [ -e "$enviroment_config_file" ]; # checking exist enviroment config file | |
then | |
print_msg "checking enviroment config file OK"; # printing status | |
print_msg "connecting enviroment config file"; # printing status | |
. $enviroment_config_file ; # connecting enviroment config file | |
else | |
print_msg "checking enviroment config file FAIL"; # printing status | |
mail -s "$env_name CRITICAL FAIL" "$report_mail_list" < "$logfile"; # fail reporting | |
exit 1; # critical stoping script | |
fi | |
# storage config | |
print_msg "checking storage config file"; | |
if [ -e "$storage_config_file" ]; # checking exist storage config file | |
then | |
print_msg "checking storage config file OK"; # printing status | |
print_msg "connecting storage config file"; # printing status | |
. $storage_config_file; # connecting storage config file | |
else | |
print_msg "checking storage config file FAIL"; # printing status | |
mail -s "$env_name CRITICAL FAIL" "$report_mail_list" < "$logfile"; # fail reporting | |
exit 1; # critical stoping script | |
fi | |
#checking all files existing | |
print_msg "checking scripts files"; # printing status | |
if [ -e "$stdb_stop" -a -e "$stdb_start" -a -e "$env_stop" -a -e "$env_start" -a -e "$xcli" ]; # checking existing files neded for script working | |
then | |
print_msg "checking scripts files OK"; # printing status | |
else | |
print_msg "checking scripts files FAIL"; # printing status | |
mail -s "$env_name CRITICAL FAIL" "$report_mail_list" < "$logfile"; # fail reporting | |
exit 1; # critical stoping script | |
fi | |
print_msg "script init finish"; # printing status | |
# SHUTDOWN STANDBY | |
print_msg "RUN: SHUTDOWN STANDBY ${env_name}"; # printing status | |
$stdb_stop # run stoping standby script | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: SHUtDOWN STANDBY ${env_name}"; # printing status | |
# SHUTDOWN ENVIROMENT | |
print_msg "RUN: SHUTDOWN ${env_name}"; # printing status | |
$env_stop # run stoping enviroment script | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: SHUtDOWN ${env_name}"; # printing status | |
# RECREATE SNAPSHOT | |
# kill nmon for remove hdisk's | |
kill -9 $(ps -ef | grep -v $$ |grep nmon | awk '{print $2}') | |
# eject current data | |
print_msg "RUN: umounting"; # printing status | |
umount -f $mountpoint; # umounting enviroment filesystem | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else lsof=`lsof $mountpoint` print_msg "INFO: ERROR $lsof"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: umounting"; # printing status | |
# volum group varied OFF | |
print_msg "RUN: varyoff"; # printing status | |
varyoffvg $volumegroup; # disabling volume group | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: varyoff"; # printing status | |
print_msg "RUN: exportvg"; # printing status | |
exportvg $volumegroup; # exportig volume group | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: exportvg"; # printing status | |
# delete device files | |
print_msg "RUN: deleting disks"; # printing status | |
for i in $(xiv_devlist -x -t csv 2>/dev/null|grep $snap_name | awk -F, '{print $1}'|awk -F/ '{print $3}') ; # brgin deleting circle | |
do | |
rmdev -dl $i; # removing device | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
done; | |
print_msg "FINISH: deleting disks"; # printing status | |
# XIV parth - snapshot recreate | |
print_msg "RUN: snap overwrite"; # printing status | |
$xcli -m $XIV02_IP -u $XIV_USER -p $XIV_PASSWORD cg_snapshots_create cg=$snap_group overwrite=$snap_name; # sent to storage command snapshot overwrith | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: snap overwrite"; # printing status | |
# recreating device files | |
print_msg "RUN: cfgmgr"; # printing status | |
cfgmgr; # check update devices list | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: cfgmgr"; # printing status | |
# collect device files for volume group | |
device_files=$(for i in `xiv_devlist -x -t csv 2>/dev/null|grep $snap_name | awk -F, '{print $1}'|awk -F/ '{print $3}'` ; do echo " $i ";done;); # collect devices list | |
recreatevg -d $device_files; # removing volume group metadata in phisical volumes | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
recreatevg -y $volumegroup -Y $logicalvolume $device_files; # recreating volume group metadata | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: recreatevg"; # printing status | |
print_msg "RUN: mountpoint rename to $mountpoint"; # printing status | |
chfs -m $mountpoint $(lsvg $volumegroup -l |awk '/ jfs2 /{print $7}'); # change mountpoint from source to destination | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: mountpoint rename"; # printing status | |
print_msg "RUN: mounting"; # printing status | |
mount $mountpoint; # mount new mountpoint | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: mounting"; # printing status | |
# START STANDBY | |
print_msg "RUN: start standby"; # printing status | |
$stdb_start; # run stoping standby script | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: start standby"; # printing status | |
# START ENVIROMENT | |
print_msg "RUN: start ${env_name}"; # printing status | |
$env_start; # run enviroment recreating and starting script | |
if [ "$?" -eq "0" ]; then print_msg "INFO: OK"; else print_msg "INFO: ERROR"; recreating_result="ERROR"; fi; # result checking | |
print_msg "FINISH: start ${env_name}"; # printing status | |
print_msg "SCRIPT FINISHED"; # printing status | |
# REPORTING | |
mail -s "$env_name recreated $recreating_result" $report_mail_list < $logfile; # sent report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment