Browse Source

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

master
Guillaume REMBERT 6 years ago
parent
commit
ca3952237d
9 changed files with 688 additions and 504 deletions
  1. +21
    -10
      cfg/sw/eurybox.conf
  2. +201
    -1
      sw/src/eurybox.functions.backup
  3. +77
    -64
      sw/src/eurybox.functions.check
  4. +124
    -190
      sw/src/eurybox.functions.create
  5. +95
    -64
      sw/src/eurybox.functions.detect
  6. +31
    -6
      sw/src/eurybox.functions.euryboxctrl
  7. +103
    -142
      sw/src/eurybox.functions.tools
  8. +4
    -4
      sw/src/eurybox.functions.update
  9. +32
    -23
      sw/src/eurybox.functions.vm

+ 21
- 10
cfg/sw/eurybox.conf View File

@@ -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"
)

##########################


+ 201
- 1
sw/src/eurybox.functions.backup View File

@@ -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
}


+ 77
- 64
sw/src/eurybox.functions.check View File

@@ -3,7 +3,6 @@

#TODO: Implement lockfile and check if not already running


#Desc: check the input arguments
#TODO: implement arguments usage (debug mode / config file ...) and checking
eurybox_check_arguments ()
@@ -32,7 +31,7 @@ eurybox_check_command()
#Conf file needs to be sourced before
eurybox_check_configuration ()
{
SCRIPT_TYPE=$1
local -i SCRIPT_TYPE=$1
#Checking script execution parameters
if [[ -z $EURYBOX_CORPORATE || -z $EURYBOX_LOG_LEVEL || -z $EURYBOX_PARALLELISM_LEVEL ]]
@@ -82,7 +81,7 @@ eurybox_check_configuration ()
esac
case $EURYBOX_DISTRIB_MAC_TYPE in
selinux|none )
eurybox_display_message message CHECK "Distribution mandatory access control type configured: $EURYBOX_DISTRIB_TYPE - version $EURYBOX_DISTRIB_VERSION"
eurybox_display_message message CHECK "Distribution mandatory access control type configured: $EURYBOX_DISTRIB_MAC_TYPE"
;;
apparmor|* )
eurybox_display_message error CHECK "Unsupported mandatory access control type: $EURYBOX_DISTRIB_MAC_TYPE - please use selinux or none"
@@ -127,6 +126,7 @@ eurybox_check_configuration ()
EURYBOX_NMAP_OPTIONS="--host-timeout $EURYBOX_NETWORK_TIMEOUT --max-retries $EURYBOX_MAX_RETRY_ON_FAILURE"
EURYBOX_LS_OPTIONS="-x"
EURYBOX_MNT_NFS_OPTIONS="-o hard,retry=$EURYBOX_MAX_RETRY_ON_FAILURE,rsize=8192,wsize=8192,timeo=${EURYBOX_NETWORK_TIMEOUT}0"
EURYBOX_MNT_SSHFS_OPTIONS="-o allow_root,large_read ${EURYBOX_SSH_OPTIONS}"
case $EURYBOX_LOG_LEVEL in
debug )
set -xv
@@ -134,6 +134,7 @@ eurybox_check_configuration ()
EURYBOX_NMAP_OPTIONS+=" -d9 -v3"
EURYBOX_LS_OPTIONS+=" -a"
EURYBOX_MNT_NFS_OPTIONS+=" -v"
EURYBOX_MNT_SSHFS_OPTIONS+=" -oLogLevel=debug"
EURYBOX_VIRSH_OPTIONS+=" -q -d 0"
;;
verbose )
@@ -142,26 +143,31 @@ eurybox_check_configuration ()
EURYBOX_NMAP_OPTIONS+=" -d0 -v2"
EURYBOX_LS_OPTIONS+=" -l"
EURYBOX_MNT_NFS_OPTIONS+=" -v"
EURYBOX_MNT_SSHFS_OPTIONS+=" -oLogLevel=verbose"
EURYBOX_VIRSH_OPTIONS+=" -q -d 2"
;;
info )
EURYBOX_SSH_OPTIONS+=" -oLogLevel=info"
EURYBOX_NMAP_OPTIONS+=" -d0 -v"
EURYBOX_LS_OPTIONS+=" -l"
EURYBOX_MNT_SSHFS_OPTIONS+=" -oLogLevel=info"
EURYBOX_VIRSH_OPTIONS+=" -q -d 4"
;;
warning )
EURYBOX_SSH_OPTIONS+=" -oLogLevel=info"
EURYBOX_NMAP_OPTIONS+=" -d0 -v0"
EURYBOX_VIRSH_OPTIONS+=" -q"
EURYBOX_MNT_SSHFS_OPTIONS+=" -oLogLevel=info"
;;
error )
EURYBOX_SSH_OPTIONS+=" -oLogLevel=error"
EURYBOX_NMAP_OPTIONS+=" -d0 -v1"
EURYBOX_VIRSH_OPTIONS+=" -q"
EURYBOX_MNT_SSHFS_OPTIONS+=" -oLogLevel=error"
;;
esac
eurybox_display_message debug CHECK "ssh options: $EURYBOX_SSH_OPTIONS"
eurybox_display_message debug CHECK "sshfs options: $EURYBOX_MNT_SSHFS_OPTIONS"
eurybox_display_message debug CHECK "nmap options: $EURYBOX_NMAP_OPTIONS"
eurybox_display_message debug CHECK "ls options: $EURYBOX_LS_OPTIONS"
eurybox_display_message debug CHECK "nfs mount options: $EURYBOX_MNT_NFS_OPTIONS"
@@ -215,7 +221,7 @@ eurybox_check_distribution ()
fi
case $EURYBOX_DISTRIB_MAC_TYPE in
selinux )
SE_OUT=`sudo getenforce`
SE_OUT=`sudo getenforce 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
@@ -246,9 +252,12 @@ eurybox_check_distribution ()
#1 arg can be supplied as script type (BACKUP/UPDATE/EXEC_COMMAND) to add extra checks
eurybox_check_environment ()
{
SCRIPT_TYPE=$1
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 virsh sha512sum sha256sum awk pigz df tail virt-sysprep tput nmap rpcinfo pbzip2
eurybox_check_command grep sudo ssh openssl tar par2 virsh sha512sum sha256sum awk pigz df tail virt-sysprep tput nmap rpcinfo pbzip2 sshfs curlftpfs cryptsetup
#Check kernel capabilities
eurybox_check_kernel
#Check distribution is coherent with configuration
@@ -270,7 +279,6 @@ eurybox_check_environment ()
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
#TODO: $SCRIPT_TYPE = "RESTORE"
if [[ $SCRIPT_TYPE = "BACKUP" ]]
then
#Check tmp folder
@@ -286,46 +294,44 @@ eurybox_check_environment ()
fi
fi
#Check bkp destination (access + space left size)
case ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]} in
"SSH" )
SPACE_LEFT=`ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "df -Pk ${EURYBOX_BACKUP_DESTINATION[PATH]}/" | tail -1 | awk '{print $4}'`
STATUS=$?
if [[ !($STATUS -eq 0) || $SPACE_LEFT -eq "" ]]
then
eurybox_display_message warning CHECK "Status: $STATUS"
eurybox_display_message error CHECK "SSH backup destination connection failed"
fi
if (( $SPACE_LEFT < $EURYBOX_BACKUP_LOW_CRITICAL_LEVEL ))
then
eurybox_display_message error CHECK "Free space left on backup destination too low: $SPACE_LEFT kB"
else
if (( $SPACE_LEFT < $EURYBOX_BACKUP_LOW_WARNING_LEVEL ))
then
eurybox_display_message warning CHECK "Free space left on backup destination low: $SPACE_LEFT kB"
else
eurybox_display_message debug CHECK "Free space left on backup destination OK: $SPACE_LEFT kB"
fi
fi
;;
"NFS" )
eurybox_mount_backup_nfs
SPACE_LEFT=`sudo df -Pk ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/ | tail -1 | awk '{print $4}'`
if (( $SPACE_LEFT < $EURYBOX_BACKUP_LOW_CRITICAL_LEVEL ))
then
eurybox_display_message error CHECK "Free space left on backup destination too low: $SPACE_LEFT kB"
else
if (( $SPACE_LEFT < $EURYBOX_BACKUP_LOW_WARNING_LEVEL ))
then
eurybox_display_message warning CHECK "Free space left on backup destination low: $SPACE_LEFT kB"
else
eurybox_display_message debug CHECK "Free space left on backup destination OK: $SPACE_LEFT kB"
fi
fi
eurybox_umount_backup_nfs
;;
esac
#FIXME:Check permissions
#READ ORIGIN FOLDER / WRITE DESTINATION FOLDER
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_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 ))
then
eurybox_display_message warning CHECK "Free space left on backup destination low: $BKP_SPACE_LEFT kB"
else
eurybox_display_message debug CHECK "Free space left on backup destination OK: $BKP_SPACE_LEFT kB"
fi
fi
#Check bkp destination access (READ/WRITE)
BKP_ACCESS_OK=`sudo touch ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/test && sudo rm ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/test`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
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"
fi
eurybox_backup_umount_target
fi
#FOR RESTORE ONLY
if [[ $SCRIPT_TYPE = "RESTORE" ]]
then
#Check bkp origin access (READ)
eurybox_backup_mount_target
BKP_ACCESS_OK=`sudo ls -al ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
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"
fi
eurybox_backup_umount_target
fi
}

@@ -333,8 +339,12 @@ eurybox_check_environment ()
#No arg required
eurybox_check_hv_access ()
{
TYPE=$1
SYSINFOS=`sudo virsh $EURYBOX_VIRSH_OPTIONS sysinfo 2>&1`
local TYPE=$1
local STATUS
local NODEINFOS
local CAPABILITIES
local DOMCAPABILITIES
local SYSINFOS=`sudo virsh $EURYBOX_VIRSH_OPTIONS sysinfo 2>&1`
STATUS=$?
if [[ $STATUS -eq 0 ]]
then
@@ -342,12 +352,12 @@ eurybox_check_hv_access ()
NODEINFOS=`sudo virsh $EURYBOX_VIRSH_OPTIONS nodeinfo 2>&1`
CAPABILITIES=`sudo virsh $EURYBOX_VIRSH_OPTIONS capabilities 2>&1`
DOMCAPABILITIES=`sudo virsh $EURYBOX_VIRSH_OPTIONS domcapabilities 2>&1`
eurybox_display_message debug CHECK "$SYSINFOS"
eurybox_display_message debug CHECK "$NODEINFOS"
eurybox_display_message debug CHECK "$CAPABILITIES"
eurybox_display_message debug CHECK "$DOMCAPABILITIES"
eurybox_display_message debug CHECK "System informations:\n$SYSINFOS"
eurybox_display_message debug CHECK "Node informations:\n$NODEINFOS"
eurybox_display_message debug CHECK "Node capabilities:\n$CAPABILITIES"
eurybox_display_message debug CHECK "Dom capabilities:\n$DOMCAPABILITIES"
else
eurybox_display_message error CHECK "Hypervisor - access failed: $SYSINFOS_OK"
eurybox_display_message error CHECK "Hypervisor - access failed: \n$SYSINFOS_OK"
fi
}

@@ -355,12 +365,15 @@ eurybox_check_hv_access ()
#5 arg min required: vm_name vm_host ssh_user ssh_port disk [disk] ...
eurybox_check_vm_access ()
{
NAME=$1
HOST=$2
USER=$3
PORT=$4
DISK=${@:5:$#}
EURYBOX_VM_NAME=`sudo virsh $EURYBOX_VIRSH_OPTIONS list --all | grep $NAME 2>&1`
local NAME=$1
local HOST=$2
local USER=$3
local PORT=$4
local DISK=${@:5:$#}
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`
if [[ -z "$EURYBOX_VM_NAME" ]]
then
eurybox_display_message error CHECK "VM $NAME - virsh not found"
@@ -378,9 +391,9 @@ eurybox_check_vm_access ()
if [[ $STATUS -eq 0 ]]
then
eurybox_display_message message CHECK "VM $NAME - SSH connection OK"
eurybox_display_message debug CHECK "$EURYBOX_SSH_OK"
eurybox_display_message debug CHECK "SSH output:\n$EURYBOX_SSH_OK"
else
eurybox_display_message warning CHECK "VM $NAME - SSH connection failed: $EURYBOX_SSH_OK"
eurybox_display_message warning CHECK "VM $NAME - SSH connection failed:\n$EURYBOX_SSH_OK"
fi
fi
fi
@@ -392,10 +405,10 @@ eurybox_check_vm_access ()
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CHECK "VM $NAME - disk $DISK - access failed: $EURYBOX_DISK_OK"
eurybox_display_message warning CHECK "VM $NAME - disk $DISK - access failed:\n$EURYBOX_DISK_OK"
else
eurybox_display_message message CHECK "VM $NAME - disk $DISK - access OK"
eurybox_display_message debug CHECK "$EURYBOX_DISK_OK"
eurybox_display_message debug CHECK "Disk access output:\n$EURYBOX_DISK_OK"
fi
fi
}


+ 124
- 190
sw/src/eurybox.functions.create View File

@@ -4,6 +4,9 @@
#FIXME: extract function parameters to transfer to control section use and make functions more generic and reusable
eurybox_create_archive_desc ()
{
local DESC_OUT
local SYNC_OUT
local STATUS
#TODO: IMPLEMENT PARALLEL EXTRACTION FOR GZ AND BZ2
case ${EURYBOX_BACKUP_ARCHIVE[FORMAT]} in
"tar" ) TAR_OPTIONS="-Stv" ;;
@@ -11,95 +14,64 @@ eurybox_create_archive_desc ()
"tar.bz2" ) TAR_OPTIONS="-Stvj" ;;
esac
STATUS=1234
case ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]} in
"SSH" )
DESTINATION=${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.desc
echo "ARCHIVE_CORPORATE:$EURYBOX_CORPORATE" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "ARCHIVE_FILE:${EURYBOX_BACKUP_ARCHIVE[NAME]}" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "ARCHIVE_FORMAT:${EURYBOX_BACKUP_ARCHIVE[FORMAT]}" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "ARCHIVE_TARGETS:${EURYBOX_BACKUP_TARGETS[*]}" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "ARCHIVE_TYPE:$EURYBOX_BACKUP_TYPE" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "ARCHIVE_VERSION:$EURYBOX_VERSION" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "ECC_FILE:${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[ECC]}" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "ECC_FORMAT:${EURYBOX_BACKUP_ARCHIVE[ECC]}" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "ECC_LEVEL:${EURYBOX_BACKUP_ARCHIVE[ECC_LEVEL]\%}" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "HASH_FILE:${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[HASH]}" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "HASH_FORMAT:${EURYBOX_BACKUP_ARCHIVE[HASH]}" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "ENCRYPTED_ARCHIVE:${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]}" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
if [[ ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} = "true" ]]
then
echo "ENCRYPTION_ALGORITHM:${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]}" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
echo "ARCHIVE_CONTENT:" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
DESTINATION=${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.desc
DESC_OUT=`sudo sh -c "echo ARCHIVE_CONTENT:$EURYBOX_CORPORATE >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo ARCHIVE_FILE:${EURYBOX_BACKUP_ARCHIVE[NAME]} >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo ARCHIVE_FORMAT:${EURYBOX_BACKUP_ARCHIVE[FORMAT]} >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo ARCHIVE_TARGETS:${EURYBOX_BACKUP_TARGETS[*]} >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo ARCHIVE_TYPE:$EURYBOX_BACKUP_TYPE >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo ARCHIVE_VERSION:$EURYBOX_VERSION >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo ECC_FILE:${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[ECC]} >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo ECC_FORMAT:${EURYBOX_BACKUP_ARCHIVE[ECC]} >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo ECC_LEVEL:${EURYBOX_BACKUP_ARCHIVE[ECC_LEVEL]\%} >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo HASH_FILE:${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[HASH]} >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo HASH_FORMAT:${EURYBOX_BACKUP_ARCHIVE[HASH]} >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo ENCRYPTED_ARCHIVE:${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} >> $DESTINATION" 2>&1`
if [[ ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} = "true" ]]
then
DESC_OUT=`sudo sh -c "echo ENCRYPTION_ALGORITHM:${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} >> $DESTINATION" 2>&1`
DESC_OUT=`sudo sh -c "echo ARCHIVE_CONTENT: >> $DESTINATION" 2>&1`
#FIXME: function to read archive with variable archive format required here
DESC_OUT=$((
(
ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat ${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]}" | sudo openssl enc -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -d -k ${EURYBOX_BACKUP_ARCHIVE[PASSWORD]} | sudo tar ${TAR_OPTIONS} | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
)) 2>&1)
STATUS=$?
else
echo "ARCHIVE_CONTENT:" | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
#FIXME: function to read archive with variable archive format required here
DESC_OUT=$((
(
ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat ${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]}" | sudo tar ${TAR_OPTIONS} | ssh -o "PasswordAuthentication no" -o "ConnectTimeout $EURYBOX_NETWORK_TIMEOUT" -o "ConnectionAttempts $EURYBOX_MAX_RETRY_ON_FAILURE" -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
)) 2>&1)
STATUS=$?
fi
;;
"NFS" )
DESTINATION=${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.desc
eurybox_mount_backup_nfs
sudo echo "ARCHIVE_CONTENT:$EURYBOX_CORPORATE" >> $DESTINATION
sudo echo "ARCHIVE_FILE:${EURYBOX_BACKUP_ARCHIVE[NAME]}" >> $DESTINATION
sudo echo "ARCHIVE_FORMAT:${EURYBOX_BACKUP_ARCHIVE[FORMAT]}" >> $DESTINATION
sudo echo "ARCHIVE_TARGETS:${EURYBOX_BACKUP_TARGETS[*]}" >> $DESTINATION
sudo echo "ARCHIVE_TYPE:$EURYBOX_BACKUP_TYPE" >> $DESTINATION
sudo echo "ARCHIVE_VERSION:$EURYBOX_VERSION" >> $DESTINATION
sudo echo "ECC_FILE:${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[ECC]}" >> $DESTINATION
sudo echo "ECC_FORMAT:${EURYBOX_BACKUP_ARCHIVE[ECC]}" >> $DESTINATION
sudo echo "ECC_LEVEL:${EURYBOX_BACKUP_ARCHIVE[ECC_LEVEL]\%}" >> $DESTINATION
sudo echo "HASH_FILE:${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[HASH]}" >> $DESTINATION
sudo echo "HASH_FORMAT:${EURYBOX_BACKUP_ARCHIVE[HASH]}" >> $DESTINATION
sudo echo "ENCRYPTED_ARCHIVE:${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]}" >> $DESTINATION
if [[ ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} = "true" ]]
then
sudo echo "ENCRYPTION_ALGORITHM:${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]}" >> $DESTINATION
sudo echo "ARCHIVE_CONTENT:" >> $DESTINATION
#FIXME: function to read archive with variable archive format required here
DESC_OUT=$((
(
sudo openssl enc -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -d -in ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]} -k ${EURYBOX_BACKUP_ARCHIVE[PASSWORD]} | sudo tar ${TAR_OPTIONS} >> $DESTINATION
DESC_OUT=$((
(
sudo sh -c "openssl enc -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -d -in ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]} -k ${EURYBOX_BACKUP_ARCHIVE[PASSWORD]} | tar ${TAR_OPTIONS} >> $DESTINATION"
# STATUS=$(( ${PIPESTATUS[0]} + ${PIPESTATUS[1]} ))
)) 2>&1)
STATUS=$?
else
sudo echo "ARCHIVE_CONTENT:" >> $DESTINATION
#FIXME: function to read archive with variable archive format required here
DESC_OUT=$((
(
sudo tar ${TAR_OPTIONS}f ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]} >> $DESTINATION
)) 2>&1)
STATUS=$?
fi
eurybox_umount_backup_nfs
;;
* )
eurybox_display_message error CREATE "Unkown backup destination protocol: ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]}"
;;
esac
)) 2>&1)
STATUS=$?
else
DESC_OUT=`sudo sh -c "sudo echo ARCHIVE_CONTENT: >> $DESTINATION" 2>&1`
#FIXME: function to read archive with variable archive format required here
DESC_OUT=$((
(
sudo sh -c "tar ${TAR_OPTIONS}f ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]} >> $DESTINATION"
)) 2>&1)
STATUS=$?
fi
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive description creation failed / error $STATUS --> $DESC_OUT"
eurybox_display_message warning CREATE "Archive description creation failed - error $STATUS:\n$DESC_OUT"
else
eurybox_display_message message CREATE "Archive description creation - OK"
eurybox_display_message debug CREATE "$DESC_OUT"
eurybox_display_message debug CREATE "Description command output:\n$DESC_OUT"
SYNC_OUT=`sudo sync 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive description FS sync failed - error $STATUS:\n$SYNC_OUT"
else
eurybox_display_message message CREATE "Archive description FS sync - OK"
eurybox_display_message debug CREATE "Sync command output:\n$SYNC_OUT"
fi
fi
}

#FIXME: extract function parameters to transfer to control section use and make functions more generic and reusable
eurybox_create_archive_tar ()
{
if [[ $EURYBOX_LOG_LEVEL = "debug" ]]
local TAR_OUT
local SYNC_OUT
local STATUS
if [[ $EURYBOX_LOG_LEVEL = "debug" || $EURYBOX_LOG_LEVEL = "verbose" ]]
then
TAR_OPTIONS="-v"
else
@@ -111,153 +83,115 @@ eurybox_create_archive_tar ()
"tar.bz2" ) TAR_OPTIONS="${TAR_OPTIONS}Sc --use-compress-program=pbzip2 " ;;
#xz
esac
case ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]} in
"SSH" )
if [[ ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} = "true" ]]
then
TAR_OUT=$((
(
sudo tar $TAR_OPTIONS ${EURYBOX_BACKUP_TARGETS[*]} | sudo openssl enc -salt -e -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -k ${EURYBOX_BACKUP_ARCHIVE[PASSWORD]} | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat > ${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]}"
#STATUS=$(( ${PIPESTATUS[0]} + ${PIPESTATUS[1]} + ${PIPESTATUS[2]} ))
)) 2>&1)
STATUS=$?
else
TAR_OUT=$((
(
sudo tar $TAR_OPTIONS ${EURYBOX_BACKUP_TARGETS[*]} | ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat > ${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]}"
#STATUS=$(( ${PIPESTATUS[0]} + ${PIPESTATUS[1]} ))
)) 2>&1)
STATUS=$?
fi
;;
"NFS" )
eurybox_mount_backup_nfs
if [[ ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} = "true" ]]
then
TAR_OUT=$((
(
sudo tar ${TAR_OPTIONS} ${EURYBOX_BACKUP_TARGETS[*]} | sudo openssl enc -salt -e -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -k ${EURYBOX_BACKUP_ARCHIVE[PASSWORD]} -out ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]}
if [[ ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} = "true" ]]
then
TAR_OUT=$((
(
sudo tar ${TAR_OPTIONS} ${EURYBOX_BACKUP_TARGETS[*]} | sudo openssl enc -salt -e -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -k ${EURYBOX_BACKUP_ARCHIVE[PASSWORD]} -out ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]}
# STATUS=$(( ${PIPESTATUS[0]} + ${PIPESTATUS[1]} ))
)) 2>&1)
STATUS=$?
else
TAR_OUT=`sudo tar ${TAR_OPTIONS} -f ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]} ${EURYBOX_BACKUP_TARGETS[*]} 2>&1`
STATUS=$?
fi
eurybox_umount_backup_nfs
;;
* )
eurybox_display_message error CREATE "Unkown backup destination protocol: ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]}"
;;
esac
)) 2>&1)
STATUS=$?
else
TAR_OUT=`sudo tar ${TAR_OPTIONS} -f ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]} ${EURYBOX_BACKUP_TARGETS[*]} 2>&1`
STATUS=$?
fi
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message error CREATE "Archive creation - failed / error: $STATUS --> $TAR_OUT. Continuing anyway"
eurybox_display_message error CREATE "Archive creation failed - error: $STATUS:\n$TAR_OUT"
else
eurybox_display_message message CREATE "Archive creation - OK"
eurybox_display_message debug CREATE "$TAR_OUT"
eurybox_display_message debug CREATE "Tar command output:\n$TAR_OUT"
SYNC_OUT=`sudo sync 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive description FS sync failed - error: $STATUS:\n$SYNC_OUT"
else
eurybox_display_message message CREATE "Archive description FS sync - OK"
eurybox_display_message debug CREATE "Sync command output:\n$SYNC_OUT"
fi
fi
}

#FIXME: extract function parameters to transfer to control section use and make functions more generic and reusable
eurybox_create_archive_par ()
{
local PAR_OUT
local SYNC_OUT
local STATUS
case $EURYBOX_LOG_LEVEL in
"debug" ) PAR_OPTIONS="-v -v";;
"message" ) PAR_OPTIONS="-v";;
"warning" ) PAR_OPTIONS="-q";;
"error" ) PAR_OPTIONS="-q -q";;
debug|verbose ) PAR_OPTIONS="-v -v";;
message ) PAR_OPTIONS="-v";;
warning ) PAR_OPTIONS="-q";;
error ) PAR_OPTIONS="-q -q";;
esac
case ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]} in
SSH )
DESTINATION=${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[ECC]}
case "${EURYBOX_BACKUP_ARCHIVE[ECC]}" in
"par2" )
#FIXME: par2 doesn't work on input, but need a file...
# ssh -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat ${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}" | sudo par2 c $PAR_OPTIONS -r${EURYBOX_BACKUP_ARCHIVE[ECC_LEVEL]} -t+ ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[ECC]} | ssh -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "cat >> $DESTINATION"
# STATUS=$?
PAR_OUT="Not Available Yet"
STATUS=1
;;
* )
eurybox_display_message error CREATE "Archive ecc format unknown: ${EURYBOX_BACKUP_ARCHIVE[HASH]}"
;;
esac
;;
NFS )
eurybox_mount_backup_nfs
case "${EURYBOX_BACKUP_ARCHIVE[ECC]}" in
"par2" )
PAR_OUT=`sudo par2 c $PAR_OPTIONS -r${EURYBOX_BACKUP_ARCHIVE[ECC_LEVEL]} -t+ ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[ECC]} ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]} 2>&1`
STATUS=$?
;;
* )
eurybox_display_message error CREATE "Archive ecc format unknown: ${EURYBOX_BACKUP_ARCHIVE[HASH]}"
;;
esac
eurybox_umount_backup_nfs
;;
case "${EURYBOX_BACKUP_ARCHIVE[ECC]}" in
"par2" )
PAR_OUT=`sudo par2 c $PAR_OPTIONS -r${EURYBOX_BACKUP_ARCHIVE[ECC_LEVEL]} -t+ ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[ECC]} ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]} 2>&1`
STATUS=$?
;;
* )
eurybox_display_message error CREATE "Archive backup destination protocol unknown: ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]}"
eurybox_display_message error CREATE "Archive ecc format unknown: ${EURYBOX_BACKUP_ARCHIVE[HASH]}"
;;
esac
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning ARCHIVE "Archive ecc creation - failed: $PAR_OUT. Continuing anyway"
eurybox_display_message warning ARCHIVE "Archive ecc creation failed - error $STATUS:\n$PAR_OUT"
else
eurybox_display_message message CREATE "Archive ecc creation - OK"
eurybox_display_message debug CREATE "$PAR_OUT"
eurybox_display_message debug CREATE "Ecc command output:\n$PAR_OUT"
SYNC_OUT=`sudo sync 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive description FS sync failed - error $STATUS:\n$SYNC_OUT"
else
eurybox_display_message message CREATE "Archive description FS sync - OK"
eurybox_display_message debug CREATE "Sync command output:\n$SYNC_OUT"
fi
fi
}

#FIXME: extract function parameters to transfer to control section use and make functions more generic and reusable
eurybox_create_archive_sha ()
{
local SHA_OUT
local SYNC_OUT
local STATUS
case $EURYBOX_LOG_LEVEL in
"debug" ) SHA_OPTIONS="";;
"message" ) SHA_OPTIONS="";;
"warning" ) SHA_OPTIONS="";;
"error" ) SHA_OPTIONS="";;
debug|verbose ) SHA_OPTIONS="";;
message ) SHA_OPTIONS="";;
warning ) SHA_OPTIONS="";;
error ) SHA_OPTIONS="";;
esac
case ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]} in
SSH )
case "${EURYBOX_BACKUP_ARCHIVE[HASH]}" in
"sha256" )
SHA_OUT=`ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "sha256sum $SHA_OPTIONS ${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}* > ${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[HASH]}" 2<&1`
;;
"sha512" )
SHA_OUT=`ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "sha512sum $SHA_OPTIONS ${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}* > ${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[HASH]}" 2<&1`
;;
* )
eurybox_display_message error CREATE "Archive hash format unknown: ${EURYBOX_BACKUP_ARCHIVE[HASH]}"
;;
esac
case "${EURYBOX_BACKUP_ARCHIVE[HASH]}" in
"sha256" )
SHA_OUT=`sudo sh -c "sha256sum $SHA_OPTIONS ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}* > ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[HASH]}" 2<&1`
STATUS=$?
;;
"sha512" )
SHA_OUT=`sudo sh -c "sha512sum $SHA_OPTIONS ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}* > ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[HASH]}" 2<&1`
STATUS=$?
;;
NFS )
eurybox_mount_backup_nfs
case "${EURYBOX_BACKUP_ARCHIVE[HASH]}" in
"sha256" )
SHA_OUT=`sudo sh -c "sha256sum $SHA_OPTIONS ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}* > ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[HASH]}" 2<&1`
STATUS=$?
;;
"sha512" )
SHA_OUT=`sudo sh -c "sha512sum $SHA_OPTIONS ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}* > ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[HASH]}" 2<&1`
STATUS=$?
;;
* )
eurybox_display_message error CREATE "Archive hash format unknown: ${EURYBOX_BACKUP_ARCHIVE[HASH]}"
;;
esac
eurybox_umount_backup_nfs
;;
;;
* )
eurybox_display_message error CREATE "Archive hash format unknown: ${EURYBOX_BACKUP_ARCHIVE[HASH]}"
;;
esac
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive hash creation failed. Continuing anyway."
eurybox_display_message warning CREATE "Archive hash creation failed - error $STATUS:\n$SHA_OUT"
else
eurybox_display_message message CREATE "Archive hash creation - OK"
eurybox_display_message debug CREATE "$SHA_OUT"
eurybox_display_message debug CREATE "Hash command output:\n$SHA_OUT"
SYNC_OUT=`sudo sync 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive description FS sync failed - error $STATUS:\n$SYNC_OUT"
else
eurybox_display_message message CREATE "Archive description FS sync - OK"
eurybox_display_message debug CREATE "Sync command output:\n$SYNC_OUT"
fi
fi
}


+ 95
- 64
sw/src/eurybox.functions.detect View File

@@ -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]}


+ 31
- 6
sw/src/eurybox.functions.euryboxctrl View File

@@ -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
}


+ 103
- 142
sw/src/eurybox.functions.tools View File

@@ -2,28 +2,48 @@
#EuryBOX tools functions file

#Desc: change file(s) permissions
#FIXME: extract function parameters to transfer to control section use and make functions more generic and reusable (no more only bkp files)
#1 arg required: permission mask
eurybox_change_files_permissions ()
#3 arg required: file dac_owner dac_mask (chmod mask) mac_mask (SE context)
eurybox_change_file_permissions ()
{
MASK=$1
case ${EURYBOX_BACKUP_DESTINATION[PROTOCOL]} in
SSH )
MASK_OUT=`ssh $EURYBOX_SSH_OPTIONS -p ${EURYBOX_BACKUP_DESTINATION[PORT]} ${EURYBOX_BACKUP_DESTINATION[USER]}@${EURYBOX_BACKUP_DESTINATION[HOST]} "chmod -R $MASK ${EURYBOX_BACKUP_DESTINATION[PATH]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}*" 2<&1`
STATUS=$?
;;
NFS )
eurybox_mount_backup_nfs
MASK_OUT=`sudo sh -c "sudo chmod -R $MASK ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}*" 2<&1`
STATUS=$?
eurybox_umount_backup_nfs
;;
esac
local FILE=$1
local DAC_OWNER=$2
local DAC_MASK=$3
local MAC_MASK=$4
local PERMISSIONS_OUT
PERMISSIONS_OUT=`sudo sh -c "sudo chmod -R $DAC_MASK $FILE" 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning TOOLS "DAC mask change failed - error $STATUS:\n$PERMISSIONS_OUT"
else
eurybox_display_message message TOOLS "DAC mask changed with success"
eurybox_display_message debug TOOLS "DAC mask output command:\n$PERMISSIONS_OUT"
fi
PERMISSIONS_OUT=`sudo sh -c "sudo chown -R $DAC_OWNER $FILE" 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning TOOLS "DAC owner change failed - error $STATUS:\n$PERMISSIONS_OUT"
else
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) ]]
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
PERMISSIONS_OUT=`sudo ls -aZ $FILE 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning TOOLS "Permissions change failed: $MASK_OUT"
eurybox_display_message warning TOOLS "Permissions listing failed - error $STATUS:\n$PERMISSIONS_OUT"
else
eurybox_display_message message TOOLS "Permissions changed: $MASK_OUT"
eurybox_display_message message TOOLS "Final files permissions:\n$PERMISSIONS_OUT"
fi
}

@@ -31,17 +51,17 @@ eurybox_change_files_permissions ()
#3 args required: level(debug, message, warning, error) category message
eurybox_display_message ()
{
LEVEL=$1
CATEGORY=$2
MESSAGE=$3
NOW=$(date +"%Y_%m_%d@%H:%M:%S")
local LEVEL=$1
local CATEGORY=$2
local MESSAGE=$3
local NOW=$(date +"%Y_%m_%d@%H:%M:%S")
case $LEVEL in
debug )
if [[ $EURYBOX_LOG_LEVEL = "debug" || $EURYBOX_LOG_LEVEL = "verbose" ]]
then
tput setb 0
tput setaf 6
echo "$NOW [EURYBOX][DEBUG][$CATEGORY] $MESSAGE"
printf "$NOW [EURYBOX][DEBUG][$CATEGORY] %b\n" "$MESSAGE"
fi
;;
message )
@@ -49,7 +69,7 @@ eurybox_display_message ()
then
tput setb 0
tput setaf 2
echo "$NOW [EURYBOX][MESSAGE][$CATEGORY] $MESSAGE"
printf "$NOW [EURYBOX][INFO][$CATEGORY] %b\n" "$MESSAGE"
fi
;;
warning )
@@ -57,7 +77,7 @@ eurybox_display_message ()
then
tput setb 0
tput setaf 1
echo "$NOW [EURYBOX][WARNING][$CATEGORY] $MESSAGE"
printf "$NOW [EURYBOX][WARNING][$CATEGORY] %b\n" "$MESSAGE"
fi
;;
error )
@@ -65,16 +85,16 @@ eurybox_display_message ()
then
tput setb 0
tput setaf 1
echo "$NOW [EURYBOX][ERROR][$CATEGORY] $MESSAGE"
printf "$NOW [EURYBOX][ERROR][$CATEGORY] %b\n" "$MESSAGE"
tput setb 0
tput sgr0
echo "Stopping script execution"
printf "Stopping script execution\n"
exit 1
fi
;;
* )
tput sgr0
echo "$NOW [EURYBOX][ERROR][SYNTAX] Bad log level message. Stopping script execution"
printf "$NOW [EURYBOX][ERROR][SYNTAX] Bad log level message. Stopping script execution\n"
exit 1
;;
esac
@@ -86,22 +106,25 @@ eurybox_display_message ()
#No arg required
eurybox_display_detected_archives ()
{
local ARCH_DESC
for (( ARCH_NUM=0;ARCH_NUM<${EURYBOX_DETECTED_ARCHIVES[NUM]};ARCH_NUM++ ))
do
NAME=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,NAME]}
TIME=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]}
ENC=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,ENC]}
COMP=${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,COMP]}
YEAR=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $1 }'`
MONTH=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $2 }'`
DAY=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $3 }'`
HOUR=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $4 }'`
MINUTE=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $5 }'`
SECOND=`echo ${EURYBOX_DETECTED_ARCHIVES[$ARCH_NUM,TIME]} | awk -F"_" '{ print $6 }'`
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 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 }'`
if [[ $NAME != $PREVIOUS_NAME ]]
then
echo "------------ [[ ARCHIVE: $NAME ]] ------------"
echo "YEAR \\ MONTH \\ DAY @ HOUR:MINUTE:SECOND | ENC | COMP | ID"
echo "YEAR \\ MONTH \\ DAY @ HOUR:MINUTE:SECOND | TYPE | VERS | ENC | COMP | ID"
PREVIOUS_YEAR=""
PREVIOUS_MONTH=""
fi
@@ -119,6 +142,25 @@ eurybox_display_detected_archives ()
ARCH_DESC="$ARCH_DESC "
fi
ARCH_DESC="$ARCH_DESC \\ $DAY @ $HOUR : $MINUTE : $SECOND "
case $TYPE in
vm_cold|vm_hot )
ARCH_DESC="$ARCH_DESC | VM "
;;
full_hot|full_cold )
ARCH_DESC="$ARCH_DESC | FULL"
;;
* )
ARCH_DESC="$ARCH_DESC | ? "
;;
esac
case $VERS in
"" )
ARCH_DESC="$ARCH_DESC | ? "
;;
* )
ARCH_DESC="$ARCH_DESC | $VERS "
;;
esac
case $ENC in
false )
ARCH_DESC="$ARCH_DESC | "
@@ -134,14 +176,15 @@ eurybox_display_detected_archives ()
none )
ARCH_DESC="$ARCH_DESC | "
;;
"tar.bz" )
tar.bz2 )
ARCH_DESC="$ARCH_DESC |BZIP2"
;;
"tar.gz" )
tar.gz )
ARCH_DESC="$ARCH_DESC | GZIP"
;;
* )
ARCH_DESC="$ARCH_DESC | ? "
echo "$COMP"
;;
esac
ARCH_DESC="$ARCH_DESC | $ARCH_NUM"
@@ -156,12 +199,13 @@ eurybox_display_detected_archives ()
#4 args required: host port user command
eurybox_exec_ssh_command ()
{
HOST=$1
PORT=$2
USER=$3
CMD=$4
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
STATUS=1234
local HOST=$1
local PORT=$2
local USER=$3
local CMD=$4
local CMD_OUT
local NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
local STATUS=1234
while [[ !( $STATUS -eq 0 ) && !( $NB_TRY_LEFT -eq 0 ) ]]
do
CMD_OUT=`ssh -p ${PORT} ${USER}@${HOST} "${CMD}" 2>&1`
@@ -169,122 +213,39 @@ eurybox_exec_ssh_command ()
if [[ $STATUS -eq 0 ]]
then
eurybox_display_message message TOOLS "Command execution - OK: $CMD"
eurybox_display_message debug TOOLS "$CMD_OUT"
eurybox_display_message debug TOOLS "Command execution output:\n$CMD_OUT"
else
eurybox_display_message warning TOOLS "Command execution - failed - trying again in 5 seconds / $NB_TRY_LEFT left: $CMD_OUT"
eurybox_display_message warning TOOLS "Command execution failed - trying again in 5 seconds - error $STATUS:\n$CMD_OUT\n$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error TOOLS "Command execution - failed - $CMD: $CMD_OUT"
eurybox_display_message error TOOLS "Command execution failed - $CMD:\n$CMD_OUT"
fi
}

#Desc: flush a directory
#1 arg required: flush_directory
#1 arg required: flushed_directory
eurybox_flush_directory ()
{
T_PATH=$1
local T_PATH=$1
local FLUSH_OUT
local STATUS
if [[ !( $T_PATH = "") && !( $T_PATH = "/" ) && !( $T_PATH == *"/etc"* ) && !( $T_PATH == *"/proc"* ) && !( $T_PATH = "/home" ) && !( $T_PATH == *"/bin"* ) && !( $T_PATH == *"/boot"*) && !( $T_PATH == *"/lib"*) && !($T_PATH == *"/lib64"*) && !($T_PATH == *"/sbin"*) && !($T_PATH == *"/usr"*) ]]
then
sudo rm -Rf $T_PATH/*
FLUSH_OUT=`sudo rm -Rf $T_PATH/* 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning TOOLS "Directory flush failed: $T_PATH"
eurybox_display_message warning TOOLS "Directory $T_PATH flush failed - error $STATUS:\n$FLUSH_OUT"
else
eurybox_display_message message TOOLS "Directory flushed: $T_PATH"
eurybox_display_message message TOOLS "Directory $T_PATH flushed"
eurybox_display_message debug TOOLS "Flush command output:\n$FLUSH_OUT"
fi
else
eurybox_display_message warning TOOLS "Forbidden directory flush attempt: $T_PATH"
fi
}

#Desc: mount an nfs backup target folder
#FIXME: extract function parameters to transfer to control section use and make functions more generic and reusable
eurybox_mount_backup_nfs ()
{
if [[ !(-d ${EURYBOX_BACKUP_DESTINATION[MOUNT]}) ]]
then
sudo mkdir -p ${EURYBOX_BACKUP_DESTINATION[MOUNT]}
L_STATUS=$?
if [[ !($L_STATUS -eq 0) ]]
then
eurybox_display_message error TOOLS "Mount point ${EURYBOX_BACKUP_DESTINATION[MOUNT]} doesn't exists and folder creation failed"
else
eurybox_display_message message TOOLS "NFS local mountpoint ${EURYBOX_BACKUP_DESTINATION[MOUNT]} successfully created"
fi
fi
L_STATUS=1234
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
while [[ !($L_STATUS -eq 0) && ($(grep ${EURYBOX_BACKUP_DESTINATION[MOUNT]} /proc/mounts) = "") && !($NB_TRY_LEFT -eq 0) ]]
do
#Is NFS server available?
NFS_OUT=`sudo nmap $EURYBOX_NMAP_OPTIONS -p 2049 ${EURYBOX_BACKUP_DESTINATION[HOST]} | grep open 2>&1`
L_STATUS=$?
if [[ !($L_STATUS -eq 0) ]]
then
eurybox_display_message warning TOOLS "Backup destination NFS server unreacheable - trying to contact again in 5 seconds / $NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
else
eurybox_display_message debug TOOLS "Backup destination NFS server reached"
NFS_OUT=`sudo rpcinfo -t ${EURYBOX_BACKUP_DESTINATION[HOST]} nfs 2>&1`
L_STATUS=$?
if [[ !($L_STATUS -eq 0) ]]
then
eurybox_display_message warning TOOLS "Backup destination NFS server not registred on destination - trying to contact again in 5 seconds / $NB_TRY_LEFT left: $NFS_OUT"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
else
MOUNT_OUT=`sudo mount $EURYBOX_MNT_NFS_OPTIONS -t ${EURYBOX_BACKUP_DESTINATION[TYPE]} ${EURYBOX_BACKUP_DESTINATION[HOST]}:${EURYBOX_BACKUP_DESTINATION[PATH]} ${EURYBOX_BACKUP_DESTINATION[MOUNT]} 2>&1`
L_STATUS=$?
if [[ !($L_STATUS -eq 0) ]]
then
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message warning TOOLS "Backup destination NFS mount failed and target folder is empty - trying to mount again in 5 seconds / $NB_TRY_LEFT left: $MOUNT_OUT"
sleep 5
fi
fi
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error TOOLS "Backup destination NFS mount failed : $MOUNT_OUT"
eurybox_display_message debug TOOLS "$NFS_OUT"
eurybox_display_message debug TOOLS ""
else
eurybox_display_message message TOOLS "Backup destination NFS mount success"
eurybox_display_message debug TOOLS "$NFS_OUT"
eurybox_display_message debug TOOLS "$MOUNT_OUT"
fi
}

#Desc: un-mount an nfs backup target folder
#FIXME: extract function parameters to transfer to control section use and make functions more generic and reusable
eurybox_umount_backup_nfs ()
{
L_STATUS=1234
NB_TRY_LEFT=$EURYBOX_MAX_RETRY_ON_FAILURE
while [[ !($L_STATUS -eq 0) && !($(grep ${EURYBOX_BACKUP_DESTINATION[MOUNT]} /proc/mounts) = "") && !($NB_TRY_LEFT -eq 0) ]]
do
UMOUNT_OUT=`sudo umount ${EURYBOX_BACKUP_DESTINATION[MOUNT]} 2>&1`
L_STATUS=$?
if [[ !($L_STATUS -eq 0) ]]
then
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
eurybox_display_message warning TOOLS "Backup destination NFS unmount failed and target folder is not empty. Trying to unmount again in 5 seconds / $NB_TRY_LEFT left: $UMOUNT_OUT"
sleep 5
fi
done
if [[ $NB_TRY_LEFT -eq 0 ]]
then
eurybox_display_message error TOOLS "Backup destination NFS unmount failed: $UMOUNT_OUT"
else
eurybox_display_message message TOOLS "Backup destination NFS unmount success"
eurybox_display_message debug TOOLS "$UMOUNT_OUT"
eurybox_display_message warning TOOLS "Forbidden directory flush attempt: $T_PATH is not removable"
fi
}


+ 4
- 4
sw/src/eurybox.functions.update View File

@@ -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
}



+ 32
- 23
sw/src/eurybox.functions.vm View File

@@ -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"
fi
sleep 5
fi


Loading…
Cancel
Save