Want to subscribe to topics you're interested in?
Become a Member

CMM Backup Script

Discussion in 'Add Ons' started by brijendrasial, Jan 8, 2019.

  1. JoeDer

    JoeDer Member

    67
    15
    8
    Feb 22, 2015
    Ratings:
    +43
    Local Time:
    12:48 AM
    Nginx 1.17.x
    MariaDB 10.3.x
    Hello @brijendrasial and thank you for the backup solution you made!
    I'm trying to add the ability to specify a custom port to FTP connection as I have a non standard port. Could you please take a look to the below edited code? what is wrong and how can I make it work? Thanks.

    Code:
    function ftp_software_check
    {
    echo -e $YELLOW"Checking If required FTP Software is installed"$RESET
    echo " "
            if  rpm -q lftp > /dev/null ; then
                    echo -e $GREEN"lftp Installation Found. Skipping Its Installation"$RESET
                    ftp_display
            fi
                    echo -e $RED"lftp Installation Not Found. Installing it"$RESET
                    echo " "
                    yum install lftp -y
                    echo "set ssl:verify-certificate no" >> /etc/lftp.conf
                    echo " "
                    ftp_display
    }
    
    
    function ftp_backup_check
    {
            if [ -f /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf  ]; then
                    echo "FTP configuration file exist. Check if variables are set right"
    
                    FTP_HOST=$(grep -i "FTP_HOST" /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf | cut -d':' -f2)
                    FTP_PORT=$(grep -i "FTP_PORT" /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf | cut -d':' -f2)
                    FTP_PATH=$(grep -i "FTP_PATH" /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf | cut -d':' -f2)
                    FTP_USER=$(grep -i "FTP_USER" /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf | cut -d':' -f2)
                    FTP_PASSWORD=$(grep -i "FTP_PASSWORD" /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf | cut -d':' -f2)
    
                    wget --spider --tries=1 --user=$FTP_USER --password=$FTP_PASSWORD ftps://$FTP_HOST:$FTP_PORT --no-check-certificate
    
                            if [ $? -ne 0 ]; then
                            echo -e $GREEN"Failed to connect to ftp host."$RESET
                                    echo " "
                                    echo "Create FTP config again"
                                    ftp_backup_config
                            else
                                    echo $RED"Connected to FTP host successfully."$RESET
                                    echo " "
                                    ftp_display
                            fi
    
            else
                    echo "Making new ftp configuration file"
                    ftp_backup_config
            fi
    
    }
    
    
    function ftp_connection_check
    {
            FTP_HOST=$(grep -i "FTP_HOST" /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf | cut -d':' -f2)
            FTP_PORT=$(grep -i "FTP_PORT" /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf | cut -d':' -f2)
            FTP_PATH=$(grep -i "FTP_PATH" /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf | cut -d':' -f2)
            FTP_USER=$(grep -i "FTP_USER" /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf | cut -d':' -f2)
            FTP_PASSWORD=$(grep -i "FTP_PASSWORD" /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf | cut -d':' -f2)
    
            wget --spider --tries=1 --user=$FTP_USER --password=$FTP_PASSWORD ftps://$FTP_HOST:$FTP_PORT --no-check-certificate
                    if [ $? -ne 0 ]; then
                            echo " "
                            echo -e $GREEN"Failed to connect to ftp host."$RESET
                            echo " "
                            echo "Create FTP config again"
                            ftp_backup_config
                    else
                            echo $RED"Connected to FTP host successfully."$RESET
                            echo " "
                    fi
    }
    
    function ftp_backup_config
    {
            echo " "
            read -p "$(echo -e $GREEN"Enter FTP Hostname:"$RESET) " ftp_host
            read -p "$(echo -e $GREEN"Enter FTP Port:"$RESET) " ftp_port
            read -p "$(echo -e $GREEN"Enter FTP Backup Path e.g /backup:"$RESET) " ftp_path
            read -p "$(echo -e $GREEN"Enter FTP user:"$RESET) " ftp_user
            read -p "$(echo -e $GREEN"Enter FTP password:"$RESET) " ftp_password
    
            cat > /usr/local/src/centminmod_backup/$backup_domain-ftp_path.conf <<EOF
            FTP_HOST:$ftp_host
            FTP_PORT:$fpt_port
            FTP_PATH:$ftp_path
            FTP_USER:$ftp_user
            FTP_PASSWORD:$ftp_password
    EOF
            ftp_connection_check
    }
    I have the below output
    Code:
    Enter The Domain Name You Want To Backup e.g domain.com: domain.com
    
    Domain You entered is domain.com
    
    Your Domain domain.com exist
    
    /home/nginx/domains/domain.com/public
    
    --2021-03-06 09:38:55--  ftps://hostname/
               => ‘.listing’
    Resolving hostname... ip
    Connecting to hostname|ip|:21... connected.
    ==> AUTH TLS ... WARNING: cannot verify hostname's certificate, issued by ‘CN=RapidSSL RSA CA 2018,OU=www.digicert.com,O=DigiCert Inc,C=US’:
      Unable to locally verify the issuer's authority.
     done.
    Logging in as domain.com ...
    Login incorrect.
    
    Failed to connect to ftp host.
    
    Create FTP config again
    
    Enter FTP Hostname:
     
  2. brijendrasial

    brijendrasial Active Member

    133
    97
    28
    Mar 21, 2018
    Ratings:
    +153
    Local Time:
    3:18 AM
    1.13.9
    10.0.22-MariaDB
    $FTP_PORT is the variable you must change. Try replacing it with the actual port of yours.

    wget --spider --tries=1 --user=$FTP_USER --password=$FTP_PASSWORD ftps://$FTP_HOST:$FTP_PORT --no-check-certificate
     
  3. JoeDer

    JoeDer Member

    67
    15
    8
    Feb 22, 2015
    Ratings:
    +43
    Local Time:
    12:48 AM
    Nginx 1.17.x
    MariaDB 10.3.x
    Can't make it work, I tried with a normal FTP without any edit and I take random ports to PASV mode.
    Code:
    --2021-03-06 13:22:33--  ftps://hostname/
               => ‘.listing’
    Resolving hostname... IP
    Connecting to hostname|IP|:21... connected.
    ==> AUTH TLS ... WARNING: cannot verify hostname's certificate, issued by ‘CN=RapidSSL RSA CA 2018,OU=www.digicert.com,O=DigiCert Inc,C=US’:
      Unable to locally verify the issuer's authority.
     done.
    Logging in as username ... Logged in!
    ==> PBSZ 0 ... done.  ==> PROT P ... done.
    ==> SYST ... done.    ==> PWD ... done.
    ==> TYPE I ... done.  ==> CWD not needed.
    ==> PASV ... couldn't connect to IP port 59868 (Every time this port is random): Connection refused
    
    Failed to connect to ftp host.
     
  4. brijendrasial

    brijendrasial Active Member

    133
    97
    28
    Mar 21, 2018
    Ratings:
    +153
    Local Time:
    3:18 AM
    1.13.9
    10.0.22-MariaDB
    I will check and let you know soon