Commit 5affbd86 authored by Guillaume REMBERT's avatar Guillaume REMBERT

VM state added to backup + automatic VM restore + archive recovery and check + minor corrections

parent 680bff77
......@@ -9,7 +9,7 @@ EURYBOX_CORPORATE="My Corporate"
#Details level on script execution
#Can be: debug, verbose, info, warning or error
EURYBOX_LOG_LEVEL="verbose"
EURYBOX_LOG_LEVEL="info"
#Parallelism depth / depends on host CPU
EURYBOX_PARALLELISM_LEVEL="8"
#Max retry on failure before stopping execution
......@@ -19,6 +19,9 @@ EURYBOX_NETWORK_TIMEOUT="1"
#Version
EURYBOX_VERSION="1.0"
#Folder used for temporary operations
EURYBOX_TMP_FOLDER="/tmp/bkp"
##############################
### ENVIRONMENT PARAMETERS ###
##############################
......@@ -45,23 +48,23 @@ EURYBOX_SERVICES=(
[1,HOST]="192.168.123.133"
[1,PORT]="22"
[1,USER]="root"
[1,DISK]="/vm_storage/images/gw001m_hdd1.qcow2"
[1,OS]="openbsd5"
# [1,DISK]="/vm_storage/images/gw001m_dvd.iso"
## [1,SERV]="GATEWAY"
## [1,TYPE]="pf"
# [2,NAME]="srv001m"
# [2,HOST]="srv001m.$EURYBOX_DOMAIN"
# [2,PORT]="22"
# [2,USER]="root"
[2,NAME]="srv001m"
[2,HOST]="srv001m.$EURYBOX_DOMAIN"
[2,PORT]="22"
[2,USER]="root"
[2,OS]="centos7"
# [2,DISK]="/vm_storage/images/srv001m_hdd1.qcow2 /vm_storage/images/srv001m_hdd2.qcow2 /home/vm_store/service001b.qcow2"
# [2,OS]="centos7"
## [2,SERV]="DHCP"
## [2,TYPE]="dhcpd"
)
#Services number (linked to the number of parameters per service)
#Should not have to be changed
EURYBOX_SERVICES_NUMBER=`expr ${#EURYBOX_SERVICES[@]} / 6`
EURYBOX_SERVICES_NUMBER=`expr ${#EURYBOX_SERVICES[@]} / 5`
#########################
......@@ -79,9 +82,6 @@ EURYBOX_BACKUP_TYPE="vm_cold"
EURYBOX_BACKUP_LOW_WARNING_LEVEL="250000000"
EURYBOX_BACKUP_LOW_CRITICAL_LEVEL="20000000"
#Folder used for temporary operations
EURYBOX_BACKUP_TMP_FOLDER="/tmp/bkp"
#Pre-Backup Commands
#Post-Backup Commands
......@@ -115,7 +115,7 @@ EURYBOX_BACKUP_ARCHIVE=(
#FOR PAR2 ONLY
[FEC_LEVEL]="25"
#FOR ZFEC ONLY
[FEC_FILE_NUM_MIN]="5"
[FEC_FILE_NUM_MIN]="6"
)
#Backup destination
......@@ -129,12 +129,11 @@ EURYBOX_BACKUP_ARCHIVE=(
#-LOCAL: local directory
EURYBOX_BACKUP_DESTINATION=(
[PROTOCOL]="LOCAL"
# [MOUNT]="/mnt/local_backup_folder"
[MOUNT]="/mnt/new_ftp"
[MOUNT]="/home/local_bkp"
#FOR SSH AND FTP
[USER]="test"
[USER]="root"
#FOR SSH(22), FTP(21) AND NFS(2049)
[PORT]="21"
[PORT]="22"
[HOST]="10.10.10.10"
[PATH]="/mnt/backup/eurybox_archives"
#FOR NFS ONLY
......@@ -150,11 +149,14 @@ EURYBOX_BACKUP_DESTINATION=(
##########################
declare -A EURYBOX_RESTORE_TARGET_ARCHIVE
EURYBOX_RESTORE_TARGET_ACQUISITION="interactive"
EURYBOX_RESTORE_PARAMETERS_ACQUISITION="interactive"
#Can be: cloned_vm, cloned_full, full
EURYBOX_RESTORE_TYPE="cloned_vm"
#Can be: safe/fast
EURYBOX_RESTORE_MODE="safe"
#########################
### UPDATE PARAMETERS ###
......
......@@ -49,12 +49,12 @@ case $EURYBOX_BACKUP_TYPE in
###############################
eurybox_display_message message STATUS "VM Cold backup started"
#Shutdown all services vm
euryboxctrl_shutdown_services_ssh
euryboxctrl_shutdown_live_services_ssh
euryboxctrl_check_all_services_halted
#Create archive file
euryboxctrl_create_arch
#Re-Start all VMs
euryboxctrl_start_services
euryboxctrl_start_live_services
#Create errors correcting codes files
euryboxctrl_create_eccf
#Create description file
......
......@@ -57,19 +57,27 @@ case $EURYBOX_RESTORE_TYPE in
########################
# CLONE VM RESTORATION #
########################
eurybox_display_message warning STATUS "CLONE VM RESTORE NOT AVAILABLE YET"
eurybox_display_message message STATUS "VM clone restore started"
#Select VM to be restored
euryboxctrl_select_restore_vm
#Check VM to be restored
euryboxctrl_check_restore_vm
#Restore VM
euryboxctrl_restore_vm
;;
cloned_full )
#####################################
# CLONE VM + HYPERVISOR RESTORATION #
#####################################
eurybox_display_message warning STATUS "CLONE VM + HV RESTORE NOT AVAILABLE YET"
eurybox_display_message warning STATUS "CLONE VM + HV RESTORE NOT AVAILABLE YET - PLEASE PREPARE ENVIRONMENT MANUALLY"
;;
full )
########################################
# FULL SYSTEM RESTORATION + VM REFRESH #
########################################
eurybox_display_message warning STATUS "FULL RESTORE NOT AVAILABLE YET"
eurybox_display_message warning STATUS "FULL RESTORE NOT AVAILABLE YET - PLEASE PREPARE ENVIRONMENT MANUALLY"
;;
* )
eurybox_display_message warning STATUS "Unknown restoration type: $EURYBOX_RESTORE_TYPE"
......
......@@ -3,6 +3,7 @@
#INTERNAL VARIABLES
declare -A EURYBOX_DETECTED_ARCHIVES
declare -A EURYBOX_DETECTED_ARCHIVE_VMS
declare -A EURYBOX_DETECTED_DISKS
declare -A EURYBOX_DETECTED_DOMAINS
declare -A EURYBOX_DETECTED_HYPERVISOR
......
......@@ -190,6 +190,7 @@ eurybox_backup_prepare_services ()
{
local DOM_FOUND
local DISK_FOUND
local DOM_LIVE
for (( DOM_NUM=0;DOM_NUM<${EURYBOX_DETECTED_DOMAINS[NUM]};DOM_NUM++ ))
do
DOM_FOUND=0
......@@ -199,6 +200,15 @@ eurybox_backup_prepare_services ()
if [[ "${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]}" = "${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]}" ]]
then
DOM_FOUND=1
DOM_LIVE=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | grep ${EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,NAME]} 2>&1`
if [[ !($DOM_LIVE = "") ]]
then
EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,LIVE]="true"
eurybox_display_message debug BACKUP "VM ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]} - detected running"
else
EURYBOX_SERVICES[$EURYBOX_SERVICES_NUM,LIVE]="false"
eurybox_display_message debug BACKUP "VM ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]} - detected not-running"
fi
#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
......@@ -222,10 +232,11 @@ eurybox_backup_prepare_services ()
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]}"
eurybox_display_message warning BACKUP "Detected host domain is 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]}
eurybox_export_vm_config ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]} "$EURYBOX_TMP_FOLDER/${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]}.libvirt.xml"
EURYBOX_BACKUP_TARGETS[$((${#EURYBOX_BACKUP_TARGETS[@]}+1))]="$EURYBOX_TMP_FOLDER/${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]}.libvirt.xml"
fi
done
}
......
......@@ -9,6 +9,8 @@ eurybox_check_arch ()
{
local ARCH_OUT
local STATUS
local ARCH_CONTENT
local ARCH_DESC="${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},DESC]}"
local ARCH_FORMAT="${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},FORMAT]}"
local ARCH_ENC="${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},ENC]}"
local ARCH_FILE="${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},FILENAME]}.${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},FORMAT]}"
......@@ -22,7 +24,7 @@ eurybox_check_arch ()
ARCH_OUT=`sudo sh -c "openssl enc -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -d -in ${ARCH_FILE} -k ${EURYBOX_BACKUP_ARCHIVE[PASSWORD]} | tar ${TAR_OPTIONS}" 2>&1`
STATUS=$?
else
ARCH_OUT=`sudo sh -c "tar ${TAR_OPTIONS}f ${ARCH_FILE}" 2>&1`
ARCH_OUT=`sudo sh -c "tar ${TAR_OPTIONS} -f ${ARCH_FILE}" 2>&1`
STATUS=$?
fi
if [[ !($STATUS -eq 0) ]]
......@@ -30,13 +32,19 @@ eurybox_check_arch ()
eurybox_display_message warning CHECK "Archive use check failed - error $STATUS:\n$ARCH_OUT"
EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},ARCH_STATUS]="KO"
else
EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},ARCH_STATUS]="OK"
eurybox_display_message message CHECK "Archive use check - OK"
eurybox_display_message debug CHECK "Archive command output:\n$ARCH_OUT"
ARCH_CONTENT=`echo "${ARCH_DESC}" | awk '{ if(content == 1) {print $0} else { if($0 == "ARCHIVE_CONTENT:") {content=1} } }'`
if [[ $ARCH_CONTENT == $ARCH_OUT ]]
then
EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},ARCH_STATUS]="OK"
eurybox_display_message message CHECK "Archive use check - OK"
eurybox_display_message debug CHECK "Archive command output:\n$ARCH_OUT"
else
eurybox_display_message warning CHECK "Archive use check failed - error description and archive content mismatch - description content:\n$ARCH_CONTENT\ndetected archive content:\n$ARCH_OUT"
EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},ARCH_STATUS]="KO"
fi
fi
}
#Desc: check the input arguments
#TODO: implement arguments usage (debug mode / config file ...) and checking
eurybox_check_arguments ()
......@@ -122,10 +130,9 @@ eurybox_check_configuration ()
;;
esac
fi
# || $SCRIPT_TYPE = "RESTORE"
if [[ $SCRIPT_TYPE = "BACKUP" ]]
if [[ $SCRIPT_TYPE = "BACKUP" || $SCRIPT_TYPE = "RESTORE" ]]
then
#Checking backup parameters
#Checking backup target parameters
if [[ -z $EURYBOX_BACKUP_TYPE || ${#EURYBOX_BACKUP_DESTINATION[@]} -eq 0 || ${#EURYBOX_BACKUP_ARCHIVE[@]} -eq 0 || ${#EURYBOX_BACKUP_TARGETS[@]} -eq 0 ]]
then
eurybox_display_message error CHECK "Backup parameters not set: Cold/$EURYBOX_BACKUP_COLD Hot/$EURYBOX_BACKUP_HOT Destination/${EURYBOX_BACKUP_DESTINATION[*]} Archive/${EURYBOX_BACKUP_ARCHIVE[*]} Target/${EURYBOX_BACKUP_TARGETS[*]}"
......@@ -404,26 +411,27 @@ eurybox_check_environment ()
do
eurybox_check_vm_access ${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,DISK]}
done
#FOR BKP ONLY
if [[ $SCRIPT_TYPE = "BACKUP" ]]
#Check tmp folder
if [[ !(-d ${EURYBOX_TMP_FOLDER}) ]]
then
#Check tmp folder
if [[ !(-d ${EURYBOX_BACKUP_TMP_FOLDER}) ]]
sudo mkdir -p ${EURYBOX_TMP_FOLDER}
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
sudo mkdir -p ${EURYBOX_BACKUP_TMP_FOLDER}
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error CHECK "Temp folder ${EURYBOX_BACKUP_TMP_FOLDER} doesn't exists and folder creation failed"
else
eurybox_display_message message CHECK "Temp folder ${EURYBOX_BACKUP_TMP_FOLDER} successfully created"
fi
eurybox_display_message error CHECK "Temp folder ${EURYBOX_BACKUP_TMP_FOLDER} doesn't exists and folder creation failed"
else
eurybox_display_message message CHECK "Temp folder ${EURYBOX_BACKUP_TMP_FOLDER} successfully created"
fi
fi
#FOR BKP ONLY
if [[ $SCRIPT_TYPE = "BACKUP" ]]
then
#Check bkp destination (access + space left size)
eurybox_backup_mount_target
BKP_SPACE_LEFT=`sudo df -Pk ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/ | tail -1 | awk '{print $4}'`
if (( $BKP_SPACE_LEFT < $EURYBOX_BACKUP_LOW_CRITICAL_LEVEL ))
then
eurybox_backup_umount_target
eurybox_display_message error CHECK "Free space left on backup destination too low: $BKP_SPACE_LEFT kB"
else
if (( $BKP_SPACE_LEFT < $EURYBOX_BACKUP_LOW_WARNING_LEVEL ))
......@@ -433,11 +441,12 @@ eurybox_check_environment ()
eurybox_display_message debug CHECK "Free space left on backup destination OK: $BKP_SPACE_LEFT kB"
fi
fi
#Check bkp destination access (READ/WRITE)
#Check bkp destination permissions (READ/WRITE)
BKP_ACCESS_OK=`sudo sh -c "touch ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/test && rm -Rf ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/test"`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_backup_umount_target
eurybox_display_message error CHECK "Backup destination access failed: \n$BKP_ACCESS_OK"
else
eurybox_display_message debug CHECK "Backup destination access OK: \n$BKP_ACCESS_OK"
......@@ -453,6 +462,7 @@ eurybox_check_environment ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_backup_umount_target
eurybox_display_message error CHECK "Backup origin access failed: \n$BKP_ACCESS_OK"
else
eurybox_display_message debug CHECK "Backup origin access OK: \n$BKP_ACCESS_OK"
......@@ -487,6 +497,27 @@ eurybox_check_hv_access ()
fi
}
#Desc: verify the restore vm
#No arg required
eurybox_check_restore_vm ()
{
local CHECK_OUT
local VM_NAME
local ARCH_ID=${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]}
local VM_ID=${EURYBOX_RESTORE_TARGET_ARCHIVE[VM_ID]}
if [[ $VM_ID == "*" ]]
then
for (( VM_NUM=0;VM_NUM<${EURYBOX_DETECTED_ARCHIVES[$ARCH_ID,VM_NUM]};VM_NUM++ ))
do
VM_NAME=${EURYBOX_DETECTED_ARCHIVES[$ARCH_ID,$VM_NUM,NAME]}
eurybox_vm_rename $VM_NAME
done
else
VM_NAME="${EURYBOX_DETECTED_ARCHIVES[$ARCH_ID,$VM_ID,NAME]}"
eurybox_vm_rename $VM_NAME
fi
}
#Desc: check Virtual Machine access
#5 arg min required: vm_name vm_host ssh_user ssh_port disk [disk] ...
eurybox_check_vm_access ()
......@@ -499,16 +530,16 @@ eurybox_check_vm_access ()
local STATUS
local EURYBOX_DISK_OK
local EURYBOX_SSH_OK
local EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list --all | grep $NAME 2>&1`
local EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list --all | awk '{ if ($2 == name) {print $2} }' name=$NAME 2>&1`
if [[ -z "$EURYBOX_VM_NAME" ]]
then
eurybox_display_message error CHECK "VM $NAME - virsh not found"
else
eurybox_display_message debug CHECK "VM $NAME - virsh found: $EURYBOX_VM_NAME"
EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | grep $NAME`
EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | awk '{ if ($2 == name) {print $2} }' name=$NAME 2>&1`
if [[ -z "$EURYBOX_VM_NAME" ]]
then
eurybox_display_message warning CHECK "VM $NAME is not running - cannot check network configuration"
eurybox_display_message message CHECK "VM $NAME is not running - cannot check network configuration"
else
eurybox_display_message message CHECK "VM $NAME - running"
eurybox_display_message debug CHECK "$EURYBOX_VM_NAME"
......@@ -519,7 +550,7 @@ eurybox_check_vm_access ()
eurybox_display_message message CHECK "VM $NAME - SSH connection OK"
eurybox_display_message debug CHECK "SSH output:\n$EURYBOX_SSH_OK"
else
eurybox_display_message warning CHECK "VM $NAME - SSH connection failed:\n$EURYBOX_SSH_OK"
eurybox_display_message error CHECK "VM $NAME - SSH connection failed:\n$EURYBOX_SSH_OK"
fi
fi
fi
......
......@@ -8,19 +8,53 @@ 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)"
while ( !( [[ $USER_INPUT =~ $LREGEX ]]) || (( $USER_INPUT >= ${EURYBOX_DETECTED_ARCHIVES[NUM]} )) )
do
#&& (( $USER_INPUT >= ${EURYBOX_DETECTED_ARCHIVES[NUM]} )) ) ; do
eurybox_display_message warning CONFIGURE "Please enter an integer number (exs: 0 / 2 / 25) lower than ${EURYBOX_DETECTED_ARCHIVES[NUM]}"
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]} ))
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_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},FILENAME]}"
}
#Desc: specify the restoration vm through interactive input by user
#No arg required
eurybox_configure_interactive_restoration_vm ()
{
local INPUT_OK="false"
local USER_INPUT
echo "Enter VM ID target for restoration (* for all VMs):"
local LREGEX='^[0-9*].+?$'
while [[ $INPUT_OK == "false" ]]
do
read USER_INPUT
if [[ $USER_INPUT =~ $LREGEX ]]
then
if [[ $USER_INPUT == "*" ]]
then
INPUT_OK="true"
else
if (( $USER_INPUT < ${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},VM_NUM]} ))
then
INPUT_OK="true"
fi
fi
fi
if [[ $INPUT_OK == "false" ]]
then
eurybox_display_message warning CONFIGURE "Please enter an integer number (exs: 0 / 2 / 25) lower than ${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},VM_NUM]} or *"
eurybox_display_message debug CONFIGURE "Received input: $USER_INPUT"
fi
done
EURYBOX_RESTORE_TARGET_ARCHIVE[VM_ID]=$USER_INPUT
if [[ !(${EURYBOX_RESTORE_TARGET_ARCHIVE[VM_ID]} == "*") ]]
then
eurybox_display_message error CONFIGURE "Selected archive unavailable: ${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]}"
eurybox_display_message message CONFIGURE "Selected target - VM: ${EURYBOX_RESTORE_TARGET_ARCHIVE[VM_ID]} / ${EURYBOX_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},${EURYBOX_RESTORE_TARGET_ARCHIVE[VM_ID]},NAME]}"
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_DETECTED_ARCHIVES[${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]},FILENAME]}"
eurybox_display_message message CONFIGURE "Selected target - restore all VMs"
fi
}
......@@ -11,11 +11,11 @@ eurybox_create_archive_desc ()
case ${EURYBOX_BACKUP_ARCHIVE[FORMAT]} in
"tar" ) TAR_OPTIONS="-Stv";;
"tar.gz" ) TAR_OPTIONS="-Stv --use-compress-program=pigz";;
"tar.bz2" ) TAR_OPTIONS="-Stv --use-compress-program=lbzip2";;
"tar.bz2" ) TAR_OPTIONS="-Stv --use-compress-program=pbzip2";;
esac
STATUS=1234
DESTINATION=${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.desc
DESCRIPTION="ARCHIVE_CONTENT:${EURYBOX_CORPORATE}\nARCHIVE_FORMAT:${EURYBOX_BACKUP_ARCHIVE[FORMAT]}\nARCHIVE_TARGETS:${EURYBOX_BACKUP_TARGETS[*]}\nARCHIVE_TYPE:${EURYBOX_BACKUP_TYPE}\nARCHIVE_VERSION:${EURYBOX_VERSION}\nFEC_FORMAT:${EURYBOX_BACKUP_ARCHIVE[FEC]}\nHASH_FORMAT:${EURYBOX_BACKUP_ARCHIVE[HASH]}\nENCRYPTED_ARCHIVE:${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]}\n"
DESCRIPTION="ARCHIVE_CORPORATE:${EURYBOX_CORPORATE}\nARCHIVE_FORMAT:${EURYBOX_BACKUP_ARCHIVE[FORMAT]}\nARCHIVE_TARGETS:${EURYBOX_BACKUP_TARGETS[*]}\nARCHIVE_TYPE:${EURYBOX_BACKUP_TYPE}\nARCHIVE_VERSION:${EURYBOX_VERSION}\nFEC_FORMAT:${EURYBOX_BACKUP_ARCHIVE[FEC]}\nHASH_FORMAT:${EURYBOX_BACKUP_ARCHIVE[HASH]}\nENCRYPTED_ARCHIVE:${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]}\n"
if [[ ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} = "true" ]]
then
DESCRIPTION+="ENCRYPTION_ALGORITHM:${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]}\nARCHIVE_CONTENT:\n"
......@@ -25,7 +25,7 @@ eurybox_create_archive_desc ()
else
DESCRIPTION+="ARCHIVE_CONTENT:\n"
#FIXME: function to read archive with variable archive format required here
DESCRIPTION+=`sudo sh -c "tar ${TAR_OPTIONS}f ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]}" 2>&1`
DESCRIPTION+=`sudo sh -c "tar ${TAR_OPTIONS} -f ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]}" 2>&1`
STATUS=$?
fi
if [[ !($STATUS -eq 0) ]]
......@@ -93,9 +93,9 @@ eurybox_create_archive_tar ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive description FS sync failed - error: $STATUS:\n$SYNC_OUT"
eurybox_display_message warning CREATE "Archive creation FS sync failed - error: $STATUS:\n$SYNC_OUT"
else
eurybox_display_message message CREATE "Archive description FS sync - OK"
eurybox_display_message message CREATE "Archive creation FS sync - OK"
eurybox_display_message debug CREATE "Sync command output:\n$SYNC_OUT"
fi
fi
......
......@@ -2,15 +2,17 @@
#EuryBOX detect functions file
#Desc: detect archive content from description file
#1 arg required: description_file
#1 arg required: detected_archive_num
eurybox_detect_archive_content ()
{
local DESTINATION=$1
local ARCH_NUM=$1
local DESTINATION=${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,FILE]}
local BKP_ENC
local BKP_COMP
local BKP_TYPE
local BKP_VERS
local BKP_ECC
local BKP_VMS_LIST
local STATUS
local ARCH_DESC=`sudo cat $DESTINATION 2>&1`
STATUS=$?
......@@ -19,8 +21,9 @@ eurybox_detect_archive_content ()
#FIXME: STATUS IS NOT 0 WHEN FORBIDEN TO ACCESS FILE
eurybox_display_message warning DETECT "Archive description access failed: \n$ARCH_DESC"
else
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,DESC]=$ARCH_DESC
eurybox_display_message debug DETECT "Archive description access success: \n$ARCH_DESC"
BKP_ENC=`echo "${ARCH_DESC}" | grep "ENCRYPTED_ARCHIVE" | awk -F":" '($NF == "true") || ($NF == "false") {print $NF}'`
BKP_ENC=`echo "${ARCH_DESC}" | grep "ENCRYPTED_ARCHIVE" | awk -F":" '($NF == "true") || ($NF == "false") {print $NF}' 2>&1`
if [[ $BKP_ENC = "" ]]
then
eurybox_display_message warning DETECT "Archive description encryption search failed"
......@@ -28,7 +31,7 @@ eurybox_detect_archive_content ()
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,ENC]=$BKP_ENC
eurybox_display_message debug DETECT "Archive description encryption search success - found: $BKP_ENC"
fi
BKP_COMP=`echo "${ARCH_DESC}" | grep "ARCHIVE_FORMAT" | awk -F":" '{print $NF}'`
BKP_COMP=`echo "${ARCH_DESC}" | grep "ARCHIVE_FORMAT" | awk -F":" '{print $NF}' 2>&1`
case $BKP_COMP in
"" )
eurybox_display_message warning DETECT "Archive description compression/format search failed"
......@@ -47,7 +50,7 @@ eurybox_detect_archive_content ()
eurybox_display_message warning DETECT "Archive description compression/format search failed - unknown backup format found: $BKP_COMP"
;;
esac
BKP_TYPE=`echo "${ARCH_DESC}" | grep "ARCHIVE_TYPE" | awk -F":" '{print $NF}'`
BKP_TYPE=`echo "${ARCH_DESC}" | grep "ARCHIVE_TYPE" | awk -F":" '{print $NF}' 2>&1`
case $BKP_TYPE in
"" )
eurybox_display_message warning DETECT "Archive description type search failed"
......@@ -60,7 +63,7 @@ eurybox_detect_archive_content ()
eurybox_display_message warning DETECT "Archive description type search failed - unknown backup type found: $BKP_TYPE"
;;
esac
BKP_VERS=`echo "${ARCH_DESC}" | grep "ARCHIVE_VERSION" | awk -F":" '{print $NF}'`
BKP_VERS=`echo "${ARCH_DESC}" | grep "ARCHIVE_VERSION" | awk -F":" '{print $NF}' 2>&1`
case $BKP_VERS in
"" )
eurybox_display_message warning DETECT "Archive description version search failed"
......@@ -73,7 +76,7 @@ eurybox_detect_archive_content ()
eurybox_display_message warning DETECT "Archive description version search failed - unknown backup version found: $BKP_VERS"
;;
esac
BKP_ECC=`echo "${ARCH_DESC}" | grep "FEC_FORMAT" | awk -F":" '{print $NF}'`
BKP_ECC=`echo "${ARCH_DESC}" | grep "FEC_FORMAT" | awk -F":" '{print $NF}' 2>&1`
case $BKP_ECC in
"" )
eurybox_display_message warning DETECT "Archive description correcting codes search failed"
......@@ -86,7 +89,7 @@ eurybox_detect_archive_content ()
eurybox_display_message warning DETECT "Archive description correcting codes search failed - unknown backup correcting codes found: $BKP_ECC"
;;
esac
BKP_HASH=`echo "${ARCH_DESC}" | grep "HASH_FORMAT" | awk -F":" '{print $NF}'`
BKP_HASH=`echo "${ARCH_DESC}" | grep "HASH_FORMAT" | awk -F":" '{print $NF}' 2>&1`
case $BKP_HASH in
"" )
eurybox_display_message warning DETECT "Archive description hash search failed"
......@@ -99,6 +102,22 @@ eurybox_detect_archive_content ()
eurybox_display_message warning DETECT "Archive description hash search failed - unknown backup hash found: $BKP_HASH"
;;
esac
BKP_VMS_LIST=( $(echo "${ARCH_DESC}" | awk '{ if(content == 1) {print $NF} else { if($0 == "ARCHIVE_CONTENT:") {content=1} } }' | grep "libvirt.xml") )
if [[ ${BKP_VMS_LIST[@]} = "" ]]
then
eurybox_display_message warning DETECT "Archive description VMs search failed"
else
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VM_NUM]=${#BKP_VMS_LIST[@]}
eurybox_display_message debug DETECT "${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VM_NUM]} archive VM(s) found"
eurybox_display_message debug DETECT "Detected:\n${BKP_VMS_LIST[*]}"
# declare -A EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VM]
for (( VM_NUM=0;VM_NUM<${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VM_NUM]};VM_NUM++ ))
do
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,$VM_NUM,FILE]=${BKP_VMS_LIST[$VM_NUM]}
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,$VM_NUM,NAME]=`echo "${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,$VM_NUM,FILE]}" | awk -F"/" '{ print $NF }' | awk -F"." '{ for(i=1; i<(NF-1); i++) { if(i==1) { name=$i } else { name=name"."$i } } ; print name }'`
eurybox_display_message debug DETECT "Archive VM detected: ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,$VM_NUM,NAME]} / filename: ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,$VM_NUM,FILE]}"
done
fi
fi
}
......@@ -140,6 +159,9 @@ eurybox_detect_archives ()
#No arg required
eurybox_detect_libvirt_env ()
{
local NETWORKS
local DOMAINS
local DISKS
#Detect networks
NETWORKS=( $(sudo virsh $EURYBOX_VIRSH_OPTIONS net-list --all | awk '{print $1}') )
STATUS=$?
......@@ -150,7 +172,7 @@ eurybox_detect_libvirt_env ()
if [[ !($NETWORKS = "") ]]
then
EURYBOX_DETECTED_NETWORKS[NUM]=${#NETWORKS[@]}
eurybox_display_message message DETECT "Hypervisors networks - detection OK: ${EURYBOX_DETECTED_NETWORKS[NUM]} virtual network(s) found"
eurybox_display_message message DETECT "Hypervisor networks - detection OK: ${EURYBOX_DETECTED_NETWORKS[NUM]} virtual network(s) found"
for (( NET_NUM=0;NET_NUM<${EURYBOX_DETECTED_NETWORKS[NUM]};NET_NUM++ ))
do
EURYBOX_DETECTED_NETWORKS[NAME,$NET_NUM]=${NETWORKS[NET_NUM]}
......
This diff is collapsed.
......@@ -8,7 +8,7 @@ eurybox_export_hv_config ()
#Dumping network configuration
for (( NET_NUM=0;NET_NUM<${EURYBOX_DETECTED_NETWORKS[NUM]};NET_NUM++ ))
do
DESTINATION=$EURYBOX_BACKUP_TMP_FOLDER/${EURYBOX_DETECTED_NETWORKS[NAME,$NET_NUM]}.libvirt.xml
DESTINATION=$EURYBOX_TMP_FOLDER/${EURYBOX_DETECTED_NETWORKS[NAME,$NET_NUM]}.libvirt.xml
sudo sh -c "virsh $EURYBOX_VIRSH_OPTIONS net-dumpxml ${EURYBOX_DETECTED_NETWORKS[NAME,$NET_NUM]} > $DESTINATION"
STATUS=$?
if [[ !($STATUS -eq 0) ]]
......@@ -23,11 +23,11 @@ eurybox_export_hv_config ()
}
#Desc: export vm xml description
#1 arg required: vm_name
#1 arg required: vm_name destination
eurybox_export_vm_config ()
{
NAME=$1
DESTINATION=$EURYBOX_BACKUP_TMP_FOLDER/$NAME.libvirt.xml
DESTINATION=$2
sudo sh -c "virsh $EURYBOX_VIRSH_OPTIONS dumpxml $NAME > $DESTINATION"
STATUS=$?
if [[ !($STATUS -eq 0) ]]
......@@ -35,7 +35,6 @@ eurybox_export_vm_config ()
eurybox_display_message error EXPORT "Error on vm $NAME configuration dump"
else
eurybox_display_message debug EXPORT "Successfully dumped vm $NAME configuration to $DESTINATION"
EURYBOX_BACKUP_TARGETS[$((${#EURYBOX_BACKUP_TARGETS[@]}+1))]=$DESTINATION
fi
}
......
......@@ -10,6 +10,7 @@ eurybox_change_file_permissions ()
local DAC_MASK=$3
local MAC_MASK=$4
local PERMISSIONS_OUT
local LS_OPTIONS="-al"
PERMISSIONS_OUT=`sudo sh -c "sudo chmod -R $DAC_MASK $FILE" 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
......@@ -28,16 +29,20 @@ eurybox_change_file_permissions ()
eurybox_display_message message TOOLS "DAC owner changed with success"
eurybox_display_message debug TOOLS "DAC owner output command:\n$PERMISSIONS_OUT"
fi
PERMISSIONS_OUT=`sudo sh -c "sudo chcon -R $MAC_MASK $FILE" 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
if [[ $EURYBOX_DISTRIB_MAC_TYPE == "selinux" ]]
then
eurybox_display_message warning TOOLS "MAC label change failed - error $STATUS:\n$PERMISSIONS_OUT"
else
eurybox_display_message message TOOLS "MAC label changed with success"
eurybox_display_message debug TOOLS "MAC label output command:\n$PERMISSIONS_OUT"
LS_OPTIONS="-aZ"
PERMISSIONS_OUT=`sudo sh -c "sudo chcon -R $MAC_MASK $FILE" 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning TOOLS "MAC label change failed - error $STATUS:\n$PERMISSIONS_OUT"
else
eurybox_display_message message TOOLS "MAC label changed with success"
eurybox_display_message debug TOOLS "MAC label output command:\n$PERMISSIONS_OUT"
fi
fi
PERMISSIONS_OUT=`sudo sh -c "ls -aZ $FILE" 2>&1`
PERMISSIONS_OUT=`sudo sh -c "ls $LS_OPTIONS $FILE" 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
......@@ -221,6 +226,43 @@ eurybox_display_detected_archives ()
done
}
#Desc: echo detected vms from archive
#1 arg required: archive_id
eurybox_display_detected_archive_vms ()
{
local ARCH_NUM=$1
local VM_DESC
local VM_NUM=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VM_NUM]}
local NAME=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,NAME]}
local TIME=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]}
local ENC=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,ENC]}
local COMP=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,COMP]}
local TYPE=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TYPE]}
local VERS=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VERS]}
local FEC=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,FEC]}
local HASH=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,HASH]}
local YEAR=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $1 }'`
local MONTH=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $2 }'`
local DAY=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $3 }'`
local HOUR=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $4 }'`
local MINUTE=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $5 }'`
local SECOND=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $6 }'`
echo "------------ [[ ARCHIVE: $NAME ]] ------------"
echo "Date: $YEAR/$MONTH/$DAY @ $HOUR:$MINUTE:$SECOND"
echo "Encrypted: $ENC"
echo "Compression: $COMP"
echo "FEC: $FEC"
echo "Version: $VERS"
echo "Hash: $HASH"
echo "VMs: $VM_NUM"
for (( VM_NUM=0;VM_NUM<${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VM_NUM]};VM_NUM++ ))
do
NAME=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,$VM_NUM,NAME]}
echo "ID: $VM_NUM => VM: $NAME"
done
}
#Desc: execute a command through ssh
#4 args required: host port user command
eurybox_exec_ssh_command ()
......@@ -274,4 +316,3 @@ eurybox_flush_directory ()
eurybox_display_message warning TOOLS "Forbidden directory flush attempt: $T_PATH is not removable"
fi
}
#!/bin/bash
#EuryBOX vm functions file
#Desc: rename a VM through libvirt
#1 arg required: vm_name
eurybox_vm_rename ()
{
local NAME=$1
local STATUS
local DISKS
local DISKS_NUM
local NOW=$(date +"%Y_%m_%d@%H_%M_%S")
local TMP_DESC="${EURYBOX_TMP_FOLDER}/${NAME}_${NOW}"
local RENAME_OUT=`sudo virsh $EURYBOX_VIRSH_OPTIONS list --all | awk '{ if ($2 == name) {print $2} }' name=$NAME 2>&1`
STATUS=$?
if [[ $STATUS -eq 0 ]]
then
if [[ $RENAME_OUT == "" ]]
then
eurybox_display_message warning VM "Rename not possible on non-present vm: $NAME"
else
RENAME_OUT=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | awk '{ if ($2 == name) {print $2} }' name=$NAME 2>&1`
if [[ !($RENAME_OUT == "") ]]
then
eurybox_display_message warning VM "Forcing stop of running vm: $NAME"
RENAME_OUT=`sudo sh -c "virsh $EURYBOX_VIRSH_OPTIONS destroy $NAME" 2>&1`
fi
eurybox_export_vm_config $NAME $TMP_DESC
DISKS=( $(sudo virsh $EURYBOX_VIRSH_OPTIONS domblklist $NAME | awk '($2 != "-") {print $2}') )
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error VM "Error on VM description dump: $NAME - error: $STATUS:\n$DISKS"
else
if [[ !($DISKS = "") ]]