Highly Available and Scalable Information System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
8.3 KiB

#!/bin/bash
#EuryBOX create functions file
#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
local DESCRIPTION
case ${EURYBOX_BACKUP_ARCHIVE[FORMAT]} in
"tar" ) TAR_OPTIONS="-Stv";;
"tar.gz" ) TAR_OPTIONS="-Stv --use-compress-program=pigz";;
"tar.bz2" ) TAR_OPTIONS="-Stv --use-compress-program=pbzip2";;
esac
STATUS=1234
DESTINATION=${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.desc
DESCRIPTION="ARCHIVE_CORPORATE:${EURYBOX_CORPORATE}\nARCHIVE_FORMAT:${EURYBOX_BACKUP_ARCHIVE[FORMAT]}\nARCHIVE_TARGETS:${EURYBOX_BACKUP_TARGETS[*]}\nARCHIVE_TYPE:${EURYBOX_BACKUP_TYPE}\nARCHIVE_VERSION:${EURYBOX_VERSION}\nFEC_FORMAT:${EURYBOX_BACKUP_ARCHIVE[FEC]}\nHASH_FORMAT:${EURYBOX_BACKUP_ARCHIVE[HASH]}\nENCRYPTED_ARCHIVE:${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]}\n"
if [[ ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} = "true" ]]
then
DESCRIPTION+="ENCRYPTION_ALGORITHM:${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]}\nARCHIVE_CONTENT:\n"
#FIXME: function to read archive with variable archive format required here
DESCRIPTION+=`sudo sh -c "openssl enc -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -d -in ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]} -pass file:${EURYBOX_BACKUP_ARCHIVE[PASSFILE]} | tar ${TAR_OPTIONS}" 2>&1`
STATUS=$?
else
DESCRIPTION+="ARCHIVE_CONTENT:\n"
#FIXME: function to read archive with variable archive format required here
DESCRIPTION+=`sudo sh -c "tar ${TAR_OPTIONS} -f ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]}" 2>&1`
STATUS=$?
fi
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive description creation failed - error $STATUS:\n$DESCRIPTION"
else
DESC_OUT=`sudo sh -c "printf %b \"$DESCRIPTION\" > $DESTINATION" 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive description write failed - error $STATUS:\n$DESC_OUT"
else
eurybox_display_message message CREATE "Archive description creation - OK"
eurybox_display_message debug CREATE "Description:\n$DESCRIPTION"
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
fi
}
#FIXME: extract function parameters to transfer to control section use and make functions more generic and reusable
eurybox_create_archive_tar ()
{
local TAR_OUT
local SYNC_OUT
local STATUS
if [[ $EURYBOX_LOG_LEVEL = "debug" || $EURYBOX_LOG_LEVEL = "verbose" ]]
then
TAR_OPTIONS="-v"
else
TAR_OPTIONS="-"
fi
case ${EURYBOX_BACKUP_ARCHIVE[FORMAT]} in
"tar" ) TAR_OPTIONS="${TAR_OPTIONS}Sch";;
"tar.gz" ) TAR_OPTIONS="${TAR_OPTIONS}Sch --use-compress-program=pigz";;
"tar.bz2" ) TAR_OPTIONS="${TAR_OPTIONS}Sch --use-compress-program=pbzip2";;
esac
if [[ ${EURYBOX_BACKUP_ARCHIVE[ENCRYPT]} = "true" ]]
then
TAR_OUT=$((
(
sudo sh -c "tar ${TAR_OPTIONS} ${EURYBOX_BACKUP_TARGETS[*]} | openssl enc -salt -e -${EURYBOX_BACKUP_ARCHIVE[ENC_ALGO]} -pass file:${EURYBOX_BACKUP_ARCHIVE[PASSFILE]} -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 sh -c "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 warning CREATE "Archive creation failed - error: $STATUS:\n$TAR_OUT"
else
eurybox_display_message message CREATE "Archive creation - OK"
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 creation FS sync failed - error: $STATUS:\n$SYNC_OUT"
else
eurybox_display_message message CREATE "Archive creation FS sync - OK"
eurybox_display_message debug CREATE "Sync command output:\n$SYNC_OUT"
fi
fi
}
#FIXME: par2 has issues with curlftpfs - flush failed (ftpfs: operation ftpfs_write failed because Input/output error)
#FIXME: extract function parameters to transfer to control section use and make functions more generic and reusable
eurybox_create_archive_fec ()
{
local FEC_OUT
local SYNC_OUT
local STATUS
local FEC_LEVEL="${EURYBOX_BACKUP_ARCHIVE[FEC_LEVEL]}"
local FEC_TYPE="${EURYBOX_BACKUP_ARCHIVE[FEC]}"
local FEC_FILE_NUM="${EURYBOX_BACKUP_ARCHIVE[FEC_FILE_NUM]}"
local FEC_FILE_NUM_MIN="${EURYBOX_BACKUP_ARCHIVE[FEC_FILE_NUM_MIN]}"
local FEC_TARGET="${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FORMAT]}"
local FEC_DESTINATION="${EURYBOX_BACKUP_DESTINATION[MOUNT]}/${EURYBOX_BACKUP_ARCHIVE[NAME]}.${EURYBOX_BACKUP_ARCHIVE[FEC]}"
case $EURYBOX_LOG_LEVEL in
debug|verbose ) FEC_OPTIONS="-v";;
message ) FEC_OPTIONS="";;
warning ) FEC_OPTIONS="";;
error ) FEC_OPTIONS="-q";;
esac
case "$FEC_TYPE" in
par2 )
FEC_OUT=`sudo sh -c "par2 c $FEC_OPTIONS -r${FEC_LEVEL} -n${FEC_FILE_NUM} -u ${FEC_TARGET}" 2>&1`
STATUS=$?
;;
zfec )
FEC_OUT=`sudo sh -c "zfec $FEC_OPTIONS -m ${FEC_FILE_NUM} -k ${FEC_FILE_NUM_MIN} ${FEC_TARGET}" 2>&1`
STATUS=$?
;;
* )
eurybox_display_message error CREATE "Archive FEC format unknown: ${EURYBOX_BACKUP_ARCHIVE[FEC]}"
;;
esac
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning ARCHIVE "Archive FEC creation failed - error $STATUS:\n$FEC_OUT"
else
eurybox_display_message message CREATE "Archive FEC creation - OK"
eurybox_display_message debug CREATE "FEC command output:\n$FEC_OUT"
SYNC_OUT=`sudo sync 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive FEC FS sync failed - error $STATUS:\n$SYNC_OUT"
else
eurybox_display_message message CREATE "Archive FEC 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_hash ()
{
local HASH_OUT
local SYNC_OUT
local STATUS
case $EURYBOX_LOG_LEVEL in
debug|verbose ) SHA_OPTIONS="";;
message ) SHA_OPTIONS="";;
warning ) SHA_OPTIONS="";;
error ) SHA_OPTIONS="";;
esac
case "${EURYBOX_BACKUP_ARCHIVE[HASH]}" in
"sha256" )
HASH_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" )
HASH_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
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive hash creation failed - error $STATUS:\n$HASH_OUT"
else
eurybox_display_message message CREATE "Archive hash creation - OK"
eurybox_display_message debug CREATE "Hash command output:\n$HASH_OUT"
SYNC_OUT=`sudo sync 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning CREATE "Archive hash FS sync failed - error $STATUS:\n$SYNC_OUT"
else
eurybox_display_message message CREATE "Archive hash FS sync - OK"
eurybox_display_message debug CREATE "Sync command output:\n$SYNC_OUT"
fi
fi
}