Commit dee24edb authored by Guillaume REMBERT's avatar Guillaume REMBERT

Functions file split + several improvements

parent 391d3950
#!/bin/bash
#EuryBOX configuration file
#2015/06/25: Guillaume REMBERT, initial version based on EuryBOX prototype
###################################
### SCRIPT EXECUTION PARAMETERS ###
......@@ -17,6 +16,8 @@ EURYBOX_PARALLELISM_LEVEL="8"
EURYBOX_MAX_RETRY_ON_FAILURE="5"
#Network calls timeout (in seconds)
EURYBOX_NETWORK_TIMEOUT="1"
#Version
EURYBOX_VERSION="1.0"
##############################
### ENVIRONMENT PARAMETERS ###
......@@ -30,7 +31,7 @@ EURYBOX_DISTRIB_MAC_TYPE="selinux"
EURYBOX_DOMAIN="mydomain.mytld"
#Hypervisor parameters
#Type = xen, qemu (with and without kvm)
#Type = xen, qemu (with kvm)
EURYBOX_HYPERVISOR=(
[TYPE]="qemu"
)
......@@ -71,15 +72,12 @@ declare -A EURYBOX_BACKUP_DESTINATION
declare -A EURYBOX_BACKUP_TARGETS
declare -A EURYBOX_BACKUP_ARCHIVE
#Execute a cold backup
EURYBOX_BACKUP_COLD=true
#Execute a hot backup
EURYBOX_BACKUP_HOT=false
#Can be: vm_cold, vm_hot, full_cold, full_hot
EURYBOX_BACKUP_TYPE="vm_cold"
#Low disk space threshold (Kilo-Bytes)
EURYBOX_BACKUP_LOW_WARNING_LEVEL="250000000"
EURYBOX_BACKUP_LOW_CRITICAL_LEVEL="25000000"
EURYBOX_BACKUP_LOW_CRITICAL_LEVEL="20000000"
#Folder used for temporary operations
EURYBOX_BACKUP_TMP_FOLDER="/tmp/bkp"
......@@ -101,10 +99,10 @@ EURYBOX_BACKUP_TARGETS=(
#ECC_LEVEL = 0/1/.../99/100
#ENC_ALGO= openssl supported algo (aes-256-xts/aes-256-ctr/...)
EURYBOX_BACKUP_ARCHIVE=(
[NAME]="eurybox_archive"
[NAME]="nodeXX_archive"
[MASK]="400"
[LABEL]="backup_u:object_r:backup_t:s0"
[FORMAT]="tar.bz2"
[FORMAT]="tar"
[HASH]="sha512"
[ECC]="par2"
[ECC_LEVEL]="10"
......@@ -128,6 +126,17 @@ EURYBOX_BACKUP_DESTINATION=(
[PORT]="22"
)
##########################
### RESTORE PARAMETERS ###
##########################
declare -A EURYBOX_RESTORE_TARGET_ARCHIVE
EURYBOX_RESTORE_TARGET_ACQUISITION="interactive"
#Can be: cloned_vm, cloned_full, full
EURYBOX_RESTORE_TYPE="cloned_vm"
#########################
### UPDATE PARAMETERS ###
#########################
......
#!/bin/bash
#2015/06/25: Guillaume REMBERT
#EuryBOX backup script
START_TIME=$(date +%s)
......@@ -22,81 +21,76 @@ if [[ -f $SCRIPT_CONF_PATH && -f $SCRIPT_FUNC_PATH ]]
then
source $SCRIPT_CONF_PATH
source $SCRIPT_FUNC_PATH
eurybox_message_display debug STATUS "Configuration and function scripts successfully sourced"
eurybox_display_message debug STATUS "Configuration and function scripts successfully sourced"
else
echo "[EURYBOX][ERROR][RESSOURCES] Configuration file $SCRIPT_CONF_PATH or functions file $SCRIPT_FUNC_PATH not found. Stopping execution"
exit 1
fi
eurybox_message_display message STATUS "Checking configuration"
eurybox_display_message message STATUS "Checking configuration"
eurybox_check_configuration BACKUP
#Check input parameters
eurybox_message_display message STATUS "Checking parameters"
eurybox_display_message message STATUS "Checking parameters"
eurybox_check_arguments $SCRIPT_ARGUMENTS
#Check environment
eurybox_message_display message STATUS "Checking environment"
eurybox_display_message message STATUS "Checking environment"
eurybox_check_environment BACKUP
eurybox_message_display message STATUS "$EURYBOX_CORPORATE backup script started"
eurybox_display_message message STATUS "$EURYBOX_CORPORATE backup script started"
###############################
# VM + HYPERVISOR COLD BACKUP #
###############################
euryboxctrl_prepare_backup
#Performing a cold backup
if [ "$EURYBOX_BACKUP_COLD" = true ]
then
eurybox_message_display message STATUS "VM Cold backup started"
#Shutdown all services vm
euryboxctrl_shutdown_services_ssh
euryboxctrl_check_all_services_halted
#Create archive file
euryboxctrl_create_arch
#Re-Start all VMs
euryboxctrl_start_services
#Create errors correcting codes files
euryboxctrl_create_eccf
#Create description file
euryboxctrl_create_desc
#Create hash file
euryboxctrl_create_hash
#Create signature file
euryboxctrl_create_sign
eurybox_message_display message STATUS "Cold backup finished"
fi
case $EURYBOX_BACKUP_TYPE in
vm_cold )
###############################
# VM + HYPERVISOR COLD BACKUP #
###############################
eurybox_display_message message STATUS "VM Cold backup started"
#Shutdown all services vm
euryboxctrl_shutdown_services_ssh
euryboxctrl_check_all_services_halted
#Create archive file
euryboxctrl_create_arch
#Re-Start all VMs
euryboxctrl_start_services
#Create errors correcting codes files
euryboxctrl_create_eccf
#Create description file
euryboxctrl_create_desc
#Create hash file
euryboxctrl_create_hash
#Create signature file
euryboxctrl_create_sign
eurybox_display_message message STATUS "VM Cold backup finished"
;;
vm_hot )
#################
# VM HOT BACKUP #
#################
#Performing a hot backup
if [ "$EURYBOX_BACKUP_HOT" = true ]
then
eurybox_message_display warning STATUS "HOT BACKUP NOT AVAILABLE YET"
eurybox_display_message warning STATUS "HOT BACKUP NOT AVAILABLE YET"
#HDD
#NB: use LVM snapshot for live backup...
#NB: use LVM + VM snapshot capabilities for live backup
#NB: sync OS FS
#NB: lock DB / prepare for bkp
#CF on CentOS wiki / good KVM backup article/script example
fi
;;
full_cold|full_hot )
#######################
# VM + HV FULL BACKUP #
#######################
eurybox_display_message warning STATUS "FULL BACKUP NOT AVAILABLE YET"
;;
* )
eurybox_display_message warning STATUS "Unknown backup type: $EURYBOX_BACKUP_TYPE"
;;
esac
euryboxctrl_terminate_backup
#Finished
END_TIME=$(date +%s)
DIFF_TIME=$(( $END_TIME - $START_TIME ))
eurybox_message_display message STATUS "Backup finished"
eurybox_message_display message TIMING "Backup took $DIFF_TIME seconds"
eurybox_display_message message STATUS "Backup finished"
eurybox_display_message message TIMING "Backup took $DIFF_TIME seconds"
#!/bin/bash
#2016/04/22: Guillaume REMBERT
#EuryBOX restoration script
START_TIME=$(date +%s)
......@@ -13,7 +12,7 @@ SCRIPT_COMMAND=$(readlink -f "$0")
SCRIPT_ARGUMENTS="$@"
SCRIPT_PATH=$(dirname "$SCRIPT_COMMAND")
#Should not be changed except if you changed sw folder layout
#Should not be changed except if sw folder layout is changed
SCRIPT_CONF_PATH=$SCRIPT_PATH/../../../../../cfg/sw/eurybox.conf
SCRIPT_FUNC_PATH=$SCRIPT_PATH/../../../eurybox.functions
......@@ -22,40 +21,69 @@ if [[ -f $SCRIPT_CONF_PATH && -f $SCRIPT_FUNC_PATH ]]
then
source $SCRIPT_CONF_PATH
source $SCRIPT_FUNC_PATH
eurybox_message_display debug STATUS "Configuration and function scripts successfully sourced"
eurybox_display_message debug STATUS "Configuration and function scripts successfully sourced"
else
echo "[EURYBOX][ERROR][RESSOURCES] Configuration file $SCRIPT_CONF_PATH or functions file $SCRIPT_FUNC_PATH not found. Stopping execution"
exit 1
fi
eurybox_message_display message STATUS "Checking configuration"
eurybox_display_message message STATUS "Checking configuration"
eurybox_check_configuration RESTORE
#Check input parameters
eurybox_message_display message STATUS "Checking parameters"
eurybox_display_message message STATUS "Checking parameters"
eurybox_check_arguments $SCRIPT_ARGUMENTS
#Check environment
eurybox_message_display message STATUS "Checking environment"
eurybox_display_message message STATUS "Checking environment"
eurybox_check_environment RESTORE
eurybox_message_display message STATUS "$EURYBOX_CORPORATE restoration script started"
eurybox_display_message message STATUS "$EURYBOX_CORPORATE restoration script started"
######################
# ARCHIVES DISCOVERY #
######################
#Discover available archives
euryboxctrl_discover_available_archives
#Select archive to be restored
euryboxctrl_select_restore_target
#Check integrity of archive file
euryboxctrl_check_desc
euryboxctrl_check_hash
euryboxctrl_check_eccf
euryboxctrl_check_arch
case $EURYBOX_RESTORE_TYPE in
cloned_vm )
########################
# CLONE VM RESTORATION #
########################
eurybox_display_message warning STATUS "CLONE VM RESTORE NOT AVAILABLE YET"
;;
cloned_full )
#####################################
# CLONE VM + HYPERVISOR RESTORATION #
#####################################
eurybox_display_message warning STATUS "CLONE VM + HV RESTORE NOT AVAILABLE YET"
;;
full )
########################################
# FULL SYSTEM RESTORATION + VM REFRESH #
########################################
eurybox_display_message warning STATUS "FULL RESTORE NOT AVAILABLE YET"
;;
* )
eurybox_display_message warning STATUS "Unknown restoration type: $EURYBOX_RESTORE_TYPE"
;;
esac
#Discovering available backups
euryboxctrl_check_available_backups
################################
# VM + HYPERVISOR RESTORATION #
################################
#Finished
END_TIME=$(date +%s)
DIFF_TIME=$(( $END_TIME - $START_TIME ))
eurybox_message_display message STATUS "Restoration finished"
eurybox_message_display message TIMING "Restoration took $DIFF_TIME seconds"
eurybox_display_message message STATUS "Restoration finished"
eurybox_display_message message TIMING "Restoration took $DIFF_TIME seconds"
This diff is collapsed.
#!/bin/bash
#EuryBOX backup functions file
#Desc: add backup services targets additional disks from configuration
#No arg required
eurybox_backup_add_config_disks ()
{
for (( EURYBOX_SERVICES_NUM=1;EURYBOX_SERVICES_NUM<=EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM++ ))
do
EURYBOX_BACKUP_TARGETS[$((${#EURYBOX_BACKUP_TARGETS[@]}+1))]=${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,DISK]}
eurybox_display_message message BACKUP "VM ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]} - config file disk dependencies added to the list for backup: ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,DISK]}"
done
}
#Desc: add backup services targets automatically detected disks
#No arg required
eurybox_backup_prepare_services ()
{
for (( DOM_NUM=0;DOM_NUM<${EURYBOX_DETECTED_DOMAINS[NUM]};DOM_NUM++ ))
do
DOM_FOUND=0
#Check if detected domains are in the list for export
for (( EURYBOX_SERVICES_NUM=1;EURYBOX_SERVICES_NUM<=EURYBOX_SERVICES_NUMBER;EURYBOX_SERVICES_NUM++ ))
do
if [[ "${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]}" = "${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}" ]]
then
DOM_FOUND=1
#Add attached disks to backup list
for (( DISK_NUM=0;DISK_NUM<${EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NUM]};DISK_NUM++ ))
do
DISK_FOUND=0
#Check if not already present in backup list
for (( BKP_NUM=0;BKP_NUM<${#EURYBOX_BACKUP_TARGETS[@]};BKP_NUM++ ))
do
if [[ ${EURYBOX_BACKUP_TARGETS[${BKP_NUM}]} == *"${EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NAME,$DISK_NUM]}"* ]]
then
DISK_FOUND=1
eurybox_display_message debug BACKUP "VM ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]} - detected disk ${EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NAME,$DISK_NUM]} already in the list for backup: ${EURYBOX_BACKUP_TARGETS[${BKP_NUM}]}"
fi
done
if [[ $DISK_FOUND -eq 0 ]]
then
EURYBOX_BACKUP_TARGETS[$((${#EURYBOX_BACKUP_TARGETS[@]}+1))]=${EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NAME,$DISK_NUM]}
eurybox_display_message message PREPARE "VM ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]} - detected disk added to the list for backup: ${EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NAME,$DISK_NUM]}"
fi
done
fi
done
if [[ $DOM_FOUND -eq 0 ]]
then
eurybox_display_message warning BACKUP "Detected domain not in the list for backup: ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]}"
else
eurybox_display_message message BACKUP "VM ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]} - prepared for backup"
eurybox_export_vm_config ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]}
fi
done
}
This diff is collapsed.
#!/bin/bash
#EuryBOX configuration functions file
#Desc: specify the restoration target through interactive input by user
#No arg required
eurybox_configure_interactive_restoration_target ()
{
echo "Enter archive ID target for restoration:"
read USER_INPUT
LREGEX='^[0-9].+?$'
while ! [[ $USER_INPUT =~ $LREGEX ]]; do
eurybox_display_message warning CONFIGURE "Please enter an integer number (exs: 0 / 2 / 25)"
eurybox_display_message debug CONFIGURE "Received input: $USER_INPUT"
read USER_INPUT
done
EURYBOX_RESTORE_TARGET_ARCHIVE[ID]=$USER_INPUT
if (( ${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]} >= ${EURYBOX_DETECTED_ARCHIVES[NUM]} ))
then
eurybox_display_message error CONFIGURE "Selected archive unavailable: ${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]}"
else
EURYBOX_BACKUP_ARCHIVE[NAME]="${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},VERSION]}"
eurybox_display_message message CONFIGURE "Selected archive: ${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]} / ${EURYBOX_BACKUP_ARCHIVE[NAME]}"
fi
}
This diff is collapsed.
#!/bin/bash
#EuryBOX detect functions file
#Desc: detect archive content from description file
#TODO: implement archive access method abstraction
#7 args required: bkp_protocol bkp_path bkp_arch bkp_mount bkp_port bkp_user bkp_host
eurybox_detect_archive_content ()
{
BKP_PROTOCOL=$1
BKP_DEST=$2
BKP_ARCH=$3
BKP_MOUNT=$4
BKP_PORT=$5
BKP_USER=$6
BKP_HOST=$7
case $BKP_PROTOCOL in
"SSH" )
DESTINATION=$BKP_DEST/$BKP_ARCH
ARCH_DESC=`ssh $EURYBOX_SSH_OPTIONS -p $BKP_PORT $BKP_USER@$BKP_HOST "cat $DESTINATION" 2>&1`
STATUS=$?
;;
"NFS" )
DESTINATION=$BKP_MOUNT/$BKP_ARCH*
eurybox_mount_backup_nfs
ARCH_DESC=`sudo cat $DESTINATION 2>&1`
STATUS=$?
eurybox_umount_backup_nfs
;;
* )
eurybox_display_message error DETECT "Unkown backup destination protocol: $BKP_PROTOCOL"
;;
esac
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error DETECT "Archive description access failed: $ARCH_DESC"
else
BKP_ENC=`echo "${ARCH_DESC}" | grep "ENCRYPTED_ARCHIVE" | awk -F":" '($NF == "true") || ($NF == "false") {print $NF}'`
if [[ $BKP_ENC = "" ]]
then
eurybox_display_message error DETECT "Archive description encryption activated search failed"
else
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,ENC]=$BKP_ENC
eurybox_display_message debug DETECT "Archive description encryption activated search success - found: $BKP_ENC"
fi
fi
}
#Desc: detect if there are archive in specified directory
#TODO: implement archive access method abstraction
#7 args required: bkp_protocol bkp_path bkp_arch bkp_mount bkp_port bkp_user bkp_host
eurybox_detect_archives ()
{
BKP_PROTOCOL=$1
BKP_DEST=$2
BKP_ARCH=$3
BKP_MOUNT=$4
BKP_PORT=$5
BKP_USER=$6
BKP_HOST=$7
case $BKP_PROTOCOL in
"SSH" )
DESTINATION=$BKP_DEST/$BKP_ARCH
FILES_LIST=`ssh $EURYBOX_SSH_OPTIONS -p $BKP_PORT $BKP_USER@$BKP_HOST "ls $EURYBOX_LS_OPTIONS $DESTINATION"`
STATUS=$?
;;
"NFS" )
DESTINATION=$BKP_MOUNT/$BKP_ARCH
eurybox_mount_backup_nfs
FILES_LIST=`sudo ls $EURYBOX_LS_OPTIONS $DESTINATION`
STATUS=$?
eurybox_umount_backup_nfs
;;
* )
eurybox_display_message error DETECT "Unkown backup destination protocol: $BKP_PROTOCOL"
;;
esac
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error DETECT "Archive description listing not found: $BKP_LIST"
else
#Filter by desc extension, extract filename and store in an array
BKP_LIST=( $(echo "$FILES_LIST" | awk -F"." '($NF == "desc") {print $0}' | awk -F"/" '{print $NF}') )
if [[ ${BKP_LIST[@]} = "" ]]
then
eurybox_display_message error DETECT "No archive found"
else
EURYBOX_DETECTED_ARCHIVES[NUM]=${#BKP_LIST[@]}
eurybox_display_message message DETECT "${EURYBOX_DETECTED_ARCHIVES[NUM]} archive descriptions found"
for (( ARCH_NUM=0;ARCH_NUM<${EURYBOX_DETECTED_ARCHIVES[NUM]};ARCH_NUM++ ))
do
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,FILE]=${BKP_LIST[$ARCH_NUM]}
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VERSION]=`echo "${BKP_LIST[$ARCH_NUM]}" | awk -F"." '{ for(i=1; i<(NF); i++) { if(i==1) { version=$i } else { version=version"."$i } } ; print version }'`
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,NAME]=`echo "${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VERSION]}" | awk -F"_" '{ for(i=1; i<(NF-5); i++) { if(i==1) { name=$i } else { name=name"_"$i } } ; print name }'`
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]=`echo "${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VERSION]}" | awk -F"_" '{ for(i=(NF-5); i<=NF; i++) { if(i==(NF-5)) { name=$i } else { name=name"_"$i } } ; print name }'`
eurybox_display_message debug DETECT "Archive detected: ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,NAME]} / timestamp: ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} / version: ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VERSION]} / filename: ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,FILE]}"
done
fi
fi
}
#Desc: detect the libvirt environment
#No arg required
eurybox_detect_libvirt_env ()
{
#Detect networks
# NETWORKS=( $(sudo virsh $EURYBOX_VIRSH_OPTIONS net-list --all | awk 'NR>2 {print $1}') )
NETWORKS=( $(sudo virsh $EURYBOX_VIRSH_OPTIONS net-list --all | awk '{print $1}') )
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error DETECT "Error on hypervisor network detection"
else
if [[ !($NETWORKS = "") ]]
then
EURYBOX_DETECTED_NETWORKS[NUM]=${#NETWORKS[@]}
eurybox_display_message message DETECT "Hypervisors networks - detection OK: ${EURYBOX_DETECTED_NETWORKS[NUM]} founds"
for (( NET_NUM=0;NET_NUM<${EURYBOX_DETECTED_NETWORKS[NUM]};NET_NUM++ ))
do
EURYBOX_DETECTED_NETWORKS[NAME,$NET_NUM]=${NETWORKS[NET_NUM]}
eurybox_display_message debug DETECT "Network detected: ${EURYBOX_DETECTED_NETWORKS[NAME,$NET_NUM]}"
done
else
eurybox_display_message warning DETECT "No hypervisor network detected"
fi
fi
#Detect domains
DOMAINS=( $(sudo virsh $EURYBOX_VIRSH_OPTIONS list --all | awk '{print $2}') )
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error DETECT "Error on hypervisor domain detection"
else
if [[ !($DOMAINS = "") ]]
then
EURYBOX_DETECTED_DOMAINS[NUM]=${#DOMAINS[@]}
eurybox_display_message message DETECT "Hypervisor domains (VM) - detection OK: ${EURYBOX_DETECTED_DOMAINS[NUM]} founds"
for (( DOM_NUM=0;DOM_NUM<${EURYBOX_DETECTED_DOMAINS[NUM]};DOM_NUM++ ))
do
EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]=${DOMAINS[DOM_NUM]}
eurybox_display_message debug DETECT "VM detected: ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]}"
done
else
eurybox_display_message warning DETECT "No hypervisor domain detected"
fi
fi
#Detect disks associated to each domain
for (( DOM_NUM=0;DOM_NUM<${EURYBOX_DETECTED_DOMAINS[NUM]};DOM_NUM++ ))
do
DISKS=( $(sudo virsh $EURYBOX_VIRSH_OPTIONS domblklist ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]} | awk '($2 != "-") {print $2}') )
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error DETECT "Error on VM disk detection: ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]}"
else
if [[ !($DISKS = "") ]]
then
EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NUM]=${#DISKS[@]}
eurybox_display_message message DETECT "VM ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]} - ${EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NUM]} disks founds"
for (( DISK_NUM=0;DISK_NUM<${EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NUM]};DISK_NUM++ ))
do
EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NAME,$DISK_NUM]=${DISKS[DISK_NUM]}
eurybox_display_message debug DETECT "VM ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]} - disk detected: ${EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NAME,$DISK_NUM]}"
done
else
eurybox_display_message warning DETECT "No domain disk detected for VM ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]}"
fi
fi
done
}
#!/bin/bash
#EuryBOX control functions file
euryboxctrl_check_all_vm_halted ()
{
#Check that no vm at all are still running
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 ()
{
#Check that no vm at all are still running
## EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | awk '(NR>2) && ($0 != "") {print $2}'`
#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 warning EURYBOXCTRL "Checking the archive file - NOT IMPLEMENTED YET"
}
euryboxctrl_check_desc ()
{
eurybox_display_message warning EURYBOXCTRL "Checking the description file - NOT IMPLEMENTED YET"
}
euryboxctrl_check_eccf ()
{
eurybox_display_message warning EURYBOXCTRL "Checking the error correcting codes files - NOT IMPLEMENTED YET"
}
euryboxctrl_check_hash ()
{
eurybox_display_message warning EURYBOXCTRL "Checking the hash file - NOT IMPLEMENTED YET"
}
euryboxctrl_check_sign ()
{
eurybox_display_message warning EURYBOXCTRL "Checking the signature file - NOT IMPLEMENTED YET"
}
euryboxctrl_create_arch ()
{
#Create the archive
eurybox_display_message message EURYBOXCTRL "Creating the archive file"
case "${EURYBOX_BACKUP_ARCHIVE[FORMAT]}" in
tar|tar.gz|tar.bz2 )
eurybox_create_archive_tar
;;
* )
eurybox_display_message error EURYBOXCTRL "Archive format unknown: ${EURYBOX_BACKUP_ARCHIVE[FORMAT]}."
;;
esac
#Flush temporary directory
eurybox_flush_directory $EURYBOX_BACKUP_TMP_FOLDER
}
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"
case "${EURYBOX_BACKUP_ARCHIVE[ECC]}" in
par2 )
eurybox_create_archive_par
;;
* )
eurybox_display_message error EURYBOXCTRL "Archive ECC type unknown: ${EURYBOX_BACKUP_ARCHIVE[ECC]}."
;;
esac
}
euryboxctrl_create_hash ()
{
#Create the associated hash file
eurybox_display_message message EURYBOXCTRL "Creating the hash file"
case "${EURYBOX_BACKUP_ARCHIVE[HASH]}" in
sha256|sha512 )
eurybox_create_archive_sha
;;
* )
eurybox_display_message error EURYBOXCTRL "Archive HASH type unknown: ${EURYBOX_BACKUP_ARCHIVE[HASH]}."
;;
esac
}
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 ()
{
eurybox_detect_archives ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]} ${EURYBOX_BACKUP_DESTINATION[PATH]} "*" ${EURYBOX_BACKUP_DESTINATION[MOUNT]} ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]} ${EURYBOX_BACKUP_DESTINATION[HOST]}
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")
#Detect environment
eurybox_detect_libvirt_env
#Add disks from config to backup list
eurybox_backup_add_config_disks
#Prepare services description 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
}
euryboxctrl_select_restore_target ()
{
if [[ $EURYBOX_RESTORE_TARGET_ACQUISITION = "interactive" ]]
then