Commit ca395223 authored by Guillaume REMBERT's avatar Guillaume REMBERT

Backup target abstraction implementation - SSH/NFS/PART/LOCAL targets fully supported

parent dee24edb
......@@ -88,8 +88,8 @@ EURYBOX_BACKUP_TMP_FOLDER="/tmp/bkp"
#Backup targets (in addition to services attached disks backup and additionnal disks from config)
EURYBOX_BACKUP_TARGETS=(
[0]="/var/log"
[1]="/etc"
# [0]="/var/log"
# [1]="/etc"
)
#Backup archive
......@@ -100,9 +100,10 @@ EURYBOX_BACKUP_TARGETS=(
#ENC_ALGO= openssl supported algo (aes-256-xts/aes-256-ctr/...)
EURYBOX_BACKUP_ARCHIVE=(
[NAME]="nodeXX_archive"
[OWNER]="root:root"
[MASK]="400"
[LABEL]="backup_u:object_r:backup_t:s0"
[FORMAT]="tar"
[FORMAT]="tar.bz2"
[HASH]="sha512"
[ECC]="par2"
[ECC_LEVEL]="10"
......@@ -112,18 +113,28 @@ EURYBOX_BACKUP_ARCHIVE=(
)
#Backup destination
#PROTOCOL= SSH/NFS
#PROTOCOL= SSH/NFS/FTP/PART/LOCAL/ISCSI
#Protocol options details
#-SSH: ssh client/server configuration done at system level + 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: TODO - ftp client/server authentication (password or certificates) + 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=(
[PROTOCOL]="NFS"
[MOUNT]="/mnt/local_backup_folder"
#FOR SSH AND FTP
[USER]="root"
#FOR SSH, FTP AND NFS
# [PORT]="22"
[PORT]="2049"
[HOST]="10.10.10.10"
[PATH]="/mnt/backup/eurybox_archives"
## [PORT]="2049"
#FOR NFS ONLY => poRT 2049 : man nfs
#FOR NFS ONLY
[TYPE]="nfs4"
[MOUNT]="/mnt/local_backup_folder"
#FOR SSH ONLY
[USER]="root"
[PORT]="22"
#FOR PART ONLY
[PART]="/dev/sde"
)
##########################
......
......@@ -12,10 +12,163 @@ eurybox_backup_add_config_disks ()
done
}
#Desc: mount the backup target
#No arg required
eurybox_backup_mount_target ()
{
local STATUS
local MOUNT_OUT
local NB_TRY_LEFT
local NMAP_OUT
local NFS_OUT
local SSH_OUT
local PART_OUT
local BKP_PROTOCOL=${EURYBOX_BACKUP_DESTINATION[PROTOCOL]}
local BKP_DEST=${EURYBOX_BACKUP_DESTINATION[PATH]}
local BKP_MOUNT=${EURYBOX_BACKUP_DESTINATION[MOUNT]}
local BKP_PORT=${EURYBOX_BACKUP_DESTINATION[PORT]}
local BKP_USER=${EURYBOX_BACKUP_DESTINATION[USER]}
local BKP_HOST=${EURYBOX_BACKUP_DESTINATION[HOST]}
local BKP_TYPE=${EURYBOX_BACKUP_DESTINATION[TYPE]}
local BKP_PART=${EURYBOX_BACKUP_DESTINATION[PART]}
if [[ $EURYBOX_LOG_LEVEL = "debug" || $EURYBOX_LOG_LEVEL = "verbose" ]]
then
local MOUNT_OPTIONS="-v"
else
local MOUNT_OPTIONS=""
fi
if [[ !(-d $BKP_MOUNT) ]]
then
local MKDIR_OUT=`sudo mkdir -p $BKP_MOUNT 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
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 700 $BKP_MOUNT 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error BACKUP "Target local mount point directory $BKP_MOUNT permissions change failed - error $STATUS:\n$CHMOD_OUT"
else
eurybox_display_message message BACKUP "Target Local mount point directory $BKP_MOUNT successfully created"
eurybox_display_message debug BACKUP "Directory creation command output:\n$MKDIR_OUT\Directory permissions change output:\n$CHMOD_OUT"
fi
fi
fi
STATUS=1234
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
while [[ !($STATUS -eq 0) && ($(grep ${BKP_MOUNT} /proc/mounts) = "") && !($NB_TRY_LEFT -eq 0) ]]
do
case $BKP_PROTOCOL in
LOCAL )
#Nothing to do
STATUS=0
;;
NFS|SSH|FTP )
#Is server available?
NMAP_OUT=`sudo nmap $EURYBOX_NMAP_OPTIONS -p $BKP_PORT $BKP_HOST | grep open 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup target $BKP_PROTOCOL server unreacheable on host $BKP_HOST / port $BKP_PORT - trying to contact again in 5 seconds - error $STATUS:\n$NMAP_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
else
eurybox_display_message debug BACKUP "Backup target $BKP_PROTOCOL server reached on host $BKP_HOST / port $BKP_PORT"
case $BKP_PROTOCOL in
NFS )
NFS_OUT=`sudo rpcinfo -n $BKP_PORT -t $BKP_HOST nfs 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup target NFS server not registred on destination - trying to contact again in 5 seconds - error $STATUS:\n$NFS_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
else
MOUNT_OUT=`sudo mount $MOUNT_OPTIONS $EURYBOX_MNT_NFS_OPTIONS -o proto=tcp,port=${BKP_PORT} -t $BKP_TYPE ${BKP_HOST}:${BKP_DEST} ${BKP_MOUNT} 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message warning BACKUP "Backup target NFS mount failed and target folder is empty - trying to mount again in 5 seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
sleep 5
fi
fi
;;
SSH )
#Check access
SSH_OUT=`ssh $EURYBOX_SSH_OPTIONS -p $BKP_PORT ${BKP_USER}@${BKP_HOST} "touch ${BKP_DEST}/eurybox_check_ssh_ok" 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup target $BKP_PROTOCOL server unreacheable on host $BKP_HOST / port $BKP_PORT - trying to contact again in 5 seconds - error $STATUS:\n$SSH_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
else
eurybox_display_message debug BACKUP "Backup target $BKP_PROTOCOL server reached on host $BKP_HOST / port $BKP_PORT"
MOUNT_OUT=`sshfs $EURYBOX_MNT_SSHFS_OPTIONS -p $BKP_PORT ${BKP_USER}@${BKP_HOST}:${BKP_DEST} ${BKP_MOUNT} 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message warning BACKUP "Backup target SSHFS mount failed and target folder is empty - trying to mount again in 5 seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
sleep 5
fi
fi
;;
FTP )
eurybox_display_message error BACKUP "Backup destination FTP not implemented yet"
;;
esac
fi
;;
PART )
#Is partition available?
PART_OUT=`sudo ls -al ${BKP_PART} 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup target ${BKP_PART} not found - trying to detect device again in 5 seconds - error $STATUS:\n$PART_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
else
eurybox_display_message message BACKUP "Backup device partition ${BKP_PART} detected"
eurybox_display_message debug BACKUP "Partition detection command output:\n$PART_OUT"
MOUNT_OUT=`sudo mount $MOUNT_OPTIONS $BKP_PART ${BKP_MOUNT} 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning BACKUP "Backup target ${BKP_PART} mount failed - trying to mount partition again in 5 seconds - error $STATUS:\n$MOUNT_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
fi
fi
;;
* )
eurybox_display_message error BACKUP "Unkown backup target protocol: $BKP_PROTOCOL"
;;
esac
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error BACKUP "Backup target mount failed:\n$MOUNT_OUT $NFS_OUT $NMAP_OUT $SSH_OUT $PART_OUT"
else
eurybox_display_message message BACKUP "Backup target mount success"
eurybox_display_message debug BACKUP "Mount command output:\n$MOUNT_OUT"
fi
}
#Desc: add backup services targets automatically detected disks
#No arg required
eurybox_backup_prepare_services ()
{
local DOM_FOUND
local DISK_FOUND
for (( DOM_NUM=0;DOM_NUM<${EURYBOX_DETECTED_DOMAINS[NUM]};DOM_NUM++ ))
do
DOM_FOUND=0
......@@ -41,7 +194,7 @@ eurybox_backup_prepare_services ()
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]}"
eurybox_display_message message BACKUP "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
......@@ -56,3 +209,50 @@ eurybox_backup_prepare_services ()
done
}
#Desc: un-mount the target backup
#No arg required
eurybox_backup_umount_target ()
{
local STATUS=1234
local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
local UMOUNT_OUT
local BKP_PROTOCOL=${EURYBOX_BACKUP_DESTINATION[PROTOCOL]}
if [[ $EURYBOX_LOG_LEVEL = "debug" || $EURYBOX_LOG_LEVEL = "verbose" ]]
then
local UMOUNT_OPTIONS="-v"
else
local UMOUNT_OPTIONS=""
fi
while [[ !($STATUS -eq 0) && !($(grep ${EURYBOX_BACKUP_DESTINATION[MOUNT]} /proc/mounts) = "") && !($NB_TRY_LEFT -eq 0) ]]
do
case $BKP_PROTOCOL in
LOCAL )
#Nothing to do
STATUS=0
;;
NFS|SSH|PART )
UMOUNT_OUT=`sudo umount $UMOUNT_OPTIONS ${EURYBOX_BACKUP_DESTINATION[MOUNT]} 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message warning BACKUP "Backup target unmount failed and target folder is not empty. Trying to unmount again in 5 seconds - error $STATUS\n$UMOUNT_OUT\n$NB_TRY_LEFT left"
sleep 5
fi
;;
* )
eurybox_display_message error BACKUP "Unkown backup target protocol: $BKP_PROTOCOL"
;;
esac
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error BACKUP "Backup target unmount failed:\n$UMOUNT_OUT"
else
eurybox_display_message message BACKUP "Backup target unmount success"
eurybox_display_message debug BACKUP "Unmount command output:\n$UMOUNT_OUT"
fi
}
This diff is collapsed.
This diff is collapsed.
......@@ -2,83 +2,115 @@
#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
#1 arg required: description_file
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
local DESTINATION=$1
local BKP_ENC
local BKP_COMP
local BKP_TYPE
local BKP_VERS
local BKP_ECC
local STATUS
local ARCH_DESC=`sudo cat $DESTINATION 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error DETECT "Archive description access failed: $ARCH_DESC"
#FIXME: STATUS IS NOT 0 WHEN FORBIDEN TO ACCESS FILE
eurybox_display_message warning DETECT "Archive description access failed: \n$ARCH_DESC"
else
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}'`
if [[ $BKP_ENC = "" ]]
then
eurybox_display_message error DETECT "Archive description encryption activated search failed"
eurybox_display_message warning DETECT "Archive description encryption 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"
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}'`
case $BKP_COMP in
"" )
eurybox_display_message warning DETECT "Archive description compression search failed"
;;
tar )
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,COMP]="none"
eurybox_display_message debug DETECT "Archive description compression search success - found: none"
;;
tar.gz|tar.bz2 )
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,COMP]=$BKP_COMP
eurybox_display_message debug DETECT "Archive description compression search success - found: $BKP_COMP"
;;
* )
eurybox_display_message warning DETECT "Archive description compression search failed - unknown backup compression found: $BKP_COMP"
;;
esac
BKP_TYPE=`echo "${ARCH_DESC}" | grep "ARCHIVE_TYPE" | awk -F":" '{print $NF}'`
case $BKP_TYPE in
"" )
eurybox_display_message warning DETECT "Archive description type search failed"
;;
vm_cold|vm_hot|full_hot|full_cold )
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TYPE]=$BKP_TYPE
eurybox_display_message debug DETECT "Archive description type search success - found: $BKP_TYPE"
;;
* )
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}'`
case $BKP_VERS in
"" )
eurybox_display_message warning DETECT "Archive description version search failed"
;;
1.0 )
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,VERS]=$BKP_VERS
eurybox_display_message debug DETECT "Archive description version search success - found: $BKP_VERS"
;;
* )
eurybox_display_message warning DETECT "Archive description version search failed - unknown backup version found: $BKP_VERS"
;;
esac
BKP_ECC=`echo "${ARCH_DESC}" | grep "ECC_FORMAT" | awk -F":" '{print $NF}'`
case $BKP_ECC in
"" )
eurybox_display_message warning DETECT "Archive description correcting codes search failed"
;;
par2 )
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,ECC]=$BKP_ECC
eurybox_display_message debug DETECT "Archive description correcting codes search success - found: $BKP_ECC"
;;
* )
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}'`
case $BKP_HASH in
"" )
eurybox_display_message warning DETECT "Archive description hash search failed"
;;
sha256|sha512 )
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,HASH]=$BKP_HASH
eurybox_display_message debug DETECT "Archive description hash search success - found: $BKP_HASH"
;;
* )
eurybox_display_message warning DETECT "Archive description hash search failed - unknown backup hash found: $BKP_HASH"
;;
esac
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
#Desc: detect archives in specified directory
#1 arg required: search_path
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
local DESTINATION="$1/*"
local BKP_LIST
local FILES_LIST=`sudo ls $EURYBOX_LS_OPTIONS $DESTINATION 2>&1`
local STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error DETECT "Archive description listing not found: $BKP_LIST"
eurybox_display_message error DETECT "Archive description listing not found: \n$FILES_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}') )
......@@ -87,7 +119,7 @@ eurybox_detect_archives ()
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"
eurybox_display_message message DETECT "${EURYBOX_DETECTED_ARCHIVES[NUM]} archive description(s) found"
for (( ARCH_NUM=0;ARCH_NUM<${EURYBOX_DETECTED_ARCHIVES[NUM]};ARCH_NUM++ ))
do
EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,FILE]=${BKP_LIST[$ARCH_NUM]}
......@@ -105,7 +137,6 @@ eurybox_detect_archives ()
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) ]]
......@@ -115,7 +146,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]} founds"
eurybox_display_message message DETECT "Hypervisors 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]}
......@@ -135,7 +166,7 @@ eurybox_detect_libvirt_env ()
if [[ !($DOMAINS = "") ]]
then
EURYBOX_DETECTED_DOMAINS[NUM]=${#DOMAINS[@]}
eurybox_display_message message DETECT "Hypervisor domains (VM) - detection OK: ${EURYBOX_DETECTED_DOMAINS[NUM]} founds"
eurybox_display_message message DETECT "Hypervisor domains (VM) - detection OK: ${EURYBOX_DETECTED_DOMAINS[NUM]} domain(s) found"
for (( DOM_NUM=0;DOM_NUM<${EURYBOX_DETECTED_DOMAINS[NUM]};DOM_NUM++ ))
do
EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]=${DOMAINS[DOM_NUM]}
......@@ -157,7 +188,7 @@ eurybox_detect_libvirt_env ()
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"
eurybox_display_message message DETECT "VM ${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]} - ${EURYBOX_DETECTED_DISKS[${EURYBOX_DETECTED_DOMAINS[NAME,$DOM_NUM]},NUM]} disk(s) found"
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]}
......
......@@ -4,7 +4,7 @@
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}'`
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"
......@@ -15,7 +15,7 @@ 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}'`
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
......@@ -114,7 +114,21 @@ euryboxctrl_create_sign ()
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]}
#Mount backup target
eurybox_display_message message EURYBOXCTRL "Mounting backup origin"
eurybox_backup_mount_target
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_detect_archive_content "${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${LNAME}"
done
#unmount backup target
eurybox_display_message message EURYBOXCTRL "Unmounting backup origin"
eurybox_backup_umount_target
eurybox_display_detected_archives
}
......@@ -141,12 +155,15 @@ euryboxctrl_prepare_backup ()
EURYBOX_BACKUP_ARCHIVE[NAME]=${EURYBOX_BACKUP_ARCHIVE[NAME]}_$(date +"%Y_%m_%d_%H_%M_%S")
#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
......@@ -155,6 +172,10 @@ euryboxctrl_prepare_backup ()
eurybox_export_hv_config
;;
esac
#Mount backup target
eurybox_display_message message EURYBOXCTRL "Mounting backup destination"
eurybox_backup_mount_target
}
euryboxctrl_select_restore_target ()
......@@ -162,7 +183,6 @@ euryboxctrl_select_restore_target ()
if [[ $EURYBOX_RESTORE_TARGET_ACQUISITION = "interactive" ]]
then
eurybox_configure_interactive_restoration_target
eurybox_detect_archive_content ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]} ${EURYBOX_BACKUP_DESTINATION[PATH]} "${EURYBOX_BACKUP_ARCHIVE[NAME]}.desc" ${EURYBOX_BACKUP_DESTINATION[MOUNT]} ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]} ${EURYBOX_BACKUP_DESTINATION[HOST]}
else
eurybox_display_message warning EURYBOXCTRL "Unknown restoration target acquisition type: $EURYBOX_RESTORE_TARGET_ACQUISITION"
fi
......@@ -220,7 +240,12 @@ euryboxctrl_update_services ()
euryboxctrl_terminate_backup ()
{
#Change archives permissions to read only
eurybox_change_files_permissions ${EURYBOX_BACKUP_ARCHIVE[MASK]}
#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
}
This diff is collapsed.
......@@ -16,7 +16,7 @@ eurybox_update_hv ()
then
EURYBOX_HV_UPDATED=1
else
eurybox_display_message debug UPDATE "Hypervisor update failed - trying again in 5 seconds / $NB_TRY_LEFT left: $UPDATE_OUT"
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
fi
done
......@@ -25,7 +25,7 @@ eurybox_update_hv ()
eurybox_display_message error UPDATE "Hypervisor update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE"
else
eurybox_display_message message UPDATE "Hypervisor update OK"
eurybox_display_message debug UPDATE "$UPDATE_OUT"
eurybox_display_message debug UPDATE "Update command output:\n$UPDATE_OUT"
fi
}
......@@ -67,7 +67,7 @@ eurybox_update_vm ()
then
EURYBOX_VM_UPDATED=1
else
eurybox_display_message debug UPDATE "VM $NAME - update failed - trying again in 5 seconds / $NB_TRY_LEFT left: $UPDATE_OUT"
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
fi
done
......@@ -76,7 +76,7 @@ eurybox_update_vm ()
eurybox_display_message error UPDATE "VM $NAME - update failed - no success after $EURYBOX_MAX_RETRY_ON_FAILURE"
else
eurybox_display_message message UPDATE "VM $NAME - update OK"
eurybox_display_message debug UPDATE "$UPDATE_OUT"
eurybox_display_message debug UPDATE "Update command output:\n$UPDATE_OUT"
fi
}
......
......@@ -5,11 +5,13 @@
#1 arg required: vm_name
eurybox_vm_shutdown_acpi ()
{
NAME=$1
local NAME=$1
local STATUS
#Waiting for the VM to be stopped
EURYBOX_VM_STATE=1
EURYBOX_VM_STOPPED=0
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
local EURYBOX_VM_NAME
local EURYBOX_VM_STATE=1
local EURYBOX_VM_STOPPED=0
local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
while [[ ( $EURYBOX_VM_STATE -eq 1 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
do
EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | grep $NAME`
......@@ -49,13 +51,16 @@ eurybox_vm_shutdown_acpi ()
#4 arg required: vm_name vm_host vm_user vm_port
eurybox_vm_shutdown_ssh ()
{
NAME=$1
HOST=$2
USER=$3
PORT=$4
EURYBOX_VM_STATE=1
EURYBOX_VM_STOPPED=0
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
local NAME=$1
local HOST=$2
local USER=$3
local PORT=$4
local EURYBOX_VM_STATE=1
local EURYBOX_VM_STOPPED=0
local STATUS
local EURYBOX_VM_NAME
local SSH_OUT
local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
while [[ ( $EURYBOX_VM_STATE -eq 1 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
do
EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | grep $NAME`
......@@ -69,7 +74,7 @@ eurybox_vm_shutdown_ssh ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning VM "VM $NAME - stop failed - trying again in 5 seconds: $SSH_OUT / $NB_TRY_LEFT left"
eurybox_display_message warning VM "VM $NAME - stop failed - trying again in 5 seconds:\n$SSH_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
else
EURYBOX_VM_STOPPED=1
......@@ -78,14 +83,14 @@ eurybox_vm_shutdown_ssh ()
fi
else
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug VM "VM $NAME - still running - trying again in 5 seconds / $NB_TRY_LEFT left"
eurybox_display_message debug VM "VM $NAME - still running - trying again in 5 seconds:\n$EURYBOX_VM_NAME\n$NB_TRY_LEFT left"
fi
sleep 5
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error VM "VM $NAME - stop failed - VM still running after $EURYBOX_MAX_RETRY_ON_FAILURE: $EURYBOX_VM_NAME"
eurybox_display_message error VM "VM $NAME - stop failed - VM still running after $EURYBOX_MAX_RETRY_ON_FAILURE:\n$EURYBOX_VM_NAME"
else
eurybox_display_message message VM "VM $NAME - stop OK"
fi
......@@ -95,14 +100,18 @@ eurybox_vm_shutdown_ssh ()
#4 arg required: vm_name vm_host vm_user vm_port
eurybox_vm_start ()
{
NAME=$1
HOST=$2
USER=$3
PORT=$4
local NAME=$1
local HOST=$2
local USER=$3
local PORT=$4
local STATUS
local VM_OUT
local EURYBOX_VM_AVAILABLE
local VIRSH_OUT
#Check if VM is operationnal (at network level)
EURYBOX_VM_STATE=0
EURYBOX_VM_STARTED=0
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
local EURYBOX_VM_STATE=0
local EURYBOX_VM_STARTED=0
local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
while [[ ( $EURYBOX_VM_STATE -eq 0 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
do
EURYBOX_VM_AVAILABLE=`ssh $EURYBOX_SSH_OPTIONS -p $PORT $USER@$HOST "touch eurybox_check_ssh_ok" 2>&1`
......@@ -120,7 +129,7 @@ eurybox_vm_start ()
VM_OUT=`sudo virsh $EURYBOX_VIRSH_OPTIONS list | grep $NAME`
if [[ -z "$VM_OUT" ]]
then
eurybox_display_message warning VM "Error on vm $NAME start : $VIRSH_OUT- trying again in 5 seconds / $NB_TRY_LEFT left"
eurybox_display_message warning VM "Error on vm $NAME start - trying again in 5 seconds:\n$VIRSH_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
else
eurybox_display_message debug VM "VM $NAME already running - waiting for network contact"
......@@ -134,7 +143,7 @@ eurybox_vm_start ()
fi
else
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message debug VM "VM $NAME - still unreachable - trying again in 5 seconds / $NB_TRY_LEFT left: $EURYBOX_VM_AVAILABLE"
eurybox_display_message debug VM "VM $NAME - still unreachable - trying again in 5 seconds\n$EURYBOX_VM_AVAILABLE\n$NB_TRY_LEFT left"