Highly Available and Scalable Information System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

369 lines
14 KiB

#!/bin/bash
#EuryBOX control functions file
euryboxctrl_check_all_vm_halted ()
{
#Check that no vm at all are still running
local EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | awk '($0 != "") {print $2}'`
if [[ !(-z "$EURYBOX_VM_NAME") ]]
then
eurybox_display_message error EURYBOXCTRL "There are still VM running: $EURYBOX_VM_NAME"
fi
}
euryboxctrl_check_all_services_halted ()
{
local EURYBOX_VM_NAME
#Check that no services vm are still running
for ((EURYBOX_SERVICES_NUM=EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM>=1;EURYBOX_SERVICES_NUM--));
do
EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | grep ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}`
if [[ !(-z "$EURYBOX_VM_NAME") ]]
then
eurybox_display_message error EURYBOXCTRL "There are still services VM running: $EURYBOX_VM_NAME"
fi
done
}
euryboxctrl_check_arch ()
{
eurybox_display_message message EURYBOXCTRL "Checking the archive file"
eurybox_check_arch
}
euryboxctrl_check_desc ()
{
eurybox_display_message warning EURYBOXCTRL "Checking the description file - NOT IMPLEMENTED YET"
}
euryboxctrl_check_eccf ()
{
eurybox_display_message message EURYBOXCTRL "Checking the error correcting codes files"
eurybox_check_eccf
}
euryboxctrl_check_hash ()
{
eurybox_display_message message EURYBOXCTRL "Checking the hash file"
eurybox_check_hash
}
euryboxctrl_check_restore_vm ()
{
eurybox_display_message message EURYBOXCTRL "Checking restore VMs"
eurybox_check_restore_vm
}
euryboxctrl_check_sign ()
{
eurybox_display_message warning EURYBOXCTRL "Checking the signature file - NOT IMPLEMENTED YET / ALWAYS OK RETURNED"
EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},SIGN_STATUS]="OK"
}
euryboxctrl_create_arch ()
{
#Create the archive
eurybox_display_message message EURYBOXCTRL "Creating the archive file"
eurybox_create_archive_tar
}
euryboxctrl_create_desc ()
{
#Create the archive description
eurybox_display_message message EURYBOXCTRL "Creating the description file"
eurybox_create_archive_desc
}
euryboxctrl_create_eccf ()
{
#Create the error correcting file
eurybox_display_message message EURYBOXCTRL "Creating the error correcting codes files"
eurybox_create_archive_fec
}
euryboxctrl_create_hash ()
{
#Create the associated hash file
eurybox_display_message message EURYBOXCTRL "Creating the hash file"
eurybox_create_archive_hash
}
euryboxctrl_create_sign ()
{
eurybox_display_message warning EURYBOXCTRL "Creating the signature file - NOT IMPLEMENTED YET"
#Create the associated signature file
#TODO: priv key / pub key infra mgt
}
euryboxctrl_discover_available_archives ()
{
local LNAME
#Mount backup target
eurybox_display_message message EURYBOXCTRL "Mounting backup origin"
eurybox_backup_mount_target
eurybox_display_message message EURYBOXCTRL "Detecting available archives"
eurybox_detect_archives ${EURYBOX_BACKUP_DESTINATION[MOUNT]}
for (( ARCH_NUM=0;ARCH_NUM<${EURYBOX_DETECTED_ARCHIVES[NUM]};ARCH_NUM++ ))
do
LNAME=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,FILE]}
eurybox_display_message message EURYBOXCTRL "Detecting archive content for ${LNAME}"
eurybox_detect_archive_content "$ARCH_NUM"
done
#unmount backup target
eurybox_display_message message EURYBOXCTRL "Unmounting backup origin"
eurybox_backup_umount_target
eurybox_display_detected_archives
}
euryboxctrl_exec_command_services ()
{
for ((EURYBOX_SERVICES_NUM=1;EURYBOX_SERVICES_NUM<=$EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM++));
do
eurybox_display_message message EURYBOXCTRL "Executing commands on ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}"
for ((EURYBOX_EXEC_COMMAND_NUM=0;EURYBOX_EXEC_COMMAND_NUM<$EURYBOX_EXEC_COMMANDS_NUMBER;EURYBOX_EXEC_COMMAND_NUM++));
do
if [[ ${EURYBOX_EXEC_COMMANDS[$EURYBOX_EXEC_COMMAND_NUM,OS]} = "all" || ${EURYBOX_EXEC_COMMANDS[$EURYBOX_EXEC_COMMAND_NUM,OS]} = ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,OS]} ]]
then
eurybox_display_message message EURYBOXCTRL "Executing command '${EURYBOX_EXEC_COMMANDS[$EURYBOX_EXEC_COMMAND_NUM,CMD]}'"
eurybox_exec_ssh_command ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,HOST]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,PORT]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,USER]} "${EURYBOX_EXEC_COMMANDS[$EURYBOX_EXEC_COMMAND_NUM,CMD]}"
else
eurybox_display_message message EURYBOXCTRL "Skipping command '${EURYBOX_EXEC_COMMANDS[$EURYBOX_EXEC_COMMAND_NUM,CMD]}' for OS ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,OS]}"
fi
done
done
}
euryboxctrl_prepare_backup ()
{
EURYBOX_BACKUP_ARCHIVE[NAME]=${EURYBOX_BACKUP_ARCHIVE[NAME]}_$(date +"%Y_%m_%d_%H_%M_%S")
#Flush temporary directory
eurybox_flush_directory $EURYBOX_TMP_FOLDER
#Detect environment
eurybox_display_message message EURYBOXCTRL "Detecting environment"
eurybox_detect_libvirt_env
#Add disks from config to backup list
eurybox_display_message message EURYBOXCTRL "Add configuration disks to backup list"
eurybox_backup_add_config_disks
#Prepare services description and dependencies for backup
eurybox_display_message message EURYBOXCTRL "Preparing services and dependencies for backup"
eurybox_backup_prepare_services
case $EURYBOX_BACKUP_TYPE in
full_cold|full_hot )
#Export hypervisor configuration
eurybox_export_hv_config
;;
esac
#Mount backup target
eurybox_display_message message EURYBOXCTRL "Mounting backup destination"
eurybox_backup_mount_target
}
euryboxctrl_prepare_restore ()
{
#Flush temporary directory
eurybox_flush_directory $EURYBOX_TMP_FOLDER
#Mount backup target
eurybox_display_message message EURYBOXCTRL "Mounting backup origin"
eurybox_backup_mount_target
case $EURYBOX_RESTORE_MODE in
safe )
#Check archive and associated files integrity
euryboxctrl_check_hash
if [[ ${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},HASH_STATUS]} = "KO" ]]
then
eurybox_display_message message EURYBOXCTRL "Trying to repair archive with FEC data"
euryboxctrl_check_eccf
if [[ ${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},ECC_STATUS]} = "KO" ]]
then
#Un-mount backup target
eurybox_display_message message EURYBOXCTRL "Unmounting backup origin"
eurybox_backup_umount_target
eurybox_display_message error EURYBOXCTRL "FEC reparation of archive failed - restoration cannot continue"
else
euryboxctrl_check_hash
if [[ ${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},HASH_STATUS]} = "KO" ]]
then
eurybox_display_message message EURYBOXCTRL "Unmounting backup origin"
eurybox_backup_umount_target
eurybox_display_message error EURYBOXCTRL "FEC reparation of archive success but hash still mismatch - restoration cannot continue"
else
eurybox_display_message message EURYBOXCTRL "Unmounting backup origin"
eurybox_backup_umount_target
eurybox_display_message error EURYBOXCTRL "Selected archive was corrupted - FEC reparation of archive has been successfull and hash verification success - restoration can be tried again"
fi
fi
else
euryboxctrl_check_sign
if [[ ${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},SIGN_STATUS]} = "KO" ]]
then
#Un-mount backup target
eurybox_display_message message EURYBOXCTRL "Unmounting backup origin"
eurybox_backup_umount_target
eurybox_display_message error EURYBOXCTRL "Signature verification of archive failed - restoration cannot continue"
else
euryboxctrl_check_arch
if [[ ${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},ARCH_STATUS]} = "KO" ]]
then
#Un-mount backup target
eurybox_display_message message EURYBOXCTRL "Unmounting backup origin"
eurybox_backup_umount_target
eurybox_display_message error EURYBOXCTRL "Hash and signature OK but archive check failed - restoration cannot continue"
else
eurybox_display_message message EURYBOXCTRL "Archive origin checks are OK - restoration can continue"
eurybox_display_detected_archive_vms ${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]}
fi
fi
fi
;;
fast )
eurybox_display_message message EURYBOXCTRL "Fast mode activated - skipping important checks before restoring - be sure when using this mode you know what you are doing"
;;
* )
eurybox_backup_umount_target
eurybox_display_message error EURYBOXCTRL "Bad configuration parameter detected: $EURYBOX_RESTORE_MODE"
;;
esac
}
euryboxctrl_restore_vm ()
{
eurybox_display_message message EURYBOXCTRL "Starting VM(s) restoration"
eurybox_restore_vm
}
euryboxctrl_select_restore_target ()
{
if [[ $EURYBOX_RESTORE_PARAMETERS_ACQUISITION = "interactive" ]]
then
eurybox_configure_interactive_restoration_target
else
eurybox_display_message warning EURYBOXCTRL "Unknown restoration target acquisition type: $EURYBOX_RESTORE_TARGET_ACQUISITION"
fi
}
euryboxctrl_select_restore_vm ()
{
if [[ $EURYBOX_RESTORE_PARAMETERS_ACQUISITION = "interactive" ]]
then
eurybox_configure_interactive_restoration_vm
else
eurybox_display_message warning EURYBOXCTRL "Unknown restoration target acquisition type: $EURYBOX_RESTORE_TARGET_ACQUISITION"
fi
}
euryboxctrl_shutdown_live_services_ssh ()
{
for ((EURYBOX_SERVICES_NUM=EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM>=1;EURYBOX_SERVICES_NUM--));
do
if [[ ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,LIVE]} == "true" ]]
then
eurybox_display_message message EURYBOXCTRL "Shutting-Down live domain via ssh ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,HOST]}"
eurybox_vm_shutdown_ssh ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,HOST]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,USER]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,PORT]}
else
eurybox_display_message message EURYBOXCTRL "Skipping shutting-down non-live domain: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}"
fi
done
}
euryboxctrl_shutdown_services_ssh ()
{
for ((EURYBOX_SERVICES_NUM=EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM>=1;EURYBOX_SERVICES_NUM--));
do
eurybox_display_message message EURYBOXCTRL "Shutting-Down via ssh ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,HOST]}"
eurybox_vm_shutdown_ssh ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,HOST]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,USER]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,PORT]}
done
}
euryboxctrl_shutdown_services_acpi ()
{
#Shutdown all services VMs
for ((EURYBOX_SERVICES_NUM=EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM>=1;EURYBOX_SERVICES_NUM--));
do
eurybox_display_message message EURYBOXCTRL "Shutting-Down via ACPI ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}"
eurybox_vm_shutdown_acpi ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}
done
}
euryboxctrl_start_services ()
{
for (( EURYBOX_SERVICES_NUM=1;EURYBOX_SERVICES_NUM<=EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM++ ))
do
eurybox_display_message message EURYBOXCTRL "Starting ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}"
eurybox_vm_start ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,HOST]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,USER]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,PORT]}
done
}
euryboxctrl_start_live_services ()
{
for (( EURYBOX_SERVICES_NUM=1;EURYBOX_SERVICES_NUM<=EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM++ ))
do
if [[ ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,LIVE]} == "true" ]]
then
eurybox_display_message message EURYBOXCTRL "Starting live domain: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}"
eurybox_vm_start ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,HOST]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,USER]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,PORT]}
else
eurybox_display_message message EURYBOXCTRL "Skipping starting non-live domain: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}"
fi
done
}
euryboxctrl_update_hypervisor ()
{
eurybox_display_message message EURYBOXCTRL "Updating physical machine / hypervisor"
eurybox_update_hv ${EURYBOX_DISTRIB_TYPE}
}
euryboxctrl_update_local_repository ()
{
eurybox_display_message message EURYBOXCTRL "Updating local repository"
eurybox_update_local_repository ${EURYBOX_DISTRIB_TYPE}
}
euryboxctrl_update_services ()
{
eurybox_display_message message EURYBOXCTRL "Updating services / virtual machines"
for ((EURYBOX_SERVICES_NUM=1;EURYBOX_SERVICES_NUM<=$EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM++));
do
eurybox_display_message message EURYBOXCTRL "Updating ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}"
eurybox_update_vm ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,HOST]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,USER]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,PORT]} ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,OS]}
done
}
euryboxctrl_terminate_backup ()
{
#Change archive files permissions
eurybox_display_message message EURYBOXCTRL "Changing archive files permissions"
eurybox_change_file_permissions "${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}*" ${EURYBOX_BACKUP_ARCHIVE[OWNER]} ${EURYBOX_BACKUP_ARCHIVE[MASK]} ${EURYBOX_BACKUP_ARCHIVE[LABEL]}
#Unmount backup target
eurybox_display_message message EURYBOXCTRL "Unmounting backup destination"
eurybox_backup_umount_target
#Flush temporary directory
eurybox_flush_directory $EURYBOX_TMP_FOLDER
}
euryboxctrl_terminate_restore ()
{
#Unmount backup target
eurybox_display_message message EURYBOXCTRL "Unmounting backup destination"
eurybox_backup_umount_target
#Flush temporary directory
eurybox_flush_directory $EURYBOX_TMP_FOLDER
}