#!/command/with-contenv /bin/bash source /assets/functions/00-container source /assets/defaults/10-db-backup source /assets/functions/10-db-backup PROCESS_NAME="db-backup-restore" oldcolumns=$COLUMNS ######################################################################################## ### System Functions ### ######################################################################################## ### Colours # Foreground (Text) Colors cdgy="\e[90m" # Color Dark Gray clg="\e[92m" # Color Light Green clm="\e[95m" # Color Light Magenta cwh="\e[97m" # Color White # Turns off all formatting coff="\e[0m" # Color Off # Background Colors bdr="\e[41m" # Background Color Dark Red bdg="\e[42m" # Background Color Dark Green bdb="\e[44m" # Background Color Dark Blue bdm="\e[45m" # Background Color Dark Magenta bdgy="\e[100m" # Background Color Dark Gray blr="\e[101m" # Background Color Light Red boff="\e[49m" # Background Color Off if [ -z "${1}" ] ; then interactive_mode=true else case "$1" in "-h" ) cat < If you only enter some of the arguments you will be prompted to fill them in. Other arguments -h This help screen EOF exit 0 ;; "-i" ) echo "interactive mode" interactive_mode=true ;; * ) interactive_mode=false ;; esac fi control_c() { if [ -f "${restore_vars}" ] ; then rm -rf "${restore_vars}" ; fi print_warn "User aborted" exit } get_filename() { COLUMNS=12 prompt="Please select a file to restore:" options=( $(find "${DEFAULT_FILESYSTEM_PATH}" -type f -maxdepth 2 -not -name '*.md5' -not -name '*.sha1' -print0 | sort -z | xargs -0) ) PS3="$prompt " select opt in "${options[@]}" "Custom" "Quit" ; do if (( REPLY == 2 + ${#options[@]} )) ; then echo "Bye!" exit 2 elif (( REPLY == 1 + ${#options[@]} )) ; then while [ ! -f "${opt}" ] ; do read -p "What path and filename to restore: " opt if [ ! -f "${opt}" ] ; then print_error "File not found. Please retry.." fi done break elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then break else echo "Invalid option. Try another one." fi done COLUMNS=$oldcolumns r_filename=${opt} } get_dbhost() { p_dbhost=$(basename -- "${r_filename}" | cut -d _ -f 3) if [ -n "${p_dbhost}" ]; then parsed_host=true print_debug "Parsed DBHost: ${p_dbhost}" if grep -q "${p_dbhost}" "${restore_vars}" ; then detected_host_num=$(grep "${p_dbhost}" "${restore_vars}" | head -n1 | cut -c 3,4) detected_host_value=$(grep "${p_dbhost}" "${restore_vars}" | head -n1 | cut -d '=' -f 2) fi fi if [ -z "${detected_host_value}" ] && [ -z "${parsed_host}" ]; then print_debug "Parsed DBHost Variant: 1 - No Env, No Parsed Filename" q_dbhost_variant=1 q_dbhost_menu=$(cat < 0 && REPLY <= ${#options[@]} )) ; then break else echo "Invalid option. Try another one." fi done COLUMNS=$oldcolumns r_filename=${opt} } get_ssl() { if grep -q "^DB${detected_host_num}_MYSQL_ENABLE_TLS=" "${restore_vars}" ; then detected_ssl_value=$(grep "^DB${detected_host_num}_MYSQL_ENABLE_TLS=" "${restore_vars}" | head -n1 | cut -d '=' -f 2) fi if [[ -z "${detected_ssl_value}" ]]; then print_debug "Parsed SSL Variant: 1 - No Env Variable Found" default_ssl="false" # Default if no env variable q_ssl_variant=1 q_ssl_menu_opt_default="| (${cwh}N${cdgy}) * " q_ssl_menu="" #No menu option else print_debug "Parsed SSL Variant: 2 - Env Variable DB${detected_host_num}_MYSQL_ENABLE_TLS = '${detected_ssl_value}'" default_ssl="${detected_ssl_value,,}" q_ssl_variant=2 q_ssl_menu="E ) Environment Variable DB${detected_host_num}_MYSQL_ENABLE_TLS: '${detected_ssl_value}'" q_ssl_menu_opt_default="| (${cwh}E${cdgy}) * " fi cat <