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

FTP backup target implementation - basic auth / user-password + many fixes

parent ca395223
......@@ -9,13 +9,13 @@ EURYBOX_CORPORATE="My Corporate"
#Details level on script execution
#Can be: debug, verbose, info, warning or error
EURYBOX_LOG_LEVEL="verbose"
EURYBOX_LOG_LEVEL="debug"
#Parallelism depth / depends on host CPU
EURYBOX_PARALLELISM_LEVEL="8"
#Max retry on failure before stopping execution
EURYBOX_MAX_RETRY_ON_FAILURE="5"
#Network calls timeout (in seconds)
EURYBOX_NETWORK_TIMEOUT="1"
EURYBOX_NETWORK_TIMEOUT="2"
#Version
EURYBOX_VERSION="1.0"
......@@ -49,12 +49,12 @@ EURYBOX_SERVICES=(
[1,OS]="openbsd5"
## [1,SERV]="GATEWAY"
## [1,TYPE]="pf"
[2,NAME]="srv001m"
[2,HOST]="srv001m.$EURYBOX_DOMAIN"
[2,PORT]="22"
[2,USER]="root"
[2,DISK]="/vm_storage/images/srv001m_hdd1.qcow2 /vm_storage/images/srv001m_hdd2.qcow2 /home/vm_store/service001b.qcow2"
[2,OS]="centos7"
# [2,NAME]="srv001m"
# [2,HOST]="srv001m.$EURYBOX_DOMAIN"
# [2,PORT]="22"
# [2,USER]="root"
# [2,DISK]="/vm_storage/images/srv001m_hdd1.qcow2 /vm_storage/images/srv001m_hdd2.qcow2 /home/vm_store/service001b.qcow2"
# [2,OS]="centos7"
## [2,SERV]="DHCP"
## [2,TYPE]="dhcpd"
)
......@@ -103,38 +103,39 @@ EURYBOX_BACKUP_ARCHIVE=(
[OWNER]="root:root"
[MASK]="400"
[LABEL]="backup_u:object_r:backup_t:s0"
[FORMAT]="tar.bz2"
[FORMAT]="tar"
[HASH]="sha512"
[ECC]="par2"
[ECC_LEVEL]="10"
[ENCRYPT]="true"
[ENC_ALGO]="aes-256-ctr"
[PASSWORD]="PutYourStrongPasswordHere"
[PASSWORD]="MyStrongEncryptionPassword"
)
#Backup destination
#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
#-SSH: ssh client/server configuration done at system level (.ssh local files) + local mount point provided by sshfs. Password authentication capability has been enforced as disabled by command options
#-NFS: nfs client/server configuration + local mount point provided by kernel.
#-ISCSI: TODO - iSCSI target/initiator configuration + local mount point provided by TBD
#-FTP: TODO - ftp client/server authentication (password or certificates) + mount provided by curlftpfs.
#-FTP: ftp client/server authentication (user/password TODO? certs/.netrc/other) + mount provided by curlftpfs.
#-PART: local unmounted partition or raw device (as USB device, additional disks, ...) + local mount point provided by kernel. TODO: LUKS encrypted partition provided by kernel and cryptsetup tool
#-LOCAL: local directory
EURYBOX_BACKUP_DESTINATION=(
[PROTOCOL]="NFS"
[PROTOCOL]="FTP"
[MOUNT]="/mnt/local_backup_folder"
#FOR SSH AND FTP
[USER]="root"
#FOR SSH, FTP AND NFS
# [PORT]="22"
[PORT]="2049"
[USER]="test"
#FOR SSH(22), FTP(21) AND NFS(2049)
[PORT]="21"
[HOST]="10.10.10.10"
[PATH]="/mnt/backup/eurybox_archives"
#FOR NFS ONLY
[TYPE]="nfs4"
#FOR PART ONLY
[PART]="/dev/sde"
#FOR FTP ONLY
[PASSWORD]="MyStrongFTPPassword"
)
##########################
......
......@@ -22,6 +22,7 @@ eurybox_backup_mount_target ()
local NMAP_OUT
local NFS_OUT
local SSH_OUT
local FTP_OUT
local PART_OUT
local BKP_PROTOCOL=${EURYBOX_BACKUP_DESTINATION[PROTOCOL]}
local BKP_DEST=${EURYBOX_BACKUP_DESTINATION[PATH]}
......@@ -31,6 +32,7 @@ eurybox_backup_mount_target ()
local BKP_HOST=${EURYBOX_BACKUP_DESTINATION[HOST]}
local BKP_TYPE=${EURYBOX_BACKUP_DESTINATION[TYPE]}
local BKP_PART=${EURYBOX_BACKUP_DESTINATION[PART]}
local BKP_PASSWORD=${EURYBOX_BACKUP_DESTINATION[PASSWORD]}
if [[ $EURYBOX_LOG_LEVEL = "debug" || $EURYBOX_LOG_LEVEL = "verbose" ]]
then
......@@ -47,7 +49,7 @@ eurybox_backup_mount_target ()
then
eurybox_display_message error BACKUP "Target local mount point directory $BKP_MOUNT doesn't exists and folder creation failed - error $STATUS:\n$MKDIR_OUT"
else
local CHMOD_OUT=`sudo chmod 700 $BKP_MOUNT 2>&1`
local CHMOD_OUT=`sudo chmod 777 $BKP_MOUNT 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
......@@ -74,7 +76,7 @@ eurybox_backup_mount_target ()
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"
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$NB_TRY_LEFT left"
NB_TRY_LEFT=$(( $NB_TRY_LEFT - 1 ))
sleep 5
else
......@@ -89,6 +91,7 @@ eurybox_backup_mount_target ()
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\n$NFS_OUT"
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) ]]
......@@ -105,11 +108,11 @@ eurybox_backup_mount_target ()
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"
eurybox_display_message warning BACKUP "Backup SSH 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"
eurybox_display_message debug BACKUP "Backup target $BKP_PROTOCOL server reached on host $BKP_HOST / port $BKP_PORT\n$SSH_OUT"
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) ]]
......@@ -121,7 +124,25 @@ eurybox_backup_mount_target ()
fi
;;
FTP )
eurybox_display_message error BACKUP "Backup destination FTP not implemented yet"
#Check access
FTP_OUT=`sudo lftp -p ${BKP_PORT} ftp://${BKP_USER}:${BKP_PASSWORD}@${BKP_HOST} -e "quit" 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$FTP_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\n$FTP_OUT"
MOUNT_OUT=`sudo curlftpfs $EURYBOX_MNT_FTPFS_OPTIONS ftp://${BKP_USER}:${BKP_PASSWORD}@${BKP_HOST}:${BKP_PORT}${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 FTPFS 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
;;
esac
fi
......@@ -156,7 +177,7 @@ eurybox_backup_mount_target ()
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"
eurybox_display_message error BACKUP "Backup target mount failed:\n$MOUNT_OUT $NFS_OUT $NMAP_OUT $SSH_OUT $FTP_OUT $PART_OUT"
else
eurybox_display_message message BACKUP "Backup target mount success"
eurybox_display_message debug BACKUP "Mount command output:\n$MOUNT_OUT"
......@@ -232,7 +253,7 @@ eurybox_backup_umount_target ()
#Nothing to do
STATUS=0
;;
NFS|SSH|PART )
NFS|SSH|FTP|PART )
UMOUNT_OUT=`sudo umount $UMOUNT_OPTIONS ${EURYBOX_BACKUP_DESTINATION[MOUNT]} 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
......
......@@ -126,7 +126,8 @@ 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}"
EURYBOX_MNT_SSHFS_OPTIONS="-o allow_root ${EURYBOX_SSH_OPTIONS}"
EURYBOX_MNT_FTPFS_OPTIONS="-o allow_root,connect_timeout=${EURYBOX_NETWORK_TIMEOUT}"
case $EURYBOX_LOG_LEVEL in
debug )
set -xv
......@@ -135,7 +136,8 @@ eurybox_check_configuration ()
EURYBOX_LS_OPTIONS+=" -a"
EURYBOX_MNT_NFS_OPTIONS+=" -v"
EURYBOX_MNT_SSHFS_OPTIONS+=" -oLogLevel=debug"
EURYBOX_VIRSH_OPTIONS+=" -q -d 0"
EURYBOX_MNT_FTPFS_OPTIONS+=" -v"
EURYBOX_VIRSH_OPTIONS+=" -q -d 2"
;;
verbose )
set -v
......@@ -144,14 +146,15 @@ eurybox_check_configuration ()
EURYBOX_LS_OPTIONS+=" -l"
EURYBOX_MNT_NFS_OPTIONS+=" -v"
EURYBOX_MNT_SSHFS_OPTIONS+=" -oLogLevel=verbose"
EURYBOX_VIRSH_OPTIONS+=" -q -d 2"
EURYBOX_MNT_FTPFS_OPTIONS+=" -v"
EURYBOX_VIRSH_OPTIONS+=" -q -d 4"
;;
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"
EURYBOX_VIRSH_OPTIONS+=" -q -d 6"
;;
warning )
EURYBOX_SSH_OPTIONS+=" -oLogLevel=info"
......@@ -167,11 +170,12 @@ eurybox_check_configuration ()
;;
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"
eurybox_display_message debug CHECK "virsh options: $EURYBOX_VIRSH_OPTIONS"
eurybox_display_message debug CHECK "nfs mount options: $EURYBOX_MNT_NFS_OPTIONS"
eurybox_display_message debug CHECK "sshfs mount options: $EURYBOX_MNT_SSHFS_OPTIONS"
eurybox_display_message debug CHECK "ftpfs mount options: $EURYBOX_MNT_FTPFS_OPTIONS"
}
#Desc: verify the kernel is Linux
......@@ -257,7 +261,7 @@ eurybox_check_environment ()
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 sshfs curlftpfs cryptsetup
eurybox_check_command grep sudo ssh openssl tar par2 virsh sha512sum sha256sum awk pigz df tail virt-sysprep tput nmap rpcinfo pbzip2 sshfs curlftpfs lftp cryptsetup
#Check kernel capabilities
eurybox_check_kernel
#Check distribution is coherent with configuration
......@@ -308,7 +312,7 @@ eurybox_check_environment ()
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`
BKP_ACCESS_OK=`sudo sh -c "touch ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/test && rm -Rf ${EURYBOX_BACKUP_DESTINATION[MOUNT]}/test"`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
......
This diff is collapsed.
......@@ -37,13 +37,13 @@ eurybox_change_file_permissions ()
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`
PERMISSIONS_OUT=`sudo sh -c "ls -aZ $FILE" 2>&1`
STATUS=$?
if [[ !($STATUS -eq 0) ]]
then
eurybox_display_message warning TOOLS "Permissions listing failed - error $STATUS:\n$PERMISSIONS_OUT"
else
eurybox_display_message message TOOLS "Final files permissions:\n$PERMISSIONS_OUT"
eurybox_display_message message TOOLS "Final permissions:\n$PERMISSIONS_OUT"
fi
}
......@@ -61,7 +61,7 @@ eurybox_display_message ()
then
tput setb 0
tput setaf 6
printf "$NOW [EURYBOX][DEBUG][$CATEGORY] %b\n" "$MESSAGE"
printf "$NOW [EURYBOX][$CATEGORY][DEBUG] %b\n" "$MESSAGE"
fi
;;
message )
......@@ -69,7 +69,7 @@ eurybox_display_message ()
then
tput setb 0
tput setaf 2
printf "$NOW [EURYBOX][INFO][$CATEGORY] %b\n" "$MESSAGE"
printf "$NOW [EURYBOX][$CATEGORY][INFO] %b\n" "$MESSAGE"
fi
;;
warning )
......@@ -77,7 +77,7 @@ eurybox_display_message ()
then
tput setb 0
tput setaf 1
printf "$NOW [EURYBOX][WARNING][$CATEGORY] %b\n" "$MESSAGE"
printf "$NOW [EURYBOX][$CATEGORY][WARNING] %b\n" "$MESSAGE"
fi
;;
error )
......@@ -85,7 +85,7 @@ eurybox_display_message ()
then
tput setb 0
tput setaf 1
printf "$NOW [EURYBOX][ERROR][$CATEGORY] %b\n" "$MESSAGE"
printf "$NOW [EURYBOX][$CATEGORY][ERROR] %b\n" "$MESSAGE"
tput setb 0
tput sgr0
printf "Stopping script execution\n"
......@@ -94,7 +94,7 @@ eurybox_display_message ()
;;
* )
tput sgr0
printf "$NOW [EURYBOX][ERROR][SYNTAX] Bad log level message. Stopping script execution\n"
printf "$NOW [EURYBOX][SYNTAX][ERROR] Bad log level message. Stopping script execution\n"
exit 1
;;
esac
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment