Commit 031c3950 authored by Guillaume REMBERT's avatar Guillaume REMBERT

Variable dependencies check + local repository management + missing restore functions file commit

parent 5affbd86
......@@ -10,8 +10,6 @@ EURYBOX_CORPORATE="My Corporate"
#Details level on script execution
#Can be: debug, verbose, info, warning or error
EURYBOX_LOG_LEVEL="info"
#Parallelism depth / depends on host CPU
EURYBOX_PARALLELISM_LEVEL="8"
#Max retry on failure before stopping execution
EURYBOX_MAX_RETRY_ON_FAILURE="5"
#Network calls timeout (in seconds)
......@@ -26,13 +24,15 @@ EURYBOX_TMP_FOLDER="/tmp/bkp"
### ENVIRONMENT PARAMETERS ###
##############################
#Can be: centos (6.x | 7.X), redhat (6.x | 7.X) #TO BE TESTED: fedora, opensuse, ubuntu, debian, archlinux, gentoo
EURYBOX_DISTRIB_TYPE="centos"
EURYBOX_DISTRIB_VERSION="7.2"
EURYBOX_DISTRIB_MAC_TYPE="selinux"
#DNS
EURYBOX_DOMAIN="mydomain.mytld"
#Host parameters
#Distrib type = archlinux, centos5, centos6, centos7, debian6, debian7, debian8, fedora20, fedora21, fedora22, fedora23, gentoo, redhat5, redhat6, redhat7, ubuntu12, ubuntu14, ubuntu16
#MAC type = none, selinux
EURYBOX_DISTRIB_TYPE="centos7"
EURYBOX_DISTRIB_MAC_TYPE="selinux"
#Hypervisor parameters
#Type = xen, qemu (with kvm)
EURYBOX_HYPERVISOR=(
......@@ -41,7 +41,7 @@ EURYBOX_HYPERVISOR=(
#Services parameters
#Disks are autodetected
#Supported OS yet (for update): archlinux, centos5, centos6, centos7, debian6, debian7, debian8, fedora20, fedora21, fedora22, fedora23, gentoo, redhat5, redhat6, redhat7, ubuntu12, ubuntu14, ubuntu16
#Supported OS (for update): archlinux, centos5, centos6, centos7, debian6, debian7, debian8, fedora20, fedora21, fedora22, fedora23, gentoo, redhat5, redhat6, redhat7, ubuntu12, ubuntu14, ubuntu16
declare -A EURYBOX_SERVICES
EURYBOX_SERVICES=(
[1,NAME]="gw001m"
......@@ -99,7 +99,7 @@ EURYBOX_BACKUP_TARGETS=(
#FEC_FILE_NUM = 1/2/...
#FEC_LEVEL = 0/1/.../99/100
#FEC_FILE_NUM_MIN = 1/2/... (<= FEC_FILE_NUM)
#ENC_ALGO= openssl supported algo (aes-256-xts/aes-256-ctr/...)
#ENC_ALGO= openssl continuous block encryption supported algo (aes-256-ctr/camellia-256-cbc/blowfish/...)
EURYBOX_BACKUP_ARCHIVE=(
[NAME]="nodeXX_archive"
[OWNER]="root:root"
......@@ -124,7 +124,7 @@ EURYBOX_BACKUP_ARCHIVE=(
#-SSH: ssh client/server configuration done at system level (.ssh local files) + local mount point provided by sshfs. Password authentication capability has been enforced as disabled by command options
#-NFS: nfs client/server configuration + local mount point provided by kernel.
#-ISCSI: TODO - iSCSI target/initiator configuration + local mount point provided by TBD
#-FTP: ftp client/server authentication (user/password TODO? certs/.netrc/other) + mount provided by curlftpfs.
#-FTP: ftp client/server authentication (user/password - TODO? certs/.netrc/other) + mount provided by curlftpfs.
#-PART: local unmounted partition or raw device (as USB device, additional disks, ...) + local mount point provided by kernel. TODO: LUKS encrypted partition provided by kernel and cryptsetup tool
#-LOCAL: local directory
EURYBOX_BACKUP_DESTINATION=(
......@@ -147,7 +147,6 @@ EURYBOX_BACKUP_DESTINATION=(
##########################
### RESTORE PARAMETERS ###
##########################
declare -A EURYBOX_RESTORE_TARGET_ARCHIVE
EURYBOX_RESTORE_PARAMETERS_ACQUISITION="interactive"
......@@ -161,7 +160,35 @@ EURYBOX_RESTORE_MODE="safe"
#########################
### UPDATE PARAMETERS ###
#########################
declare -A EURYBOX_UPDATE_LOCAL_REPOSITORIES
EURYBOX_UPDATE_LOCAL_REPOSITORIES_PATH="/home/local_repositories"
#NB: URI scheme follow rsync conventions / read rsync man to get all details
EURYBOX_UPDATE_LOCAL_REPOSITORIES=(
[1,NAME]="centos7"
[1,ARCH]="x86_64"
[1,URI]="centos.mirrors.ovh.net::ftp.centos.org/7/"
[2,NAME]="openbsd59"
[2,ARCH]="amd64"
[2,URI]="ftp.fr.openbsd.org::OpenBSD/5.9/"
[3,NAME]="gentoo"
[3,ARCH]=""
[3,URI]="rsync.gentoo.org::gentoo-portage/"
[4,NAME]="archlinux"
[4,ARCH]="x86_64"
[4,URI]="fooo.biz::archlinux/"
[5,NAME]="ubuntu16"
[5,ARCH]="amd64"
[5,URI]="archive.ubuntu.com::ubuntu/dists/xenial/"
[6,NAME]="fedora24"
[6,ARCH]="x86_64"
[6,URI]="fr2.rpmfind.net::linux/fedora/linux/releases/24/"
[7,NAME]="debian8"
[7,ARCH]="arm64"
[7,URI]="ftp.fr.debian.org::debian/dists/jessie/"
)
EURYBOX_UPDATE_LOCAL_REPOSITORIES_NUMBER=`expr ${#EURYBOX_UPDATE_LOCAL_REPOSITORIES[@]} / 3`
###############################
### EXEC COMMAND PARAMETERS ###
......
#!/bin/bash
#2015/06/27: Guillaume REMBERT
#EuryBOX exec commands script
START_TIME=$(date +%s)
......@@ -22,23 +21,23 @@ 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 EXEC_COMMAND
#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 EXEC_COMMAND
eurybox_message_display message STATUS "$EURYBOX_CORPORATE execute commands script started"
eurybox_display_message message STATUS "$EURYBOX_CORPORATE execute commands script started"
#Start all VMs
euryboxctrl_start_services
......@@ -49,5 +48,5 @@ euryboxctrl_exec_command_services
#Finished
END_TIME=$(date +%s)
DIFF_TIME=$(( $END_TIME - $START_TIME ))
eurybox_message_display message STATUS "Commands execution finished"
eurybox_message_display message TIMING "Commands execution took $DIFF_TIME seconds"
eurybox_display_message message STATUS "Commands execution finished"
eurybox_display_message message TIMING "Commands execution took $DIFF_TIME seconds"
......@@ -15,6 +15,7 @@ declare -A EURYBOX_DETECTED_SECRETS
declare -A EURYBOX_DETECTED_SNAPSHOTS
declare -A EURYBOX_DETECTED_STORAGE_POOLS
declare -A EURYBOX_DETECTED_STORAGE_VOLUMES
declare -A EURYBOX_RESTORE_TARGET_ARCHIVE
#Detect and source all function files
FUNCTIONS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
......
......@@ -49,7 +49,7 @@ eurybox_backup_mount_target ()
then
eurybox_display_message error BACKUP "Target local mount point directory $BKP_MOUNT doesn't exists and folder creation failed - error $STATUS:\n$MKDIR_OUT"
else
local CHMOD_OUT=`sudo chmod 777 $BKP_MOUNT 2>&1`
local CHMOD_OUT=`sudo chmod -R 777 $BKP_MOUNT 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
......
#!/bin/bash
#EuryBOX check functions file
#TODO: Implement lockfile and check if not already running
#Desc: verify the archive access and content
#No arg required
eurybox_check_arch ()
......@@ -76,17 +74,15 @@ eurybox_check_configuration ()
local -i SCRIPT_TYPE=$1
#Checking script execution parameters
if [[ -z $EURYBOX_CORPORATE || -z $EURYBOX_LOG_LEVEL || -z $EURYBOX_PARALLELISM_LEVEL ]]
if [[ -z $EURYBOX_CORPORATE || -z $EURYBOX_LOG_LEVEL ]]
then
eurybox_display_message warning CHECK "Script execution parameters not set. Continuing script execution in debug mode."
EURYBOX_CORPORATE="EURYECE TELECOM"
EURYBOX_LOG_LEVEL=debug
EURYBOX_PARALLELISM_LEVEL=2
else
eurybox_display_message message CHECK "Script execution parameters:"
eurybox_display_message message CHECK "Corporate: $EURYBOX_CORPORATE"
eurybox_display_message message CHECK "Log level: $EURYBOX_LOG_LEVEL"
eurybox_display_message message CHECK "Parallelism level: $EURYBOX_PARALLELISM_LEVEL"
fi
#Checking environment parameters
......@@ -104,21 +100,16 @@ eurybox_check_configuration ()
eurybox_display_message debug CHECK "Services number: $EURYBOX_SERVICES_NUMBER"
fi
#Checking distribution parameters
if [[ -z $EURYBOX_DISTRIB_TYPE || -z $EURYBOX_DISTRIB_VERSION || -z $EURYBOX_DISTRIB_MAC_TYPE ]]
if [[ -z $EURYBOX_DISTRIB_TYPE || -z $EURYBOX_DISTRIB_MAC_TYPE ]]
then
eurybox_display_message error CHECK "Distribution parameters not set: Type/$EURYBOX_DISTRIB_TYPE Version/$EURYBOX_DISTRIB_VERSION MAC Type:$EURYBOX_DISTRIB_MAC_TYPE"
eurybox_display_message error CHECK "Distribution parameters not set: Type -> $EURYBOX_DISTRIB_TYPE / MAC -> $EURYBOX_DISTRIB_MAC_TYPE"
else
case $EURYBOX_DISTRIB_TYPE in
centos|redhat )
if [[ $EURYBOX_DISTRIB_VERSION = "6.0" || $EURYBOX_DISTRIB_VERSION = "6.1" || $EURYBOX_DISTRIB_VERSION = "6.2" || $EURYBOX_DISTRIB_VERSION = "6.3" || $EURYBOX_DISTRIB_VERSION = "6.4" || $EURYBOX_DISTRIB_VERSION = "6.5" || $EURYBOX_DISTRIB_VERSION = "6.6" || $EURYBOX_DISTRIB_VERSION = "6.7" || $EURYBOX_DISTRIB_VERSION = "7.0" || $EURYBOX_DISTRIB_VERSION = "7.1" || $EURYBOX_DISTRIB_VERSION = "7.2" ]]
then
eurybox_display_message message CHECK "Distribution configured: $EURYBOX_DISTRIB_TYPE - version $EURYBOX_DISTRIB_VERSION"
else
eurybox_display_message error CHECK "Distribution $EURYBOX_DISTRIB_TYPE - unsupported version: $EURYBOX_DISTRIB_VERSION - please use version 6.x or 7.x"
fi
fedora20|fedora21|centos7|redhat7|centos6|redhat6|centos5|redhat5|fedora22|fedora23|fedora24|debian6|debian7|debian8|ubuntu12|ubuntu14|ubuntu16|gentoo|archlinux|openbsd5 )
eurybox_display_message message CHECK "Distribution configured: $EURYBOX_DISTRIB_TYPE"
;;
* )
eurybox_display_message error CHECK "Unsupported distribution: $EURYBOX_DISTRIB_TYPE - please use centos or redhat distribution"
eurybox_display_message error CHECK "Unsupported distribution: $EURYBOX_DISTRIB_TYPE"
;;
esac
case $EURYBOX_DISTRIB_MAC_TYPE in
......@@ -312,7 +303,7 @@ eurybox_check_hash()
eurybox_check_kernel()
{
#Check kernel name
KERNEL_NAME=`uname -s`
local KERNEL_NAME=`uname -s`
if [[ $KERNEL_NAME != "Linux" ]]
then
eurybox_display_message error CHECK "Kernel $KERNEL_NAME not supported - please use Linux"
......@@ -323,22 +314,41 @@ eurybox_check_kernel()
#fgrep nfs4 /proc/kallsyms
}
#Desc: check the hypervisor distribution
#Desc: check the hypervisor distribution / host parameters
#No arg required
eurybox_check_distribution ()
{
#Check distrib type
case $EURYBOX_DISTRIB_TYPE in
centos )
centos5|centos6|centos7 )
DISTRIBUTION_FILE="/etc/centos-release"
;;
redhat )
redhat5|redhat6|redhat7 )
DISTRIBUTION_FILE="/etc/redhat-release"
;;
fedora20|fedora21|fedora22|fedora23 )
DISTRIBUTION_FILE="/etc/fedora-release"
;;
debian6|debian7|debian8 )
DISTRIBUTION_FILE="/etc/debian_version"
;;
ubuntu12|ubuntu14|ubuntu16 )
DISTRIBUTION_FILE="/etc/lsb-release"
;;
# openbsd5 )
# DISTRIBUTION_FILE=""
# ;;
gentoo )
DISTRIBUTION_FILE="/etc/gentoo-release"
;;
archlinux )
DISTRIBUTION_FILE="/etc/arch-release"
;;
* )
eurybox_display_message error CHECK "Unsupported distribution: $EURYBOX_DISTRIB_TYPE - please use centos or redhat distribution"
eurybox_display_message error CHECK "Unsupported distribution: $EURYBOX_DISTRIB_TYPE"
;;
esac
DETECTED_DISTRIBUTION=`grep $EURYBOX_DISTRIB_VERSION $DISTRIBUTION_FILE 2>&1`
DETECTED_DISTRIBUTION=`cat $DISTRIBUTION_FILE 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
......@@ -346,12 +356,14 @@ eurybox_check_distribution ()
else
if [[ $DETECTED_DISTRIBUTION != "" ]]
then
#TODO: CHECK VERSION COHERENCE FROM FILE CONTENT
eurybox_display_message message CHECK "Distribution verification success"
eurybox_display_message debug CHECK "${DETECTED_DISTRIBUTION}"
else
eurybox_display_message error CHECK "Configured distribution version doesn't corresponds to detected distribution version: ${DETECTED_DISTRIBUTION}"
fi
fi
#Check MAC type
case $EURYBOX_DISTRIB_MAC_TYPE in
selinux )
SE_OUT=`sudo getenforce 2>&1`
......@@ -382,15 +394,103 @@ eurybox_check_distribution ()
}
#Desc: check the overall environment
#1 arg can be supplied as script type (BACKUP/UPDATE/EXEC_COMMAND) to add extra checks
#1 arg can be supplied as script type (BACKUP/RESTORE/UPDATE/EXEC_COMMAND) to add extra checks
eurybox_check_environment ()
{
local SCRIPT_TYPE=$1
local STATUS
local BKP_SPACE_LEFT
local BKP_ACCESS_OK
#Check external sotfware used
eurybox_check_command grep sudo ssh openssl tar par2 zfec virsh sha512sum sha256sum awk df tail virt-sysprep tput nmap rpcinfo pigz pbzip2 sshfs curlftpfs lftp cryptsetup
#Check common external sotfware used
eurybox_check_command grep sudo ssh virsh awk df tail tput nmap
#Check specific external sotfware used depending on configuration
if [[ $SCRIPT_TYPE = "BACKUP" || $SCRIPT_TYPE = "RESTORE" ]]
then
case ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]} in
LOCAL )
;;
SSH )
eurybox_check_command sshfs
;;
NFS )
eurybox_check_command rpcinfo
;;
FTP )
eurybox_check_command curlftpfs lftp
;;
PART )
eurybox_check_command cryptsetup
;;
ISCSI|* )
eurybox_display_message error CHECK "Unsupported backup destination protocol: ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]}"
;;
esac
if [[ $SCRIPT_TYPE = "BACKUP" ]]
then
case ${EURYBOX_BACKUP_ARCHIVE[FORMAT]} in
tar )
eurybox_check_command tar
;;
tar.gz )
eurybox_check_command tar pigz
;;
tar.bz )
eurybox_check_command tar pbzip2
;;
* )
eurybox_display_message error CHECK "Unsupported backup archive format: ${EURYBOX_BACKUP_ARCHIVE[FORMAT]}"
;;
esac
case ${EURYBOX_BACKUP_ARCHIVE[HASH]} in
sha256 )
eurybox_check_command sha256sum
;;
sha512 )
eurybox_check_command sha512sum
;;
* )
eurybox_display_message error CHECK "Unsupported backup archive hash type: ${EURYBOX_BACKUP_ARCHIVE[HASH]}"
;;
esac
case ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} in
true )
eurybox_check_command openssl
ENC_OUT=`echo "TEST"| openssl enc -salt -e -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -k ${EURYBOX_BACKUP_ARCHIVE[PASSWORD]} -out /dev/null 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error CHECK "Encryption engine test failed: error ${STATUS}\n${ENC_OUT}"
else
eurybox_display_message debug CHECK "Encryption engine successfully tested"
fi
;;
false )
;;
* )
eurybox_display_message error CHECK "Wrong backup archive encryption (true or false): ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]}"
;;
esac
case ${EURYBOX_BACKUP_ARCHIVE[FEC]} in
par2 )
eurybox_check_command par2
;;
zfec )
eurybox_check_command zfec
;;
* )
eurybox_display_message error CHECK "Unsupported backup archive FEC format: ${EURYBOX_BACKUP_ARCHIVE[FEC]}"
;;
esac
fi
if [[ $SCRIPT_TYPE = "RESTORE" ]]
then
eurybox_check_command openssl tar par2 zfec sha512sum sha256sum virt-sysprep pigz pbzip2
fi
if [[ $SCRIPT_TYPE = "UPDATE" ]]
then
eurybox_check_command rsync
fi
fi
#Check kernel capabilities
eurybox_check_kernel
#Check distribution is coherent with configuration
......@@ -570,3 +670,12 @@ eurybox_check_vm_access ()
fi
}
#TODO:PACKAGES TO INSTALL
#yum install -y nmap pigz pbzip2 sshfs curlftpfs lftp cryptsetup par2cmdline libguestfs-tools
#yum install python-pip gcc python-devel
#pip install --upgrade pip
#pip install zfec
#update: yum-utils / debmirror
#TODO: Implement lockfile and check if not already running
......@@ -110,7 +110,6 @@ eurybox_detect_archive_content ()
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]}
......
......@@ -324,13 +324,13 @@ euryboxctrl_start_live_services ()
euryboxctrl_update_hypervisor ()
{
eurybox_display_message message EURYBOXCTRL "Updating physical machine / hypervisor"
eurybox_update_hv
eurybox_update_hv ${EURYBOX_DISTRIB_TYPE}
}
euryboxctrl_update_local_repository ()
{
eurybox_display_message message EURYBOXCTRL "Updating local repository"
eurybox_update_local_repository
eurybox_update_local_repository ${EURYBOX_DISTRIB_TYPE}
}
euryboxctrl_update_services ()
......
......@@ -20,6 +20,7 @@ eurybox_export_hv_config ()
fi
done
#Dumping storage configuration
#TODO!
}
#Desc: export vm xml description
......
#!/bin/bash
#EuryBOX restore functions file
#Desc: restore selected target VM(s) from selected backup
#No arg required
eurybox_restore_vm ()
{
local VM_FILE
local VM_NAME
local VM_DISKS
local VM_DISKS_NUM
local VM_DISK_NAME
local RESTORE_OUT
local STATUS
local VM_NUM_START
local VM_NUM_END
local VM_ID=${EURYBOX_RESTORE_TARGET_ARCHIVE[VM_ID]}
local ARCH_ID=${EURYBOX_RESTORE_TARGET_ARCHIVE[ID]}
local ARCH_FILE="${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_DETECTED_ARCHIVES[${ARCH_ID},FILENAME]}.${EURYBOX_DETECTED_ARCHIVES[${ARCH_ID},FORMAT]}"
local ARCH_ENC=${EURYBOX_DETECTED_ARCHIVES[${ARCH_ID},ENC]}
local ARCH_FORMAT=${EURYBOX_DETECTED_ARCHIVES[${ARCH_ID},FORMAT]}
local DESTINATION="$EURYBOX_TMP_FOLDER"
if [[ $VM_ID == "*" ]]
then
VM_NUM_START=0
VM_NUM_END=$(( ${EURYBOX_DETECTED_ARCHIVES[$ARCH_ID,VM_NUM]} - 1))
else
VM_NUM_START=VM_ID
VM_NUM_END=VM_ID
fi
for (( VM_NUM=${VM_NUM_START};VM_NUM<=${VM_NUM_END};VM_NUM++ ))
do
VM_FILE=${EURYBOX_DETECTED_ARCHIVES[$ARCH_ID,$VM_NUM,FILE]}
VM_NAME=${EURYBOX_DETECTED_ARCHIVES[$ARCH_ID,$VM_NUM,NAME]}
eurybox_restore_file $ARCH_FILE $ARCH_FORMAT $ARCH_ENC $VM_FILE $DESTINATION
RESTORE_OUT=`sudo virsh $EURYBOX_VIRSH_OPTIONS define $DESTINATION/$VM_FILE`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error RESTORE "Archive restoration : VM import failed - error $STATUS:\n$RESTORE_OUT"
else
eurybox_display_message message RESTORE "Archive restoration : VM $VM_NAME description import success"
eurybox_display_message debug RESTORE "Archive restoration VM import command output:\n$RESTORE_OUT"
DISKS=( $(sudo virsh $EURYBOX_VIRSH_OPTIONS domblklist $VM_NAME | awk '($2 != "-") {print $2}') )
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error RESTORE "Archive restoration : VM disk detection failed - error $STATUS:\n$DISKS[*]"
else
if [[ !($DISKS = "") ]]
then
VM_DISKS_NUM=${#DISKS[@]}
eurybox_display_message message RESTORE "VM $VM_NAME - $VM_DISKS_NUM disk(s) found"
eurybox_display_message debug RESTORE "Detected disk(s) : ${DISKS[*]}"
for (( DISK_NUM=0;DISK_NUM<$VM_DISKS_NUM;DISK_NUM++ ))
do
VM_DISK_NAME=`echo ${DISKS[DISK_NUM]} | awk -F"/" '{ for(i=2; i<=(NF); i++) { if(i==2) { filename=$i } else { filename=filename"/"$i } } ; print filename }'`
eurybox_display_message debug RESTORE "VM $VM_NAME - restoring disk: $VM_DISK_NAME to ${DISKS[DISK_NUM]}"
eurybox_restore_file $ARCH_FILE $ARCH_FORMAT $ARCH_ENC $VM_DISK_NAME "/"
done
else
eurybox_display_message warning RESTORE "No domain disk detected for VM $VM_NAME"
fi
fi
fi
done
}
#Desc: restore selected files from archive to destination
#5 args required: archive_file archive_format archive_encrypted selected_files destination
eurybox_restore_file ()
{
local ARCH_FILE=$1
local ARCH_FORMAT=$2
local ARCH_ENC=$3
local SELECT_FILE=$4
local DESTINATION=$5
local RESTORE_OUT
local SYNC_OUT
local STATUS
local TAR_OPTIONS
case $ARCH_FORMAT in
"tar" ) TAR_OPTIONS="-Sxv -C $DESTINATION";;
"tar.gz" ) TAR_OPTIONS="-Sxv --use-compress-program=pigz -C $DESTINATION";;
"tar.bz2" ) TAR_OPTIONS="-Sxv --use-compress-program=pbzip2 -C $DESTINATION";;
esac
STATUS=1234
if [[ $ARCH_ENC = "true" ]]
then
RESTORE_OUT=`sudo sh -c "openssl enc -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -d -in $ARCH_FILE -k ${EURYBOX_BACKUP_ARCHIVE[PASSWORD]} | tar ${TAR_OPTIONS} $SELECT_FILE" 2>&1`
STATUS=$?
else
RESTORE_OUT=`sudo sh -c "tar ${TAR_OPTIONS} -f $ARCH_FILE $SELECT_FILE" 2>&1`
STATUS=$?
fi
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning RESTORE "Archive file(s) $SELECT_FILE restoration failed - error $STATUS:\n$RESTORE_OUT"
else
eurybox_display_message message RESTORE "Archive file(s) restoration success: ${DESTINATION} => ${SELECT_FILE}"
eurybox_display_message debug RESTORE "Archive restoration command output:\n$RESTORE_OUT"
fi
}
......@@ -2,27 +2,50 @@
#EuryBOX update functions file
#Desc: update hypervisor
#FIXME: implement distrib specific update command (with one arg)
#No arg required
#1 arg required: operating_system
eurybox_update_hv ()
{
EURYBOX_HV_UPDATED=0
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
local UPDATE_OUT
local OS=$1
local EURYBOX_HV_UPDATED=0
local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
while [[ ( $EURYBOX_HV_UPDATED -eq 0 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
do
UPDATE_OUT=`sudo yum -y update 2>&1`
case $OS in
fedora20|fedora21|centos7|redhat7|centos6|redhat6|centos5|redhat5 )
UPDATE_OUT=`sudo yum -y update 2>&1`
;;
fedora22|fedora23|fedora24 )
UPDATE_OUT=`sudo dnf -y update 2>&1`
;;
debian6|debian7|debian8|ubuntu12|ubuntu14|ubuntu16 )
UPDATE_OUT=`sudo apt-get -y update && apt-get -y upgrade 2>&1`
;;
openbsd5 )
UPDATE_OUT=`echo "Not Implemented Yet"`
;;
gentoo )
UPDATE_OUT=`sudo emerge --sync && sudo emerge -uDU --with-bdeps=y @world && sudo emerge -av --depclean && sudo emerge --update --newuse --deep @world && sudo revdep-rebuild -v 2>&1`
;;
archlinux )
UPDATE_OUT=`sudo pacman -Syy && sudo pacman -Su 2>&1`
;;
* )
eurybox_display_message error UPDATE "OS unknown : $OS"
;;
esac
STATUS=$?
if [[ $STATUS -eq 0 ]]
then
EURYBOX_HV_UPDATED=1
else
eurybox_display_message debug UPDATE "Hypervisor update failed - trying again in 5 seconds - error $STATUS:\n$UPDATE_OUT\n$NB_TRY_LEFT left"
sleep 5
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug UPDATE "Hypervisor update failed - trying again - error $STATUS:\n$UPDATE_OUT\n$NB_TRY_LEFT left"
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error UPDATE "Hypervisor update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE"
eurybox_display_message error UPDATE "Hypervisor update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE attempts - error $STATUS:\n${UPDATE_OUT}"
else
eurybox_display_message message UPDATE "Hypervisor update OK"
eurybox_display_message debug UPDATE "Update command output:\n$UPDATE_OUT"
......@@ -33,20 +56,21 @@ eurybox_update_hv ()
#5 args required: vm_name vm_host vm_user vm_ssh_port operating_system
eurybox_update_vm ()
{
NAME=$1
HOST=$2
USER=$3
PORT=$4
OS=$5
EURYBOX_VM_UPDATED=0
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
local UPDATE_OUT
local NAME=$1
local HOST=$2
local USER=$3
local PORT=$4
local OS=$5
local EURYBOX_VM_UPDATED=0
local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
while [[ ( $EURYBOX_VM_UPDATED -eq 0 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
do
case $OS in
fedora20|fedora21|centos7|redhat7|centos6|redhat6|centos5|redhat5 )
UPDATE_OUT=`ssh $EURYBOX_SSH_OPTIONS -p $PORT $USER@$HOST "yum -y update" 2>&1`
;;
fedora22|fedora23 )
fedora22|fedora23|fedora24 )
UPDATE_OUT=`ssh $EURYBOX_SSH_OPTIONS -p $PORT $USER@$HOST "dnf -y update" 2>&1`
;;
debian6|debian7|debian8|ubuntu12|ubuntu14|ubuntu16 )
......@@ -61,19 +85,22 @@ eurybox_update_vm ()
archlinux )
UPDATE_OUT=`ssh $EURYBOX_SSH_OPTIONS -p $PORT $USER@$HOST "pacman -Syy && pacman -Su" 2>&1`
;;
* )
eurybox_display_message error UPDATE "OS unknown : $OS"
;;
esac
STATUS=$?
if [[ $STATUS -eq 0 ]]
then
EURYBOX_VM_UPDATED=1
else
eurybox_display_message debug UPDATE "VM $NAME update failed - trying again in 5 seconds - error $STATUS:\n$UPDATE_OUT\n$NB_TRY_LEFT left"
sleep 5
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug UPDATE "VM $NAME update failed - trying again - error $STATUS:\n$UPDATE_OUT\n$NB_TRY_LEFT left"
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error UPDATE "VM $NAME - update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE"
eurybox_display_message error UPDATE "VM $NAME - update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE attempts - error $STATUS:\n${UPDATE_OUT}"
else
eurybox_display_message message UPDATE "VM $NAME - update OK"
eurybox_display_message debug UPDATE "Update command output:\n$UPDATE_OUT"
......@@ -81,17 +108,79 @@ eurybox_update_vm ()
}
#Desc: update local repository
#No arg required
#1 arg required: operating_system
eurybox_update_local_repository ()
{
eurybox_display_message warning UPDATE "Not implemented yet"
#eurybox_display_message message STATUS "Updating local repository"
#reposync -n -d -p /local_repo/
#eurybox_display_message message STATUS "Updating repository descriptions"
##TODO: CHECK IF REPO EXIST AND CREATE (NO UPDATE) IF NOT + ADD VARIABLE REPOS LIST + SCRIPT AUTO DEPLOY
#createrepo --update /local_repo/base/Packages
#createrepo --update /local_repo/updates/Packages
#createrepo --update /local_repo/extras/Packages
#createrepo --update /local_repo/epel
local UPDATE_OUT
local REPO_UPDATED_NUM
local REPO_ERRORS
local REPO_PATH=${EURYBOX_UPDATE_LOCAL_REPOSITORIES_PATH}
local OS=$1
local EURYBOX_REPO_UPDATED=0
local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
eurybox_display_message message UPDATE "Updating local repositories"
while [[ ( $EURYBOX_REPO_UPDATED -eq 0 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
do
REPO_UPDATED_NUM=0
REPO_ERRORS=""
for (( REPO_NUM=1;REPO_NUM<=${EURYBOX_UPDATE_LOCAL_REPOSITORIES_NUMBER};REPO_NUM++ ))
do
NAME=${EURYBOX_UPDATE_LOCAL_REPOSITORIES[${REPO_NUM},NAME]}
ARCH=${EURYBOX_UPDATE_LOCAL_REPOSITORIES[${REPO_NUM},ARCH]}
URI=${EURYBOX_UPDATE_LOCAL_REPOSITORIES[${REPO_NUM},URI]}
eurybox_display_message message UPDATE "Updating repository : $NAME - arch: $ARCH - uri: $URI"
MKDIR_OUT=`sudo mkdir -p ${REPO_PATH}/${NAME}/${ARCH}`
UPDATE_OUT=`sudo sh -c "rsync -avzHm --include=**${ARCH}** --include=*/ --exclude=* $URI ${REPO_PATH}/${NAME}/${ARCH}" 2>&1`
STATUS=$?
if [[ $STATUS -eq 0 ]]
then
eurybox_display_message message UPDATE "Local repository $NAME - $URI - clone OK"
eurybox_display_message debug UPDATE "Mkdir command output:\n$MKDIR_OUT"
eurybox_display_message debug UPDATE "Clone command output:\n$UPDATE_OUT"
#TODO:MAC MASK
UPDATE_OUT=`sudo chmod -R 500 ${REPO_PATH}/${NAME}/${ARCH} 2>&1`
STATUS=$?
if [[ $STATUS -eq 0 ]]
then
eurybox_display_message message UPDATE "Local repository $NAME - MAC permissions change OK"
REPO_UPDATED_NUM=$(( ${REPO_UPDATED_NUM} + 1 ))
else
if [[ $REPO_ERRORS = "" ]]
then
REPO_ERRORS="${NAME}:\n${UPDATE_OUT}"
else
REPO_ERRORS="${REPO_ERRORS}\n\n${NAME}:\n${UPDATE_OUT}"
fi
eurybox_display_message debug UPDATE "Local repository $NAME MAC permissions change failed - trying others - error $STATUS:\n$UPDATE_OUT"
fi
else
if [[ $REPO_ERRORS = "" ]]
then
REPO_ERRORS="${NAME}:\n${UPDATE_OUT}"
else
REPO_ERRORS="${REPO_ERRORS}\n\n${NAME}:\n${UPDATE_OUT}"
fi
eurybox_display_message debug UPDATE "Local repository $NAME clone failed - trying others - error $STATUS:\n$UPDATE_OUT"
fi
if [[ $REPO_NUM -eq ${EURYBOX_UPDATE_LOCAL_REPOSITORIES_NUMBER} ]]
then
if [[ $REPO_UPDATED_NUM -eq ${EURYBOX_UPDATE_LOCAL_REPOSITORIES_NUMBER} ]]
then
EURYBOX_REPO_UPDATED=1
else
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug UPDATE "Local repositories update failed - trying again\n$NB_TRY_LEFT left"
fi
fi