#!/bin/bash # # Setting global version version="3.2.4" # # Setting current Epoch: cur_epoch=`date +%s` # # Detect CentOS version: centosvers=$(grep -Eo "[0-9]\.[0-9]" /etc/redhat-release | cut -d . -f 1) # # Functions spinner() { local pid=$1 local delay=0.25 local spinstr='|/-\' while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do local temp=${spinstr#?} printf " %c " "$spinstr" local spinstr=$temp${spinstr%"$temp"} sleep $delay printf "\b\b\b\b\b\b" done printf " \b\b\b\b" } trap control_c INT escaper() { action=$? if [ $action = 1 -o $action = 255 ]; then dialog --backtitle "$backtitle" --title "$title" --yesno "\nAre you sure you want to quit?\n\nAny changes you made will be lost!" 9 50 sure=$? if [ $sure = 0 ]; then logger -t backup_installer "Stopped the CloudVPS Backup Installer" clear exit fi fi } genhour() { genhour=9 hour=$RANDOM let "hour %= $genhour" } genminute() { genminute=59 minute=$RANDOM let "minute %= $genminute" } genday() { genday=28 day=$RANDOM let "day %= $genday" } control_c() { dialogloc=$(which dialog) if [ -z $dialogloc ]; then echo -e "Control + C pressed, will exit." logger -t backup_installer "Quit due to Control + C" exit else dialog --msgbox "\nControl + C pressed, will exit." 8 50 logger -t backup_installer "Quit due to Control + C" clear exit fi } mysqldumps() { # DirectAdmin: if [ -d /usr/local/directadmin ]; then source /usr/local/directadmin/conf/mysql.conf mysqldumps="Y" mysqluser=$user mysqlpass=$passwd # cPanel / WHM: elif [ -d /usr/local/cpanel ]; then mysqldumps="Y" mysqluser="root" mysqlpass="" # Parallels Plesk: elif [ -d /usr/local/psa ]; then mysqldumps="Y" mysqluser="admin" mysqlpass=$(cat /etc/psa/.psa.shadow) # OpenPanel / OpenApp: elif [ -d /var/openpanel ]; then mysqldumps="Y" mysqluser=$(grep ^user < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') mysqlpass=$(grep ^password < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') # Debian / Ubuntu: elif [ -f /etc/mysql/debian.cnf ]; then mysqldumps="Y" mysqluser=$(grep ^user < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') mysqlpass=$(grep ^password < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') # ISPConfig 3: elif [ -f /usr/local/ispconfig/server/lib/mysql_clientdb.conf ]; then mysqldumps="Y" mysqluser=$(grep user < /usr/local/ispconfig/server/lib/mysql_clientdb.conf | awk '{print $3'} | sed "s/[';]//g") mysqlpass=$(grep password < /usr/local/ispconfig/server/lib/mysql_clientdb.conf | awk '{print $3'} | sed "s/[';]//g") # If no usable configurations are found, set to none: else mysqldumps="N" mysqluser="none" mysqlpass="none" fi } softwarecheck() { echo -n "Operating System detected: " if [ -f /etc/debian_version ]; then echo -e "Debian / Ubuntu\n" logger -t backup_installer "Ubuntu / Debian detected" echo -e "Checking if needed packages are present on the system:\n" echo -n "Update APT packagelist: " # Setting epoch in file, this will make sure that we don't update APT everytime we start the script # We only update APT once there are 2 days passed: if ! [ -f /tmp/epoch.apt ]; then echo $cur_epoch > /tmp/epoch.apt if apt-get update > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "OK" logger -t backup_installer "Refreshed APT source tree" else echo -e "Failed\n\nPlease check the APT sources manually (apt-get update)." logger -t backup_installer "Failed to refresh APT sources, exiting..." exit fi debian_software_check elif [ -f /tmp/epoch.apt ]; then old_epoch=$(cat /tmp/epoch.apt) epoch=$(echo $cur_epoch - $old_epoch | bc) if [ $epoch -lt 172800 ]; then echo -e "Not needed" logger -t backup_installer "APT update not needed, needs 2 days to have passed" debian_software_check else echo $cur_epoch > /tmp/epoch.apt if apt-get update > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "OK" logger -t backup_installer "Refreshed APT source tree" else echo -e "Failed\n\nPlease check the APT sources manually (apt-get update)." logger -t backup_installer "Failed to refresh APT sources, exiting..." exit fi debian_software_check fi fi elif [ -f /etc/redhat-release ]; then echo -e "CentOS / RedHat version $centosvers" echo -e "Checking if needed packages are present on the system:\n" logger -t backup_installer "CentOS / RedHat detected" echo -n "Checking for dialog: " if [ -x /usr/bin/dialog ]; then echo -e "Present" logger -t backup_installer "Package dialog is already installed" else if yum install -q -y dialog > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package dialog is now installed" else clear; echo -e "There was an error installing dialog! Installer will not start!" logger -t backup_installer "Package dialog not installed due to errors, exiting..." exit fi fi echo -n "Checking for curl: " if [ -x /usr/bin/curl ]; then echo -e "Present" logger -t backup_installer "Package curl already installed" else if yum install -q -y curl > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package curl is now installed" else clear; echo -e "There was an error installing curl! Installer will not start!" logger -t backup_installer "Package curl not installed due to errors, exiting..." exit fi fi echo -n "Checking for rsync: " if [ -x /usr/bin/rsync ]; then echo -e "Present" logger -t backup_installer "Package rsync already installed" else if yum install -q -y rsync > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package rsync is now installed" else clear; echo -e "There was an error installing rsync! Installer will not start!" logger -t backup_installer "Package rsync not installed due to errors, exiting..." exit fi fi echo -n "Checking for sendmail: " if [ -x /usr/sbin/sendmail ]; then echo -e "Present" logger -t backup_installer "Package sendmail already installed" else if yum install -q -y sendmail > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package sendmail is now installed" else clear; echo -e "There was an error installing sendmail! Installer will not start!" logger -t backup_installer "Package sendmail not installed due to errors, exiting..." exit fi fi echo -n "Checking for mailx: " if [ -x /usr/bin/mail ]; then echo -e "Present" logger -t backup_installer "Package mailx already installed" else if yum install -q -y mailx > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package mailx is now installed" else clear; echo -e "There was an error installing mailx! Installer will not start!" logger -t backup_installer "Package mailx not installed due to errors, exiting..." exit fi fi echo -n "Checking for bc: " if [ -x /usr/bin/bc ]; then echo -e "Present" logger -t backup_installer "Package bc already installed" else if yum install -q -y bc > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package bc is now installed" else clear; echo -e "There was an error installing bc! Installer will not start!" logger -t backup_installer "Package bc not installed due to errors, exiting..." exit fi fi echo -n "Checking for expect: " if [ -x /usr/bin/expect ]; then echo -e "Present" logger -t backup_installer "Package expect already installed" else if yum install -q -y expect > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package expect is now installed" else clear; echo -e "There was an error installing expect! Installer will not start!" logger -t backup_installer "Package expect not installed due to errors, exiting..." exit fi fi echo -n "Checking for Perl: " if [ -x /usr/bin/perl ]; then echo -e "Present" logger -t backup_installer "Package perl already installed" else if yum install -q -y perl > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package perl is now installed" else clear; echo -e "There was an error installing perl! Installer will not start!" logger -t backup_installer "Package perl not installed due to errors, exiting..." exit fi fi echo -n "Checking for mc: " if [ -x /usr/bin/mc ]; then echo -e "Present" logger -t backup_installer "Package mc already installed" else if yum install -q -y mc > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package mc is now installed" else clear; echo -e "There was an error installing mc! Installer will not start!" logger -t backup_installer "Package mc not installed due to errors, exiting..." exit fi fi echo -n "Checking for sshfs: " if [ -x /usr/bin/sshfs ]; then echo -e "Present" logger -t backup_installer "Package sshfs already installed" else if [ "$centosvers" == "7" ]; then echo -e "Needs EPEL repository:" echo -n "Checking EPEL repo: " if [ -f /etc/yum.repos.d/epel.repo ]; then echo -e "Present" logger -t backup_installer "EPEL repo alreay available on system" else if rpm -Uhv http://ftp.nluug.nl/pub/os/Linux/distr/fedora-epel//epel-release-latest-7.noarch.rpm > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "EPEL repo installed on system" else echo -e "There was an error installing the EPEL repo, the installer will now quit!" logger -t backup_installer "EPEL repo could not be installed, exiting..." exit fi fi echo -n "Installing sshfs: " if yum install -q -y sshfs > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package sshfs is now installed" # Disable Epel Repo: sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/epel.repo else echo -e "There was an error installing sshfs! Installer will not start!" logger -t backup_installer "Package sshfs not installed due to errors, exiting..." exit fi else if yum install -q -y sshfs > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package sshfs is now installed" sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/epel.repo else echo -e "There was an error installing sshfs! Installer will not start!" logger -t backup_installer "Package sshfs not installed due to errors, exiting..." exit fi fi fi echo -n "Checking for nano: " if [ -x /usr/bin/nano ]; then echo -e "Present" logger -t backup_installer "Package nano already installed" else if yum install -q -y nano > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package nano is now installed" else clear; echo -e "There was an error installing nano! Installer will not start!" logger -t backup_installer "Package nano not installed due to errors, exiting..." exit fi fi else echo -e "Unkown, the installer will now quit..." logger -t backup_installer "Unknown Linux distribution detected, exiting" exit fi } debian_software_check() { echo -n "Checking for dialog: " if [ -x /usr/bin/dialog ]; then echo -e "Present" logger -t backup_installer "Package dialog already installed" else if apt-get -y install dialog > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package dialog is now installed" else clear; echo -e "There was an error installing dialog! Installer wil not start!" logger -t backup_installer "Package dialog not installed due to an error, exiting..." exit fi fi echo -n "Checking for curl: " if [ -x /usr/bin/curl ]; then echo -e "Present" logger -t backup_installer "Package curl already installed" else if apt-get -y install curl > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package curl is now installed" else clear; echo -e "There was an error installing curl! Installer will not start!" logger -t backup_installer "Package curl not installed due to an error, exiting..." exit fi fi echo -n "Checking for rsync: " if [ -x /usr/bin/rsync ]; then echo -e "Present" logger -t backup_installer "Package rsync already installed" else if apt-get -y install rsync > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package rsync is now installed" else clear; echo -e "There was an error installing rsync! Installer will not start!" logger -t backup_installer "Package rsync not installed due to an error, exiting..." exit fi fi echo -n "Checking for sendmail: " if ! [ -d /etc/postfix/ ]; then if [ -x /usr/sbin/sendmail ]; then echo -e "Present" logger -t backup_installer "Package sendmail already installed" else if apt-get -y install sendmail > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package sendmail is now installed" else clear; echo -e "There was an error installing sendmail! Installer will not start!" logger -t backup_installer "Package sendmail not installed due to an error, exiting..." exit fi fi else echo -e "Failed, Postfix is currently installed and untested with the backup tools, but will continue..." fi echo -n "Checking for mailx: " if [ -x /usr/bin/mail ]; then echo -e "Present" logger -t backup_installer "Package mailx already installed" else apt-get -y install mailx > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid retval=$? if [ $retval = 0 ]; then echo -e "Installed" logger -t backup_installer "Package mailx is now installed" elif [ $retval = 100 ]; then echo -e "Not available, trying mailutils" logger -t backup_installer "Package mailx not available, trying mailutils" echo -n "Checking for mailutils: " if apt-get -y install mailutils > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package mailutils is now installed" else echo -e "Error, could not install mailutils" logger -t backup_installer "Package mailutils not installed due to errors, exiting..." fi else clear; echo -e "There was an error installing mailx! Installer will not start!" logger -t backup_installer "Package mailx not installed due to an error, exiting..." exit fi fi echo -n "Checking for bc: " if [ -x /usr/bin/bc ]; then echo -e "Present" logger -t backup_installer "Package bc already installed" else if apt-get -y install bc > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package bc is now installed" else clear; echo -e "There was an error installing bc! Installer will not start!" logger -t backup_installer "Package bc not installed due to an error, exiting..." exit fi fi echo -n "Checking for expect: " if [ -x /usr/bin/expect ]; then echo -e "Present" logger -t backup_installer "Package expect already installed" else if apt-get -y install expect > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package expect is now installed" else clear; echo -e "There was an error installing expect! Installer will not start!" logger -t backup_installer "Package expect not installed due to an error, exiting..." exit fi fi echo -n "Checking for Perl: " if [ -x /usr/bin/perl ]; then echo -e "Present" logger -t backup_installer "Package perl already installed" else if apt-get -y install perl > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package perl is now installed" else clear; echo -e "There was an error installing perl! Installer will not start!" logger -t backup_installer "Package perl not installed due to an error, exiting..." exit fi fi echo -n "Checking for mc: " if [ -x /usr/bin/mc ]; then echo -e "Present" logger -t backup_installer "Package mc already installed" else if apt-get -y install mc > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package mc is now installed" else clear; echo -e "There was an error installing mc! Installer will not start!" logger -t backup_installer "Package mc not installed due to an error, exiting..." exit fi fi echo -n "Checking for sshfs: " if [ -x /usr/bin/sshfs ]; then echo -e "Present" logger -t backup_installer "Package sshfs already installed" else if apt-get -y install sshfs > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package sshfs is now installed" else clear; echo -e "There was an error installing sshfs! Installer will not start!" logger -t backup_installer "Package sshfs not installed due to an error, exiting..." exit fi fi echo -n "Checking for nano: " if [ -x /usr/bin/nano ]; then echo -e "Present" logger -t backup_installer "Package nano already installed" else if apt-get -y install nano > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "Installed" logger -t backup_installer "Package nano is now installed" else clear; echo -e "There was an error installing nano! Installer will not start!" logger -t backup_installer "Package nano not installed due to an error, exiting..." exit fi fi } commandlineuninstall() { echo -e "CloudVPS Backupscript Uninstaller" logger -t backup_installer "CLI: Started the uninstall procedure" if ! [[ -f /etc/cloudvps/backup.conf || -f /etc/backups/xlsbackup.conf ]]; then echo -e "\nBackupscript not installed!\n" logger -t backup_installer "CLI: Cannot uninstall script, because it is not installed" exit fi echo -n "Removing configfile: " if chattr -i /etc/cloudvps/backup.conf > /dev/null 2>&1; rm -rf /etc/cloudvps/ > /dev/null 2>&1 then echo -e "OK" logger -t backup_installer "CLI: Removed configfile" else echo -e "FAILED\n\nPlease remove the configfile manually." logger -t backup_installer "CLI: Could not remove configfile" fi echo -n "Removing cronjob: " crontab -u root -l > /tmp/cron.txt if grep cloudvpsbackup /tmp/cron.txt > /dev/null then if sed -i '/cloudvpsbackup/ d' /tmp/cron.txt; crontab /tmp/cron.txt; rm /tmp/cron.txt > /dev/null 2>&1 then echo -e "OK" logger -t backup_installer "CLI: Cronjob removed" else echo -e "FAILED, remove manually via \"crontab -e\"" logger -t backup_installer "CLI: Failed to remove cronjob" fi elif grep xlsbackup /tmp/cron.txt > /dev/null then if sed -i '/xlsbackup/ d' /tmp/cron.txt; crontab /tmp/cron.txt; rm /tmp/cron.txt > /dev/null 2>&1 then echo -e "OK" logger -t backup_installer "CLI: Cronjob removed" else echo -e "FAILED, remove manually via \"crontab -e\"" logger -t backup_installer "CLI: Failed to remove cronjob" fi else echo -e "FAILED, no cronjob found!" logger -t backup_installer "CLI: Cronjob not found" fi echo -n "Removing backupscript: " if rm -f /usr/local/bin/cloudvpsbackup > /dev/null 2>&1 then echo -e "OK" logger -t backup_installer "CLI: Removed the backupscript" else echo -e "FAILED\n\nPlease remove the script manually." logger -t backup_installer "CLI: Could not remove the backupscript" fi echo -n "Removing symlink: " if [ -L /usr/local/bin/xlsbackup ]; then rm -f /usr/local/bin/xlsbackup > /dev/null 2>&1 echo -e "OK" logger -t backup_installer "CLI: Removed symlink" else echo "OK, none found." logger -t backup_installer "CLI: No symlink to be removed" fi echo -e "\nUninstall of the CloudVPS Backup Script is completed!\n" logger -t backup_installer "CLI: Uninstall of the backupscript is now finished" exit } commandlineupdate() { clear echo -e "CloudVPS Backupscript Upgrade" # Check if the script is installed: if ! [[ -f /usr/local/bin/xlsbackup || -f /usr/local/bin/cloudvpsbackup ]]; then echo -e "\nThe backupscript is not installed, please install it first!\n" logger -t backup_installer "CLI: Cannot update backupscript because it is not installed" exit fi # Load configfile: if [ -f /etc/backups/xlsbackup.conf ]; then source /etc/backups/xlsbackup.conf elif [ -f /etc/cloudvps/backup.conf ]; then source /etc/cloudvps/backup.conf fi # Software checks: softwarecheck echo -e "\n" # Get current installed version: echo -n "Version check: " if [ -f /usr/local/bin/xlsbackup ]; then version=$(cat /usr/local/bin/xlsbackup | grep "VERSION=" | cut -d = -f 2 | sed 's/"//g') versionstripped=$(echo $version | sed 's/\.//g') elif [ -f /etc/cloudvps/backup.conf ]; then version=$(cat /etc/cloudvps/backup.conf | grep "VERSION=" | cut -d = -f 2 | sed 's/"//g') versionstripped=$(echo $version | sed 's/\.//g') else version="1.0.0" versionstripped=100 fi # Get remote version: newversion=$(curl -s http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt | grep "VERSION=" | cut -d = -f 2 | sed 's/"//g' | head -1) newversionstripped=$(echo $newversion | sed 's/\.//g') if ! [[ -f /etc/backups/xlsbackup.conf || -f /etc/cloudvps/backup.conf ]]; then echo -e "FAILED\n\nUpgrades are not supported in this version of the backupscript.\nPlease uninstall the old backupscript and run the installer\nto install the new script.\n" exit fi # If both versions are the same: if [[ $versionstripped == $newversionstripped ]]; then echo -e "Up-to-date ($newversion)\n" exit # If the versions differ: elif [[ $versionstripped < $newversionstripped ]]; then # If the configfile is CloudVPS: if [ -f /etc/cloudvps/backup.conf ]; then if [ -z $PATCHED ]; then echo -e "The update patch will now be downloaded and executed:" if curl -f -s -o /root/cloudvps-backup-patch http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-patch.txt then chmod +x /root/cloudvps-backup-patch > /dev/null 2>&1 /root/cloudvps-backup-patch chattr -i /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/VERSION=\"$version\"/VERSION=\"$newversion\"/" /etc/cloudvps/backup.conf > /dev/null 2> /dev/null chattr +i /etc/cloudvps/backup.conf echo -e "\nUpgrade and patch completed! Continuing to use the new functionality!" elif [ $? = 22 ]; then echo -e "Updating script: FAILED\n\nCould not download and execute the patch script!\nPlease try it manually via the CloudVPS Backup Installer\n" exit fi else if curl -s -o /usr/local/bin/cloudvpsbackup http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt > /dev/null 2>&1 then chmod +x /usr/local/bin/cloudvpsbackup > /dev/null 2>&1 chattr -i /etc/cloudvps/backup.conf perl -pi -w -e "s/VERSION=\"$version\"/VERSION=\"$newversion\"/" /etc/cloudvps/backup.conf > /dev/null 2> /dev/null chattr +i /etc/cloudvps/backup.conf echo -e "Upgrade from $version to $newversion successfuly installed.\n\nThe new script will be used during the next run.\n" logger -t backup_installer "Found backupscript update, version $newversion is available, update is succesfully installed" else echo -e "Upgrade failed...\n\n" logger -t backup_installer "Found backupscript update, version $newversion, but failed to apply the update..." fi exit fi elif [ -f /etc/backups/xlsbackup.conf ]; then if [ $versionstripped = 16 ]; then genday while [ $genday = 0 ]; do genday done echo -e "Update available from $version to $newversion" echo -n "Moving configfile: " if [ -f /etc/backups/xlsbackup.conf ]; then if mkdir -p /etc/cloudvps/ > /dev/null 2>&1; chattr -i /etc/backups/xlsbackup.conf > /dev/null 2>&1; mv /etc/backups/xlsbackup.conf /etc/cloudvps/backup.conf > /dev/null 2>&1; rm -rf /etc/backups/ > /dev/null 2>&1 then echo -e "OK" else echo -e "FAILED" fi fi echo -n "Patching configfile: " # Remove lock from configfile and load the configuration variables source /etc/cloudvps/backup.conf # Update version number in configfile if [[ $versionstripped < 200 ]]; then echo "VERSION=\"$newversion\"" >> /etc/cloudvps/backup.conf else perl -pi -w -e "s/VERSION=\"$version\"/VERSION=\"$newversion\"/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi # Patches for some old configfiles if [[ "$MYSQLBACKUPDIR" == "/var/sqlbackups" ]]; then perl -pi -w -e "s/MYSQLBACKUPDIR=\/var\/sqlbackups/MYSQLBACKUPDIR=\/var\/sqlbackups\//" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi if [[ $MYSQLBACKUP == 1 ]]; then perl -pi -w -e "s/MYSQLBACKUP=1/MYSQLBACKUP=N/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi if [[ $MYSQLBACKUP == 0 ]]; then perl -pi -w -e "s/MYSQLBACKUP=0/MYSQLBACKUP=Y/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi if [ -z $UPDATECHECK ]; then echo -e "UPDATECHECK=$day" >> /etc/cloudvps/backup.conf fi if [ -z $NOTIFICATIONS ]; then echo -e "NOTIFICATIONS=Y" >> /etc/cloudvps/backup.conf fi if [ -z $MAILLOG ]; then echo -e "MAILLOG=N" >> /etc/cloudvps/backup.conf fi if [ -z $LOGGING ]; then echo -e "LOGGING=Y" >> /etc/cloudvps/backup.conf fi if [ -z $AUTOUPDATE ]; then echo -e "AUTOUPDATE=Y" >> /etc/cloudvps/backup.conf fi if [ -d /usr/local/directadmin ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then source /usr/local/directadmin/conf/mysql.conf perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$user/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$passwd/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi elif [ -d /usr/local/cpanel ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER="root" MYSQLPASS="" perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$MYSQLUSER/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$MYSQLPASS/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi elif [ -d /usr/local/psa ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER="admin" MYSQLPASS=$(cat /etc/psa/.psa.shadow) perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$MYSQLUSER/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$MYSQLPASS/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi elif [ -d /var/openpanel ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER=$(grep ^user < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') MYSQLPASS=$(grep ^password < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$MYSQLUSER/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$MYSQLPASS/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi elif [ -f /etc/mysql/debian.cnf ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER=$(grep ^user < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') MYSQLPASS=$(grep ^password < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$MYSQLUSER/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$MYSQLPASS/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi fi # If old script exists, remove it and create a symlink: if [ -f /usr/local/bin/xlsbackup ]; then echo -n "Removing old script: " if rm -f /usr/local/bin/xlsbackup > /dev/null 2>&1 then echo -e "OK" logger -t backup_installer "CLI: Removed old XLS script" else echo -e "FAILED" logger -t backup_installer "CLI: Could not remove old XLS script" fi echo -n "Downloading new backupscript: " if curl -f -s -o /usr/local/bin/cloudvpsbackup http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt then echo -e "OK" logger -t backup_installer "CLI: Downloaded new backupscript" else echo -e "FAILED\n\nExiting!" logger -t backup_installer "CLI: Failed downloading new backupscript" exit fi echo -n "Creating symlink: " if ln -s /usr/local/bin/cloudvpsbackup /usr/local/bin/xlsbackup > /dev/null 2>&1 then echo -e "OK" logger -t backup_installer "CLI: Created symlink for old to new backupscript" else echo -e "FAILED\n\nExiting!" logger -t backup_installer "CLI: Could not create symlink for old to new backupscript" exit fi echo -n "Setting permissions: " if chmod +x /usr/local/bin/cloudvpsbackup > /dev/null 2>&1 then echo -e "OK" logger -t backup_installer "CLI: Set executive permission new backupscript" else echo -e "FAILED\n\nExiting!" logger -t backup_installer "CLI: Could not set executive permission new backupscript" exit fi fi # # Upgrade from 1.6 to 2.0 config complete, now continue patching to 2.1: echo -e "\nStarting upgrade to version 2.1.X:" if curl -f -s -o /root/cloudvps-backup-patch http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-patch.txt then chmod +x /root/cloudvps-backup-patch > /dev/null 2>&1 /root/cloudvps-backup-patch perl -pi -w -e "s/VERSION=\"$version\"/VERSION=\"$newversion\"/" /etc/cloudvps/backup.conf > /dev/null 2> /dev/null chattr +i /etc/cloudvps/backup.conf echo -e "\nUpgrade and patch completed! Continuing to use the new functionality!" elif [ $? = 22 ]; then echo -e "Updating script: FAILED\n\nCould not download and execute the patch script!\nPlease try it manually via the CloudVPS Backup Installer\n" exit fi echo -e "\nUpgrade complete!\n" else echo -e "Unsupported version found (< 1.6). Exiting..." exit fi else echo -e "Unsupported version found. Exiting..." fi fi exit } commandlinelogcleaner() { logger -t backup_installer "CLI: Started the log cleaning procedure" space=$(du -sch /var/log/backups/ | grep total | awk '{print $1}') echo -e "CloudVPS Backup Log Cleaner\n\nThis will clear all backup logfiles where you will save "$space"B of diskspace:\n" echo -n "Clearing logs: " if rm -rf /var/log/backups/rsync/* > /dev/null 2>&1; rm -rf /var/log/backups/error/* > /dev/null 2>&1; rm -rf /var/log/backups/warn/* > /dev/null 2>&1; rm -rf /var/log/backups/temp/* > /dev/null 2>&1 & pid=$!; spinner $pid; wait $pid then echo -e "OK" logger -t backup_installer "CLI: Cleared all logs in /var/log/backups/, saved "$space"B of diskspace" else echo -e "FAILED\n\nCould not clear logs, will now exit..." logger -t backup_installer "CLI: Could not clear logs" fi logger -t backup_installer "CLI: Finished log cleaning procedure" exit } commandlineshowquota() { echo -e "CloudVPS Quota Usage" logger -t backup_installer "CLI: Started the show quota procedure" source /etc/cloudvps/backup.conf if [[ "$BSERVER" == backup-*.xlshosting.* || "$BSERVER" == backup-*.cloudvps.* ]]; then # Get quota report and save it, then break it into variables: ssh -p $SSHPORT -i $PRIVKEY $BUSER@$BSERVER quota > ./quota 2>&1 accsize=$(cat quota | grep / | awk '{print $1}' | tail -1) if ! [[ $accsize =~ ^[0-9]+$ ]]; then accsize=$(cat quota | grep / | awk '{print $2}' | tail -1) accinuse=$(cat quota | grep / | awk '{print $3}' | tail -1) accinusepercent=$(cat quota | grep / | awk '{print $5}' | tail -1) accfree=$(cat quota | grep / | awk '{print $4}' | tail -1) else accinuse=$(cat quota | grep / | awk '{print $2}' | tail -1) accinusepercent=$(cat quota | grep / | awk '{print $4}' | tail -1) accfree=$(cat quota | grep / | awk '{print $3}' | tail -1) fi echo -e "\nBelow are the quota details:\n\nServer....: $BSERVER\nUsername..: $BUSER\nSize......: "$accsize"B\nUsage.....: "$accinuse"B ($accinusepercent)\nFree......: "$accfree"B\n" logger -t backup_installer "CLI: Quota lookup: $accinuse GB of $accsize GB" rm ./quota > /dev/null 2>&1 else echo -e "\nQuota support is only available for CloudVPS backupservers." logger -t backup_installer "CLI: Quota support is not available for $BSERVER as it is not a CloudVPS backupserver" fi logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit } commandlineinstall() { echo -e "CloudVPS Backupscript Installation V$version\n" if [ -f /etc/cloudvps/backup.conf ]; then dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThe backupscript is already installed.\n\nIf you want to change the configuration, please use the configuration editor." 10 60 clear exit fi if [ -f /etc/backups/xlsbackup.conf ]; then echo -e "Old configfile found, please upgrade the script instead of installing it again." logger -t backup_installer "CLI: Old configfile found, customer needs to update instead of install the script." clear exit fi genhour genminute genday softwarecheck mysqldumps newversion=$(curl -s http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt | grep "VERSION=" | cut -d = -f 2 | sed 's/"//g' | head -1) hostname=`hostname` while [ $genday = 0 ]; do genday done # First check if CSF is present, if so add the appropriate rules: if [ -d /etc/csf/ ]; then echo -n "Preparing CSF: " backupip=`host $server | awk '{print $4}'` # Add IP of the backupserver to the allow list if csf -a $backupip then echo -e "OK" logger -t backup_installer "CLI: IP $backupip added to CSF whitelist" else echo -e "FAILED!\n\nPlease check your CSF configuration and try again" logger -t backup_installer "CLI: Could not add $backupip to CSF whitelist" exit fi fi # Continue installing the script echo -n "Creating config: " if ! [ -d /etc/cloudvps/ ]; then mkdir -p /etc/cloudvps/ > /dev/null 2>&1 logger -t backup_installer "CLI: Created config directory" fi if ! touch /etc/cloudvps/backup.conf > /dev/null 2>&1 then echo -e "Could not create configuration file! Exiting...\n" logger -t backup_installer "CLI: Could touch new configfile" exit fi echo -e "BUSER=$account" >> /etc/cloudvps/backup.conf echo -e "BSERVER=$server" >> /etc/cloudvps/backup.conf echo -e "NOTIFICATIONS=Y" >> /etc/cloudvps/backup.conf echo -e "WEKEN=$weeks" >> /etc/cloudvps/backup.conf echo -e "MAANDEN=$months" >> /etc/cloudvps/backup.conf echo -e "PRIVKEY=/root/.ssh/id_rsa.cloudvpsbackup" >> /etc/cloudvps/backup.conf echo -e "REPORTS_EMAIL=$email" >> /etc/cloudvps/backup.conf echo -e "BACKUPROOT=/" >> /etc/cloudvps/backup.conf echo -e "XFERSPEED=7500" >> /etc/cloudvps/backup.conf echo -e "SSHPORT=22" >> /etc/cloudvps/backup.conf echo -e "REMOTEPATH=/home/$account/" >> /etc/cloudvps/backup.conf echo -e "H=$hostname" >> /etc/cloudvps/backup.conf echo -e "LOGGING=Y" >> /etc/cloudvps/backup.conf if [[ "$mysqldumps" == "Y" ]] ; then echo -e "MYSQLBACKUP=Y" >> /etc/cloudvps/backup.conf echo -e "MYSQLUSER=$mysqluser" >> /etc/cloudvps/backup.conf echo -e "MYSQLPASS=$mysqlpass" >> /etc/cloudvps/backup.conf echo -e "MYSQLBACKUPDIR=/var/sqlbackups/" >> /etc/cloudvps/backup.conf else echo -e "MYSQLBACKUP=N" >> /etc/cloudvps/backup.conf echo -e "MYSQLUSER=none" >> /etc/cloudvps/backup.conf echo -e "MYSQLPASS=none" >> /etc/cloudvps/backup.conf echo -e "MYSQLBACKUPDIR=/var/sqlbackups/" >> /etc/cloudvps/backup.conf fi echo -e "UPDATECHECK=$day" >> /etc/cloudvps/backup.conf echo -e "VERSION=\"$newversion\"" >> /etc/cloudvps/backup.conf echo -e "AUTOUPDATE=Y" >> /etc/cloudvps/backup.conf echo -e "PATCHED=Y" >> /etc/cloudvps/backup.conf echo -e "$email" > /etc/cloudvps/recipients.mail echo -e "/usr/src/\n/lib/modules/\n/usr/tmpDSK\n/lib/firmware/\n/selinux/\n/var/named/run-root/\n/proc/\n/sys/\n/var/log/\n/tmp/\n/dev/\n/mnt/\n/var/run/\n/var/installatron/\ncache/\n/var/tmp/\ntypo3conf/deprecation_*\n/run/\nsession/\n/var/lib/varnish/\n/media\n/usr/local/psa/admin/logs/\n/home/cpbackuptmp/\n/backup/cpbackup/\n/home/virtfs/\n/usr/local/cpanel/3rdparty/mailman/cgi-bin/\n/usr/local/apache/\n/etc/exim/\n/home/tmp/" > /etc/cloudvps/excludes.rsync echo -e "OK" logger -t backup_installer "CLI: configfile successfuly created" echo -n "Checking keyfile: " if [ -f /root/.ssh/id_rsa.cloudvpsbackup ]; then echo -e "Found" logger -t backup_installer "CLI: Keyfile already exists" else echo -e "Created"; ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa.cloudvpsbackup > /dev/null 2>&1 logger -t backup_installer "CLI: Created keyfile" fi echo -n "Exchange keyfile: " if /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oConnectTimeout=60 -oStrictHostKeyChecking=no -oPort=22 $account@$server expect "password:" send "$password\r" expect "sftp>" send "get .ssh/authorized_keys .\r" expect "sftp>" send "quit\r" EOF then if [ -f /root/authorized_keys ] then echo -n "Keyfile found, key added and uploading new keyfile -> "; cat /root/.ssh/id_rsa.cloudvpsbackup.pub >> /root/authorized_keys; /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oConnectTimeout=60 -oStrictHostKeyChecking=no -oPort=22 $account@$server expect "password:" send "$password\r" expect "sftp>" send "put authorized_keys .ssh/authorized_keys\r" expect "sftp>" send "quit\r" EOF echo -e "OK" logger -t backup_installer "CLI: Exchanged keyfile with backupserver" rm /root/authorized_keys > /dev/null 2> /dev/null else echo -n "Keyfile not found, creating and uploading new keyfile -> " /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oConnectTimeout=60 -oStrictHostKeyChecking=no -oPort=22 $account@$server expect "password:" send "$password\r" expect "sftp>" send "mkdir .ssh\r" expect "sftp>" send "cd .ssh\r" expect "sftp>" send "put /root/.ssh/id_rsa.cloudvpsbackup.pub authorized_keys\r" expect "sftp>" send "quit\r" EOF echo -e "OK" logger -t backup_installer "CLI: Exchanged keyfile with backupserver" fi fi echo -n "Installing script: " if curl -f -s -o /usr/local/bin/cloudvpsbackup http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt > /dev/null 2> /dev/null; then echo -e "OK" logger -t backup_installer "CLI: Downloaded and installed backupscript" else echo -e "FAILED!\n\nPlease check your network connection." logger -t backup_installer "CLI: Could not download and/or install backupscript" exit fi echo -n "Setting permissions: " if chmod +x /usr/local/bin/cloudvpsbackup > /dev/null 2> /dev/null then echo -e "OK" logger -t backup_installer "CLI: Changed permissions for backupscript" else echo -e "FAILED, will continue..." logger -t backup_installer "CLI: Could not change permissions for backupscript, but will continue" fi echo -n "Installing cronjob: " if [[ "$reports" == "Y" ]]; then if cat <(crontab -l) <(echo "$minute $hour * * * /usr/local/bin/cloudvpsbackup 2>&1 | mail -s '[BACKUP] Backupreport of `hostname`' $email") | crontab - then echo -e "OK" logger -t backup_installer "CLI: Installed cronjob with emailaddress $email" else echo -e "FAILED\n\nThere was an error installing the cronjob!" logger -t backup_installer "CLI: Could not install cronjob" exit 10 fi else if cat <(crontab -l) <(echo "$minute $hour * * * /usr/local/bin/cloudvpsbackup > /dev/null 2>&1") | crontab - then echo -e "OK" logger -t backup_installer "CLI: Installed cronjob without mail function" else echo -e "FAILED\n\nThere was an error installing the cronjob!" logger -t backup_installer "CLI: Could not install cronjob" exit 10 fi fi echo -n "Mailing report: " # With simple installs, we always mail a report: mail -s '[BACKUP] Backup installation on '$hostname' was successful' $email < /dev/null 2>&1 then logger -t backup_installer "CLI: Unlocked the backup configuration file" else echo -e "Failed to unlock the CloudVPS backup configuration file...\n" logger -t backup_installer "CLI: Failed to unlock the backup configuration file" exit fi if which nano > /dev/null 2>&1 then nano=`which nano` logger -t backup_installer "CLI: Starting nano editor to edit configuration" $nano /etc/cloudvps/backup.conf logger -t backup_installer "CLI: Closed nano editor, stopped editing configuration" if chattr +i /etc/cloudvps/backup.conf > /dev/null 2>&1 then logger -t backup_installer "CLI: Locked the backup configuration file" else echo -e "Failed to ock the CloudVPS backup configuration file...\n" logger -t backup_installer "CLI: Failed to lock the backup configuration file" exit fi else echo -e "No nano editor found, cannot start editor." logger -t backup_installer "CLI: Editor nano not found, cannot start edit function" exit fi exit elif ! [ -z $1 ]; then echo -e "Unknown commandline option \"$1\".\n\nPlease run with \"$0 --help\" for more information about the available commandline options." exit fi # Starting output ot the script: clear logger -t backup_installer "Started the CloudVPS Backup Installer version $version" echo -e "============================================================" echo -e "= CloudVPS Backup Installation Script V$version =" echo -e "============================================================\n" # Some software checks after we made sure we are root: softwarecheck # Starting the dialog renderings from here: # # Quick update check to see if this is the latest release: currentversion=$(echo $version | sed 's/"//g' | head -1) currentversionstripped=$(echo $currentversion | sed 's/\.//g') newversion=$(curl -s http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-installer.txt | grep "version=" | cut -d = -f 2 | sed 's/"//g' | head -1) newversionstripped=$(echo $newversion | sed 's/\.//g') if [[ $currentversionstripped < $newversionstripped ]]; then logger -t backup_installer "Upgrade detected from version $currentversion to version $newversion" dialog --backtitle "$backtitle_upgrade" --title "$title" --yesno "\nThere is an update available for this tool.\n\nThe current version is $currentversion and available is version $newversion.\n\nBefore upgrading, do you want to read the changelog?" 12 60 readlog=$? if [ $readlog = 0 ]; then curl -f -s -o /root/changelog-backupinstaller http://download.cloudvps.com/pub/files/scripts/backup/changelog-installer.txt > /dev/null 2>&1 dialog --backtitle "$backtitle_upgrade" --title "$title" --textbox "/root/changelog-backupinstaller" 20 95 rm /root/changelog-backupinstaller > /dev/null 2>&1 logger -t backup_installer "Displayed the changelog" fi dialog --backtitle "$backtitle_upgrade" --title "$title" --yesno "\nDo you want to upgrade?" 7 60 agree=$? case $agree in 0) if curl -s -o $0 http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-installer.txt > /dev/null 2>&1 then dialog --backtitle "$backtitle_upgrade" --title "$title" --yesno "\nThe update was successful!\n\nDo you want to run the updated installer?" 9 60 run=$? case $run in 0) ./$0 clear exit ;; 1) clear exit ;; esac logger -t backup_installer "The upgrade has been downloaded and installed" else dialog --backtitle "$backtitle_upgrade" --title "$title" --msgbox "\nCould not download the update. Will now exit." 7 60 logger -t backup_installer "There was an unknown error while updating the installer, exiting..." clear exit fi ;; 1) dialog --backtitle "$backtitle_upgrade" --title "$title" --msgbox "\nYou do not want to update. Please note that you'll now be using the old version." 8 60 logger -t backup_installer "Upgrade cancelled by user" clear ;; esac fi # General settings and checks on server: defaultsshport=22 defaultbackuppath=/ hostname=`hostname` sqlbackupdefault=/var/sqlbackups/ privkeydefault="/root/.ssh/id_rsa.cloudvpsbackup" currentsize=$(df -hT --exclude-type="tmpfs" --exclude-type="devtmpfs" --block-size=G | grep "/" | awk '{print $4}' | tr -d G | head -1) clear # If old or no configfile is found draw different menu: if [ -f /etc/cloudvps/backup.conf ]; then dialog --backtitle "$backtitle" --title "$title" --menu "\nSelect action:" 9 50 0 \ "3" "Configuration editor" \ "4" "Uninstall backupscript" \ "5" "Update backupscript" \ "6" "Test functionality" \ "7" "Quota calculator" \ "8" "Clear backup logs" \ "9" "Show account quota" \ "10" "Data recovery (script)" \ "11" "Run backupscript (manual run)" \ "12" "Exchange SSH keyfile" \ "13" "Mail recipients list" \ "14" "Rsync excludes list" \ "15" "Backup explorer" \ "16" "Help" 2> /tmp/$pid-action escaper action=$(cat /tmp/$pid-action); rm -f /tmp/$pid-action > /dev/null 2> /dev/null elif [ -d /etc/backups/ ]; then dialog --backtitle "$backtitle" --title "$title" --menu "\nOld script detected, because of this, the menu is slimmed down to show only needed actions.\nAfter you have upgraded your script, the menu will be showing all options.\n\nSelect action:" 14 50 0 \ "5" "Update backupscript" \ "7" "Quota calculator" \ "9" "Show account quota" \ "16" "Help" 2> /tmp/$pid-action escaper action=$(cat /tmp/$pid-action); rm -f /tmp/$pid-action > /dev/null 2> /dev/null elif [ -d /etc/xlsbackup/ ]; then dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThe current configuration and script are too old and cannot be upgraded.\n\nPlease uninstall the script by removing it's crontab entry, configfile and backupscript and re-run this installer to install the script." 12 60 clear exit elif [ -f /usr/local/bin/xlsbackup ]; then dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThe current configuration and script are too old and cannot be upgraded.\n\nPlease uninstall the script by removing it's crontab entry, configfile and backupscript and re-run this installer to install the script." 12 60 clear exit else dialog --backtitle "$backtitle" --title "$title" --menu "\nThis menu is currently not showing all options. Please install the backupscript in order to use all the functions.\n\nSelect action:" 12 50 0 \ "1" "Install backupscript (easy)" \ "2" "Install backupscript (advanced)" \ "7" "Quota calculator" \ "16" "Help" 2> /tmp/$pid-action escaper action=$(cat /tmp/$pid-action); rm -f /tmp/$pid-action > /dev/null 2> /dev/null fi # The specific actions in the script: case $action in 1) logger -t backup_installer "Started the easy backup installation procedure" newversion=$(curl -s http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt | grep "VERSION=" | cut -d = -f 2 | sed 's/"//g' | head -1) if [ -f /etc/cloudvps/backup.conf ]; then dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThe backupscript is already installed.\n\nIf you want to change the configuration, please use the configuration editor." 10 60 clear exit fi if [ -f /etc/backups/xlsbackup.conf ]; then dialog --backtitle "$backtitle" --title "$title" --msgbox "\nOld configfile found, please upgrade the script instead of installing it again." 8 60 clear exit fi genhour genminute genday mysqldumps while [ $genday = 0 ]; do genday done dialog --backtitle "$backtitle" --title "$title" --form "\nYour Backup Account Details\n" 22 65 0 \ "Backup username....:" 1 1 "" 1 22 30 0 \ "Backup password....:" 2 1 "" 2 22 20 0 \ "Backup server......:" 3 1 "" 3 22 35 0 \ "Backup root dir....:" 4 1 "/" 4 22 35 0 \ "Weekly retention...: $currentsize GB extra needed per week" 5 1 "0" 5 22 2 0 \ "Monthly retention..: $currentsize GB extra needed per month" 6 1 "0" 6 22 2 0 \ "Enable MySQL dumps.:" 7 1 "$mysqldumps" 7 22 1 0 \ "MySQL dump dir.....:" 8 1 "/var/sqlbackups/" 8 22 35 0 \ "Hour schedule (HH).:" 9 1 "$hour" 9 22 2 0 \ "Minute sched. (MM).:" 10 1 "$minute" 10 22 2 0 \ "Extensive logging..:" 11 1 "Y" 11 22 1 0 \ "Backup report email:" 12 1 "" 12 22 35 0 \ "Send reports.......:" 13 1 "N" 13 22 1 0\ "Alerts email.......:" 14 1 "" 14 22 35 0 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options `) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi while [ ${#array[@]} -lt 13 ] do dialog --backtitle "$backtitle" --title "$title" --msgbox "\nNot all fields are populated!\n\nPlease make sure you fill in all the fields." 10 50; clear logger -t backup_installer "Not all form fields are populated, returning to form..." dialog --backtitle "$backtitle" --title "$title" --form "\nYour Backup Account Details\n" 22 60 0 \ "Backup username....:" 1 1 "${array[0]}" 1 22 14 0 \ "Backup password....:" 2 1 "${array[1]}" 2 22 20 0 \ "Backup server......:" 3 1 "${array[2]}" 3 22 35 0 \ "Backup root dir....:" 4 1 "${array[3]}" 4 22 35 0 \ "Weekly retention...: $currentsize GB extra needed per week" 5 1 "${array[4]}" 5 1 "${array[4]}" 5 22 2 0 \ "Monthly retention..: $currentsize GB extra needed per month" 6 1 "${array[5]}" 6 22 2 0 \ "Enable MySQL dumps.:" 7 1 "${array[6]}" 7 22 1 0 \ "MySQL dump dir.....:" 8 1 "${array[7]}" 8 22 35 0 \ "Hour schedule (HH).:" 9 1 "${array[8]}" 9 22 2 0 \ "Minute sched. (MM).:" 10 1 "${array[9]}" 10 22 2 0 \ "Extensive logging..:" 11 1 "${array[10]}" 11 22 1 0 \ "Backup report email:" 12 1 "${array[11]}" 12 22 35 0 \ "Send reports.......:" 13 1 "${array[12]}" 13 22 1 0 \ "Alerts email.......:" 14 1 "${array[13]}" 14 22 35 0 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options` ) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi done case $choice in 0) clear # First check if CSF is present, if so add the appropriate rules: if [ -d /etc/csf/ ]; then backupip=`host ${array[2]} | awk '{print $4}'` # Restart CSF echo "5" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nAdding backupserver IP to whitelist" 8 50 if csf -a $backupip then echo "5" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nAdded backupserver IP to whitelist" 8 50; sleep 1 logger -t backup_installer "Added backupserver IP to whitelist" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nCould not add backupserver IP to whitelist, installation will not be possible!\n\nPlease check your CSF settings and re-run this installer" 9 60 logger -t backup_installer "Could not add backupserver IP to whitelist, installation not possible at this time" exit fi fi # Continue installing the script echo "10" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nCreating configfile" 8 50 0 if ! [ -d /etc/cloudvps/ ]; then if mkdir -p /etc/cloudvps/ > /dev/null 2>&1 then logger -t backup_installer "Created the config directory /etc/cloudvps/" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nCould not create the configuration directory /etc/cloudvps/\n\nExiting..." 9 60 logger -t backup_installer "Failed to create the config directory /etc/cloudvps" clear exit fi fi touch /etc/cloudvps/backup.conf > /dev/null 2> /dev/null # Make sure that only root can read the configfile chmod 600 /etc/cloudvps/backup.conf > /dev/null 2> /dev/null echo -e "BUSER=${array[0]}" >> /etc/cloudvps/backup.conf echo -e "BSERVER=${array[2]}" >> /etc/cloudvps/backup.conf echo -e "NOTIFICATIONS=Y" >> /etc/cloudvps/backup.conf echo -e "WEKEN=${array[4]}" >> /etc/cloudvps/backup.conf echo -e "MAANDEN=${array[5]}" >> /etc/cloudvps/backup.conf echo -e "PRIVKEY=$privkeydefault" >> /etc/cloudvps/backup.conf echo -e "BACKUPROOT=${array[3]}" >> /etc/cloudvps/backup.conf echo -e "XFERSPEED=7500" >> /etc/cloudvps/backup.conf echo -e "SSHPORT=$defaultsshport" >> /etc/cloudvps/backup.conf echo -e "REMOTEPATH=/home/${array[0]}/" >> /etc/cloudvps/backup.conf echo -e "H=$hostname" >> /etc/cloudvps/backup.conf if [ ${array[10]} = "Y" ]; then echo -e "LOGGING=Y" >> /etc/cloudvps/backup.conf else echo -e "LOGGING=N" >> /etc/cloudvps/backup.conf fi if [ ${array[6]} = "Y" ] ; then echo -e "MYSQLBACKUP=Y" >> /etc/cloudvps/backup.conf echo -e "MYSQLUSER=$mysqluser" >> /etc/cloudvps/backup.conf echo -e "MYSQLPASS=$mysqlpass" >> /etc/cloudvps/backup.conf echo -e "MYSQLBACKUPDIR=${array[7]}" >> /etc/cloudvps/backup.conf else echo -e "MYSQLBACKUP=N" >> /etc/cloudvps/backup.conf echo -e "MYSQLUSER=$mysqluser" >> /etc/cloudvps/backup.conf echo -e "MYSQLPASS=$mysqlpass" >> /etc/cloudvps/backup.conf echo -e "MYSQLBACKUPDIR=${array[7]}" >> /etc/cloudvps/backup.conf fi echo -e "UPDATECHECK=$day" >> /etc/cloudvps/backup.conf echo -e "VERSION=\"$newversion\"" >> /etc/cloudvps/backup.conf echo -e "AUTOUPDATE=Y" >> /etc/cloudvps/backup.conf echo -e "PATCHED=Y" >> /etc/cloudvps/backup.conf echo -e "REPORTS_EMAIL=${array[11]}" >> /etc/cloudvps/backup.conf echo -e "${array[13]}" > /etc/cloudvps/recipients.mail echo -e "/usr/src/\n/lib/modules/\n/usr/tmpDSK\n/lib/firmware/\n/selinux/\n/var/named/run-root/\n/proc/\n/sys/\n/var/log/\n/tmp/\n/dev/\n/mnt/\n/var/run/\n/var/installatron/\ncache/\n/var/tmp/\ntypo3conf/deprecation_*\n/run/\nsession/\n/var/lib/varnish/\n/media\n/usr/local/psa/admin/logs/\n/home/cpbackuptmp/\n/backup/cpbackup/\n/home/virtfs/\n/usr/local/cpanel/3rdparty/mailman/cgi-bin/\n/usr/local/apache/\n/etc/exim/\n/home/tmp/" > /etc/cloudvps/excludes.rsync logger -t backup_installer "Created the configfile" if [ -f /root/.ssh/id_rsa.cloudvpsbackup ]; then echo "20" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile found, not generating a new one" 8 50 0; sleep 1 logger -t backup_installer "Keyfile not found, creating a new one" else echo "20" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nGenerating new key" 8 50 0; ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa.cloudvpsbackup > /dev/null 2> /dev/null logger -t backup_installer "Created new SSH key" fi echo "30" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nChecking for keyfile on the backupserver" 8 50 0 if /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oStrictHostKeyChecking=no -oPort=$defaultsshport ${array[0]}@${array[2]} expect "password:" send "${array[1]}\r" expect "sftp>" send "get .ssh/authorized_keys .\r" expect "sftp>" send "quit\r" EOF then if [ -f authorized_keys ] then echo "40" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile found, key added and uploading new keyfile" 8 50 0; cat /root/.ssh/id_rsa.cloudvpsbackup.pub >> authorized_keys; if /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oStrictHostKeyChecking=no -oPort=$defaultsshport ${array[0]}@${array[2]} expect "password:" send "${array[1]}\r" expect "sftp>" send "put authorized_keys .ssh/authorized_keys\r" expect "sftp>" send "quit\r" EOF then echo "40" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile succesfully uploaded" 8 50 rm authorized_keys > /dev/null 2> /dev/null logger -t backup_installer "Keyfile succesfully uploaded to the backupserver" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThere was an error uploading the keyfile to the backupserver, will now exit" 9 60 rm authorized_keys > /dev/null 2> /dev/null logger -t backup_installer "Could not upload the keyfile to the backupserver, exiting..." clear exit fi else echo "40" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile not found, creating and uploading new keyfile" 8 50 0 if /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oStrictHostKeyChecking=no -oPort=$defaultsshport ${array[0]}@${array[2]} expect "password:" send "${array[1]}\r" expect "sftp>" send "mkdir .ssh\r" expect "sftp>" send "cd .ssh\r" expect "sftp>" send "put /root/.ssh/id_rsa.cloudvpsbackup.pub authorized_keys\r" expect "sftp>" send "quit\r" EOF then echo "40" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile succesfully uploaded" 8 50 logger -t backup_installer "Keyfile succesfully uploaded to the backupser" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThere was an error uploading the keyfile to the backupserver, will now exit" 9 60 logger -t backup_installer "Could not upload keyfile to the backupserver, exiting..." $0 --uninstall > /dev/null 2>&1 clear exit fi fi fi echo "50" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nDownloading backupscript" 8 50 0 if curl -f -s -o /usr/local/bin/cloudvpsbackup http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt > /dev/null 2> /dev/null; then echo "60" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nDownload of the backupscript succeeded" 8 50 0 logger -t backup_installer "Downloaded the backupscript" else echo "60" | dialog --backtitle "$backtitle" --title "$title" --msgbox "\nDownload of the script failed!\nPlease check your networksettings" 9 50 logger -t backup_installer "Could not download the backupscript, exiting..." $0 --uninstall > /dev/null 2>&1 clear exit fi echo "70" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nSetting permissions on script" 8 50 0; chmod +x /usr/local/bin/cloudvpsbackup > /dev/null 2> /dev/null logger -t backup_installer "Setting permissions on the backupscript" echo "80" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nSetting up cronjob" 8 50 if [[ "${array[12]}" == "N" ]]; then if cat <(crontab -l) <(echo "${array[9]} ${array[8]} * * * /usr/local/bin/cloudvpsbackup > /dev/null 2>&1") | crontab - then echo "90" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nSuccessfully set up the cronjob" 8 50 logger -t backup_installer "Created a cronjob entry" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThere was an error setting up the cronjob.\n\nThe installer will now exit!" 10 50 logger -t backup_installer "Could not create cronjob entry, exiting..." $0 --uninstall > /dev/null 2>&1 clear exit fi else if cat <(crontab -l) <(echo "${array[9]} ${array[8]} * * * /usr/local/bin/cloudvpsbackup 2>&1 | mail -s '[BACKUP] Backupreport of `hostname`' ${array[11]}") | crontab - then echo "90" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nSuccessfully set up the cronjob" 8 50 logger -t backup_installer "Created a cronjob entry" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThere was an error setting up the cronjob.\n\nThe installer will now exit!" 10 50 logger -t backup_installer "Could not create cronjob entry, exiting..." $0 --uninstall > /dev/null 2>&1 clear exit fi fi echo "100" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nInstallation finished!" 8 50; sleep 1 logger -t backup_installer "Backupscript installation succeeded!" dialog --backtitle "$backtitle" --title "$title" --yesno "\nDo you want to have a short installation report emailed to the following address?\n\n${array[11]}?" 10 60 sendreport=$? if [ $sendreport = 0 ]; then backupinstallationreport dialog --backtitle "$backtitle" --title "$title" --msgbox "\nInstallation report has been sent to the following address:\n\n${array[11]}." 10 60 logger -t backup_installer "Sent installation report to ${array[11]}" fi dialog --backtitle "$backtitle" --title "$title" --msgbox "\nCongratulations!\n\nThe backupscript is now installed on this machine!" 10 50 clear exit ;; esac logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit ;; 2) logger -t backup_installer "Started the advanced installation procedure" newversion=$(curl -s http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt | grep "VERSION=" | cut -d = -f 2 | sed 's/"//g' | head -1) if [ -f /etc/cloudvps/backup.conf ]; then dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThe backupscript is already installed.\n\nIf you want to change the configuration, please use the configuration editor." 10 60 clear exit fi if [ -f /etc/backups/xlsbackup.conf ]; then dialog --backtitle "$backtitle" --title "$title" --msgbox "\nOld configfile found, please upgrade the script instead of installing it again." 8 60 clear exit fi genhour genminute genday mysqldumps while [ $genday = 0 ]; do genday done dialog --backtitle "$backtitle" --title "$title" --form "\nYour Backup Account Details\n" 0 60 22 \ "Backup username....:" 1 1 "" 1 22 14 0 \ "Backup password....:" 2 1 "" 2 22 20 0 \ "Backup server......:" 3 1 "" 3 22 30 0 \ "Backup root path...:" 4 1 "/" 4 22 30 0 \ "Backup remote path.:" 5 1 "/replace/with/remote/path/" 5 22 30 0 \ "SSH Keyfile........:" 6 1 "/root/.ssh/id_rsa.cloudvpsbackup" 6 22 35 0 \ "SSH Port...........:" 7 1 "22" 7 22 5 0 \ "Weekly retention...: $currentsize GB extra needed per week" 8 1 "0" 8 22 2 0 \ "Monthly retention..: $currentsize GB extra needed per month" 9 1 "0" 9 22 2 0 \ "MySQL dumps........:" 10 1 "$mysqldumps" 10 22 1 0 \ "MySQL username.....:" 11 1 "$mysqluser" 11 22 20 0 \ "MySQL password.....:" 12 1 "$mysqlpass" 12 22 20 0 \ "MySQL dump folder..:" 13 1 "/var/sqlbackups/" 13 22 35 0 \ "Hour schedule (HH).:" 14 1 "$hour" 14 22 2 0 \ "Minute sched. (MM).:" 15 1 "$minute" 15 22 2 0 \ "Notifications......:" 16 1 "Y" 16 22 1 0 \ "Verbose logging....:" 17 1 "Y" 17 22 1 0 \ "Xfer speed (in KBs): Max is 12500 KB/s" 18 1 "7500" 18 22 5 0 \ "Automatic updates..:" 19 1 "Y" 19 22 1 0 \ "Backup report email:" 20 1 "" 20 22 30 0 \ "Send reports.......:" 21 1 "N" 21 22 1 0 \ "Alerts email.......:" 22 1 "" 22 22 30 0 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options `) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi while [[ ${array[17]} -gt 12500 ]] do dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThe given transferspeed of ${array[17]} KB/s you entered is invalid, the maximum is 12500 KB/s" 8 60; clear logger -t backup_installer "Network speed set too high at ${array[12]}, issuing a warning" dialog --backtitle "$backtitle" --title "$title" --form "\nYour Backup Account Details\n" 28 60 0 \ "Backup username....:" 1 1 "${array[0]}" 1 22 14 0 \ "Backup password....:" 2 1 "${array[1]}" 2 22 20 0 \ "Backup server......:" 3 1 "${array[2]}" 3 22 30 0 \ "Backup root path...:" 4 1 "${array[3]}" 4 22 30 0 \ "Backup remote path.:" 5 1 "${array[4]}" 5 22 30 0 \ "SSH Keyfile........:" 6 1 "${array[5]}" 6 22 35 0 \ "SSH Port...........:" 7 1 "${array[6]}" 7 22 5 0 \ "Weekly retention...: $currentsize GB extra needed per week" 8 1 "${array[7]}" 8 22 2 0 \ "Monthly retention..: $currentsize GB extra needed per month" 9 1 "${array[8]}" 9 22 2 0 \ "MySQL dumps........:" 10 1 "${array[9]}" 10 22 1 0 \ "MySQL username.....:" 11 1 "${array[10]}" 11 22 20 0 \ "MySQL password.....:" 12 1 "${array[11]}" 12 22 20 0 \ "MySQL dump folder..:" 13 1 "${array[12]}" 13 22 35 0 \ "Hour schedule (HH).:" 14 1 "${array[13]}" 14 22 2 0 \ "Minute sched. (MM).:" 15 1 "${array[14]}" 15 22 2 0 \ "Notifications......:" 16 1 "${array[15]}" 16 22 1 0 \ "Verbose logging....:" 17 1 "${array[16]}" 17 22 1 0 \ "Xfer speed (in KBs): Max is 12500 KB/s" 18 1 "${array[17]}" 18 22 5 0 \ "Automatic updates..:" 19 1 "${array[18]}" 19 22 1 0 \ "Backup report email:" 20 1 "${array[19]}" 20 22 30 0 \ "Send reports.......:" 21 1 "${array[20]}" 21 22 1 0 \ "Alerts email.......:" 22 1 "${array[21]}" 22 22 30 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options `) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi done while ! [ ${#array[@]} = 22 -o ${#array[@]} = 21 -o ${#array[@]} = 20 ] do logger -t backup_installer "Not all fields are populated, returning to the form" dialog --backtitle "$backtitle" --title "$title" --msgbox "\nNot all fields are populated!\n\nPlease make sure you fill in all the fields." 10 50; clear dialog --backtitle "$backtitle" --title "$title" --form "\nYour Backup Account Details\n" 28 60 0 \ "Backup username....:" 1 1 "${array[0]}" 1 22 14 0 \ "Backup password....:" 2 1 "${array[1]}" 2 22 20 0 \ "Backup server......:" 3 1 "${array[2]}" 3 22 30 0 \ "Backup root path...:" 4 1 "${array[3]}" 4 22 30 0 \ "Backup remote path.:" 5 1 "${array[4]}" 5 22 30 0 \ "SSH Keyfile........:" 6 1 "${array[5]}" 6 22 35 0 \ "SSH Port...........:" 7 1 "${array[6]}" 7 22 5 0 \ "Weekly retention...: $currentsize GB extra needed per week" 8 1 "${array[7]}" 8 22 2 0 \ "Monthly retention..: $currentsize GB extra needed per month" 9 1 "${array[8]}" 9 22 2 0 \ "MySQL dumps........:" 10 1 "${array[9]}" 10 22 1 0 \ "MySQL username.....:" 11 1 "${array[10]}" 11 22 20 0 \ "MySQL password.....:" 12 1 "${array[11]}" 12 22 20 0 \ "MySQL dump folder..:" 13 1 "${array[12]}" 13 22 35 0 \ "Hour schedule (HH).:" 14 1 "${array[13]}" 14 22 2 0 \ "Minute sched. (MM).:" 15 1 "${array[14]}" 15 22 2 0 \ "Notifications......:" 16 1 "${array[15]}" 16 22 1 0 \ "Verbose logging....:" 17 1 "${array[16]}" 17 22 1 0 \ "Xfer speed (in KBs): Max is 12500 KB/s" 18 1 "${array[17]}" 18 22 5 0 \ "Automatic updates..:" 19 1 "${array[18]}" 19 22 1 0 \ "Backup report email:" 20 1 "${array[19]}" 20 22 30 0 \ "Send reports.......:" 21 1 "${array[20]}" 21 22 1 0 \ "Alerts email.......:" 22 1 "${array[21]}" 22 22 30 0 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options `) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi done case $choice in 0) clear # First check if CSF is present, if so add the appropriate rules: if [ -d /etc/csf/ ]; then echo "0" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nAdding backupserver IP to CSF whitelist" 8 50 backupip=`host ${array[2]} | awk '{print $4}'` # Add IP of the backupserver to the allow list echo -e "$backupip # Backupserver ${array[2]}" >> /etc/csf/csf.allow logger -t backup_installer "Added IP address $backupip to the whitelist of CSF" # Restart CSF echo "5" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nRestarting the CSF service" 8 50 if /etc/init.d/csf restart > /dev/null 2>&1 then echo "5" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nRestarted the CSF service" 8 50; sleep 1 logger -t backup_installer "Restarted the CSF service" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nCould not restart CSF, installation will not be possible!\n\nPlease check your CSF settings and re-run this installer" 9 60 logger -t backup_installer "Could not restart CSF service and backup is not possible, exiting..." exit fi fi # Continue installing the script echo "10" | dialog -backtitle "$backtitle" --title"$title" --gauge "\nCreating configfile" 8 50 0 if ! [ -d /etc/cloudvps/ ]; then mkdir -p /etc/cloudvps/ > /dev/null 2> /dev/null fi touch /etc/cloudvps/backup.conf > /dev/null 2> /dev/null chmod 600 /etc/cloudvps/backup.conf > /dev/null 2> /dev/null echo -e "BUSER=${array[0]}" >> /etc/cloudvps/backup.conf echo -e "BSERVER=${array[2]}" >> /etc/cloudvps/backup.conf echo -e "NOTIFICATIONS=${array[15]}" >> /etc/cloudvps/backup.conf echo -e "WEKEN=${array[7]}" >> /etc/cloudvps/backup.conf echo -e "MAANDEN=${array[8]}" >> /etc/cloudvps/backup.conf echo -e "PRIVKEY=${array[5]}" >> /etc/cloudvps/backup.conf echo -e "BACKUPROOT=${array[3]}" >> /etc/cloudvps/backup.conf echo -e "XFERSPEED=${array[17]}" >> /etc/cloudvps/backup.conf echo -e "SSHPORT=${array[6]}" >> /etc/cloudvps/backup.conf echo -e "REMOTEPATH=${array[4]}" >> /etc/cloudvps/backup.conf echo -e "H=$hostname" >> /etc/cloudvps/backup.conf if [ ${array[16]} = "Y" ]; then echo -e "LOGGING=Y" >> /etc/cloudvps/backup.conf else echo -e "LOGGING=N" >> /etc/cloudvps/backup.conf fi if [ ${array[9]} = "Y" ] ; then echo -e "MYSQLBACKUP=Y" >> /etc/cloudvps/backup.conf echo -e "MYSQLUSER=${array[10]}" >> /etc/cloudvps/backup.conf echo -e "MYSQLPASS=${array[11]}" >> /etc/cloudvps/backup.conf echo -e "MYSQLBACKUPDIR=${array[12]}" >> /etc/cloudvps/backup.conf else echo -e "MYSQLBACKUP=N" >> /etc/cloudvps/backup.conf echo -e "MYSQLUSER=$mysqluser" >> /etc/cloudvps/backup.conf echo -e "MYSQLPASS=$mysqluser" >> /etc/cloudvps/backup.conf echo -e "MYSQLBACKUPDIR=${array[12]}" >> /etc/cloudvps/backup.conf fi echo -e "UPDATECHECK=$day" >> /etc/cloudvps/backup.conf echo -e "VERSION=\"$newversion\"" >> /etc/cloudvps/backup.conf echo -e "AUTOUPDATE=${array[18]}" >> /etc/cloudvps/backup.conf echo -e "PATCHED=Y" >> /etc/cloudvps/backup.conf echo -e "REPORTS_EMAIL=${array[19]}" >> /etc/cloudvps/backup.conf if [ -z "${array[21]}" ]; then echo -e "${array[20]}" > /etc/cloudvps/recipients.mail else echo -e "${array[21]}" > /etc/cloudvps/recipients.mail fi echo -e "/usr/src/\n/lib/modules/\n/usr/tmpDSK\n/lib/firmware/\n/selinux/\n/var/named/run-root/\n/proc/\n/sys/\n/var/log/\n/tmp/\n/dev/\n/mnt/\n/var/run/\n/var/installatron/\ncache/\n/var/tmp/\ntypo3conf/deprecation_*\n/run/\nsession/\n/var/lib/varnish/\n/media\n/usr/local/psa/admin/logs/\n/home/cpbackuptmp/\n/backup/cpbackup/\n/home/virtfs/\n/usr/local/cpanel/3rdparty/mailman/cgi-bin/\n/usr/local/apache/\n/etc/exim/\n/home/tmp/" > /etc/cloudvps/excludes.rsync if [ -f ${array[5]} ]; then echo "20" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile found, not generating a new one" 8 50 0; sleep 1 else echo "20" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nGenerating new key" 8 50 0; ssh-keygen -t rsa -N '' -f ${array[5]} > /dev/null 2> /dev/null fi logger -t backup_installer "Created the configfile" echo "30" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nChecking for keyfile on the backupserver" 8 50 0 if /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oStrictHostKeyChecking=no -oPort=${array[6]} ${array[0]}@${array[2]} expect "password:" send "${array[1]}\r" expect "sftp>" send "get .ssh/authorized_keys .\r" expect "sftp>" send "quit\r" EOF then if [ -f authorized_keys ] then echo "40" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile found, key added and uploading new keyfile" 8 50 0; cat ${array[5]}.pub >> authorized_keys; /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oStrictHostKeyChecking=no -oPort=${array[6]} ${array[0]}@${array[2]} expect "password:" send "${array[1]}\r" expect "sftp>" send "put authorized_keys .ssh/authorized_keys\r" expect "sftp>" send "quit\r" EOF rm authorized_keys > /dev/null 2> /dev/null logger -t backup_installer "Keyfile found on backupserver, added key and re-upload keyfile" else echo "40" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile not found, creating and uploading new keyfile" 8 50 0 /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oStrictHostKeyChecking=no -oPort=${array[6]} ${array[0]}@${array[2]} expect "password:" send "${array[1]}\r" expect "sftp>" send "mkdir .ssh\r" expect "sftp>" send "cd .ssh\r" expect "sftp>" send "put ${array[5]}.pub authorized_keys\r" expect "sftp>" send "quit\r" EOF logger -t backup_installer "No keyfile found, uploading new keyfile to backupserver" fi fi echo "50" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nDownloading backupscript" 8 50 0 if curl -s -o /usr/local/bin/cloudvpsbackup http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt > /dev/null 2> /dev/null; then echo "60" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nDownload of the backupscript succeeded" 8 50 0 logger -t backup_installer "Succesfully downloaded the backupscript" else echo "60" | dialog --backtitle "$backtitle" --title "$title" --msgbox "\nDownload of the script failed!\nPlease check your network settings" 9 50 logger -t backup_installer "Failed to download the backupscript, please check your network setup" clear exit fi echo "70" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nSetting permissions on script" 8 50 0; chmod +x /usr/local/bin/cloudvpsbackup > /dev/null 2> /dev/null logger -t backup_installer "Setting permissions on the backupscript" echo "80" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nSetting up cronjob" 8 50 if cat <(crontab -l) <(echo "${array[14]} ${array[13]} * * * /usr/local/bin/cloudvpsbackup 2>&1 | mail -s '[BACKUP] Backupreport of `hostname`' ${array[19]}") | crontab - then echo "90" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nSuccessfully set up the cronjob" 8 50 logger -t backup_installer "Installed cronjob at ${array[13]}:${array[14]}" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nThere was an error setting up the cronjob.\n\nThe installer will now exit!" 10 50 logger -t backup_installer "There was an error installing the cronjob, exiting..." clear exit fi echo "100" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nInstallation finished!" 8 50; sleep 1 dialog --backtitle "$backtitle" --title "$title" --yesno "\nDo you want to have a short installation report emailed to the following address:\n\n${array[19]}?" 10 60 sendreport=$? if [ $sendreport = 0 ]; then backupadvancedinstallationreport dialog --backtitle "$backtitle" --title "$title" --msgbox "\nInstallation report has been sent to the following address:\n\n${array[19]}." 9 60 logger -t backup_installer "Mailed installation report to ${array[19]}" fi dialog --backtitle "$backtitle" --title "$title" --msgbox "\nCongratulations!\n\nThe backupscript is now installed on this machine!" 9 50 logger -t backup_installer "Succesfully installed the backupscript!" clear ;; 1) clear ;; esac logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit ;; 3) logger -t backup_installer "Started the configuration editor" if ! [[ -f /etc/cloudvps/backup.conf || -f /etc/backups/xlsbackup.conf ]]; then dialog --backtitle "$backtitle_config" --title "$title" --msgbox "\nNo configfile found!\n\nPlease install the script first." 9 50 clear exit fi clear # Include configfile: if [ -f /etc/cloudvps/backup.conf ]; then source /etc/cloudvps/backup.conf fi # Checking for controlpanel and configuring MySQL dump support: if [ -d /usr/local/directadmin ]; then if [[ $MYSQLBACKUP == "Y" ]]; then if [ -z $MYSQLUSER ]; then source /usr/local/directadmin/conf/mysql.conf MYSQLUSER=$user MYSQLPASS=$passwd fi fi source /usr/local/directadmin/conf/mysql.conf elif [ -d /usr/local/cpanel ]; then if [[ $MYSQLBACKUP == "Y" ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER="root" MYSQLPASS="" fi fi elif [ -d /usr/local/psa ]; then if [[ $MYSQLBACKUP == "Y" ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER="admin" MYSQLPASS=$(cat /etc/psa/.psa.shadow) fi fi elif [ -d /var/openpanel ]; then if [[ $MYSQLBACKUP == "Y" ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER=$(grep ^user < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') MYSQLPASS=$(grep ^password < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') fi fi elif [ -f /usr/local/ispconfig/server/lib/mysql_clientdb.conf ]; then if [[ $MYSQLBACKUP == "Y" ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER=$(grep user < /usr/local/ispconfig/server/lib/mysql_clientdb.conf | awk '{print $3'} | sed "s/[';]//g") MYSQLPASS=$(grep password < /usr/local/ispconfig/server/lib/mysql_clientdb.conf | awk '{print $3'} | sed "s/[';]//g") fi fi elif [ -f /etc/mysql/debian.cnf ]; then if [[ $MYSQLBACKUP == "Y" ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER=$(grep ^user < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') MYSQLPASS=$(grep ^password < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') fi fi fi dialog --backtitle "$backtitle_config" --title "$title" --colors --form "\nBelow are the current configuration options.\nYou can adjust the settings to your needs and when you're done, select \"OK\"." 26 65 0 \ "Backup username....:" 1 1 "$BUSER" 1 22 14 0 \ "Backup server......:" 2 1 "$BSERVER" 2 22 30 0 \ "Backup root path...:" 3 1 "$BACKUPROOT" 3 22 30 0 \ "Backup remote path.:" 4 1 "$REMOTEPATH" 4 22 30 0 \ "SSH Port...........:" 5 1 "$SSHPORT" 5 22 5 0 \ "Weekly retention...: $currentsize GB extra needed per week" 6 1 "$WEKEN" 6 22 2 0 \ "Monthly retention..: $currentsize GB extra needed per month" 7 1 "$MAANDEN" 7 22 2 0 \ "MySQL dumps........:" 8 1 "$MYSQLBACKUP" 8 22 1 0 \ "MySQL username.....:" 9 1 "$MYSQLUSER" 9 22 20 0 \ "MySQL password.....:" 10 1 "$MYSQLPASS" 10 22 20 0 \ "MySQL dump folder..:" 11 1 "$MYSQLBACKUPDIR" 11 22 35 0 \ "Notifications......:" 12 1 "$NOTIFICATIONS" 12 22 1 0 \ "Verbose logging....:" 13 1 "$LOGGING" 13 22 1 0 \ "Xfer speed (in KBs): Max is 12500 KB/s" 14 1 "$XFERSPEED" 14 22 5 0 \ "Automatic updates..:" 15 1 "$AUTOUPDATE" 15 22 1 0 \ "Alert emailaddress.: Can be changed via Mail Recipients" 16 1 "" 16 22 0 1 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options `) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi while ! [ ${#array[@]} = 16 -o ${#array[@]} = 17 -o ${#array[@]} = 15 -o ${#array[@]} = 14 ] do logger -t backup_installer "Not all of the required fields are populated, returning to installation form" dialog --backtitle "$backtitle" --title "$title" --msgbox "\nNot all fields are populated!\n\nPlease make sure you fill in all the fields." 10 50; clear dialog --backtitle "$backtitle_config" --title "$title" --colors --form "\nBelow are the current configuration options.\nYou can adjust the settings to your needs and when you're done, select \"OK\"." 25 60 0 \ "Backup username....:" 1 1 "${array[0]}" 1 22 14 0 \ "Backup server......:" 2 1 "${array[1]}" 2 22 30 0 \ "Backup root path...:" 3 1 "${array[2]}" 3 22 30 0 \ "Backup remote path.:" 4 1 "${array[3]}" 4 22 30 0 \ "SSH Port...........:" 5 1 "${array[4]}" 5 22 5 0 \ "Weekly retention...: $currentsize GB extra needed per week" 6 1 "${array[5]}" 6 22 2 0 \ "Monthly retention..: $currentsize GB extra needed per month" 7 1 "${array[6]}" 7 22 2 0 \ "MySQL dumps........:" 8 1 "${array[7]}" 8 22 1 0 \ "MySQL username.....:" 9 1 "${array[8]}" 9 22 20 0 \ "MySQL password.....:" 10 1 "${array[9]}" 10 22 20 0 \ "MySQL dump folder..:" 11 1 "${array[10]}" 11 22 35 0 \ "Notifications......:" 12 1 "${array[11]}" 12 22 1 0 \ "Verbose logging....:" 13 1 "${array[12]}" 13 22 1 0 \ "Xfer speed (in KBs): Max is 12500 KB/s" 14 1 "${array[13]}" 14 22 5 0 \ "Automatic updates..:" 15 1 "${array[14]}" 15 22 1 0 \ "Alert emailaddress.: Can be changed via Mail Recipients" 16 1 "" 16 22 0 1 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options `) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi done case $choice in 0) # Removing lock from file and change config values: if [ -f /etc/cloudvps/backup.conf ]; then chattr -i /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/BUSER=$BUSER/BUSER=${array[0]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/BSERVER=$BSERVER/BSERVER=${array[1]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/BACKUPROOT=$BACKUPROOT/BACKUPROOT=${array[2]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/REMOTEPATH=$REMOTEPATH/REMOTEPATH=${array[3]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/SSHPORT=$SSHPORT/SSHPORT=${array[4]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/WEKEN=$WEKEN/WEKEN=${array[5]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MAANDEN=$MAANDEN/MAANDEN=${array[6]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLBACKUP=$MYSQLBACKUP/MYSQLBACKUP=${array[7]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLUSER=$MYSQLUSER/MYSQLUSER=${array[8]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=$MYSQLPASS/MYSQLPASS=${array[9]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLBACKUPDIR=$MYSQLBACKUPDIR/MYSQLBACKUPDIR=${array[10]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/XFERSPEED=$XFERSPEED/XFERSPEED=${array[13]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/LOGGING=$LOGGING/LOGGING=${array[12]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/NOTIFICATIONS=$NOTIFICATIONS/NOTIFICATIONS=${array[11]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/AUTOUPDATE=$AUTOUPDATE/AUTOUPDATE=${array[14]}/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi dialog --backtitle "$backtitle_config" --title "$title" --msgbox "\nYour configuration settings are now saved." 7 50 logger -t backup_installer "Saved configuration changes" clear exit ;; esac ;; 4) logger -t backup_installer "Started the backup uninstaller procedure" clear dialog --backtitle "$backtitle_uninstall" --title "$title" --yesno "\nThis wil remove the backupscript including all configuration files and cronjob from your server.\n\nDo you agree?" 10 60 agree=$? case $agree in 0) echo "15" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoving cronjob" 8 60 crontab -u root -l > /tmp/cron.txt if grep cloudvpsbackup /tmp/cron.txt > /dev/null then if sed -i '/cloudvpsbackup/ d' /tmp/cron.txt; crontab /tmp/cron.txt; rm /tmp/cron.txt > /dev/null 2>&1 then echo "30" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoved cronjob" 8 60 logger -t backup_installer "Removed the backup cronjob" else echo "30" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nCould not remove cronjob (remove manually)" 8 60 logger -t backup_installer "Could not remove cronjob, remove manually via \"crontab -e\"" fi elif grep xlsbackup /tmp/cron.txt > /dev/null then if sed -i '/xlsbackup/ d' /tmp/cron.txt; crontab /tmp/cron.txt; rm /tmp/cron.txt > /dev/null 2>&1 then echo "30" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoved cronjob" 8 60 logger -t backup_installer "Removed the backup cronjob" else echo "30" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nCould not remove cronjob (remove manually)" 8 60 logger -t backup_installer "Could not remove cronjob, remove manually via \"crontab -e\"" fi fi echo "45" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoving configfiles: Removing" 8 50 if rm -rf /etc/cloudvps/ > /dev/null 2> /dev/null then echo "60" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoving configfiles: Done" 8 50; sleep 1 logger -t backup_installer "Purged configfiles" else echo "60" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoving configfiles: Failed" 8 50; sleep 1 logger -t backup_installer "Could not purge configfiles" fi echo "75" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoving logfiles: Removing" 8 50 if rm -rf /var/log/backups/ > /dev/null 2> /dev/null then echo "90" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoving logfiles: Done" 8 50; sleep 1 logger -t backup_installer "Purged logfiles" else echo "90" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoving logfiles: Failed" 8 50; sleep 1 logger -t backup_installer "Could not purge logfiles" fi echo "95" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoving backupscript: Removing" 8 50 if rm -rf /usr/local/bin/cloudvpsbackup > /dev/null 2> /dev/null then echo "100" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoving backupscript: Done" 8 50; sleep 1 logger -t backup_installer "Removed the backupscript" else echo "100" | dialog --backtitle "$backtitle_uninstall" --title "$title" --gauge "\nRemoving backupscript: Failed" 8 50; sleep 1 logger -t backup_installer "Could not remove the backupscript" fi dialog --backtitle "$backtitle_uninstall" --title "$title" --msgbox "\nThe backupscript with it's files is now removed.\n\nPlease do not forget to remove the cronjob with the following command:\n\"crontab -e\"" 11 60 logger -t backup_installer "Backupscript uninstalled, please remove the cronjob manually via \"crontab -e\"" clear ;; 1) logger -t backup_installer "User aborted the uninstall procedure" clear ;; esac logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit ;; 5) logger -t backup_installer "Started the upgrade procedure" genday while [ $genday = 0 ]; do genday done if ! [[ -f /etc/backups/xlsbackup.conf || -f /etc/cloudvps/backup.conf ]]; then dialog --backtitle "$backtitle_upgrade" --title "$title" --msgbox "\nYou are using an too old version of the backupscript or do not have it installed yet.\n\nPlease remove any old scripts and instances and start the installer." 10 60 logger -t backup_installer "Upgrade stalled, the script is either not installed or too old to be upgraded" clear exit fi dialog --backtitle "$backtitle_upgrade" --title "$title" --yesno "\nDo you want to check for updates?" 7 50 search=$? case $search in 0) # Get current installed version: if [ -f /usr/local/bin/xlsbackup ]; then version=$(cat /usr/local/bin/xlsbackup | grep "VERSION=" | cut -d = -f 2 | sed 's/"//g') versionstripped=$(echo $version | sed 's/\.//g') elif [ -f /etc/cloudvps/backup.conf ]; then version=$(cat /etc/cloudvps/backup.conf | grep "VERSION=" | cut -d = -f 2 | sed 's/"//g') versionstripped=$(echo $version | sed 's/\.//g') else version="1.0.0" versionstripped=100 fi # Get remote version: newversion=$(curl -s http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt | grep "VERSION=" | cut -d = -f 2 | sed 's/"//g' | head -1) newversionstripped=$(echo $newversion | sed 's/\.//g') if [[ $versionstripped -eq $newversionstripped || $versionstripped -gt $newversionstripped ]]; then dialog --backtitle "$backtitle_upgrade" --title "$title" --msgbox "\nThe installed version $version is up-to-date.\n\nWill now exit." 9 60 logger -t backup_installer "Upgrade not needed, is alreadu up-to-date with version $version" clear exit elif [[ $versionstripped < $newversionstripped ]]; then echo "$log Upgrade from version $version to version $newversion found" >> /var/log/backups/backup.log dialog --backtitle "$backtitle_upgrade" --title "$title" --yesno "\nThere is an update available!\n\nYou have version $version installed and available is version $newversion.\n\nBefore upgrading, do you want to see the changelog?" 12 60 agree=$? if [ $agree = 0 ]; then curl -f -s -o /root/changelog-backupscript http://download.cloudvps.com/pub/files/scripts/backup/changelog-backupscript.txt > /dev/null 2>&1 dialog --backtitle "$backtitle_upgrade" --title "$title" --textbox "/root/changelog-backupscript" 20 95 rm /root/changelog-backupscript > /dev/null 2>&1 fi dialog --backtitle "$backtitle_upgrade" --title "$title" --yesno "\nDo you want to upgrade to version $newversion?" 7 60 agree=$? case $agree in 0) logger -t backup_installer "Starting upgrade from version $version to version $newversion" # If the configfile is CloudVPS: if [ -f /etc/cloudvps/backup.conf ]; then if [ -z $PATCHED ]; then echo "0" | --backtitle "$backtitle_upgrade" --title "$title" --gauge "\nDownloading and starting the patcher script" 8 60 if curl -f -s -o /root/cloudvps-backup-patch http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-patch.txt then logger -t backup_installer "Downloading and executing patcher script" chmod +x /root/cloudvps-backup-patch > /dev/null 2>&1 /root/cloudvps-backup-patch --graphical chattr -i /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/VERSION=\"$version\"/VERSION=\"$newversion\"/" /etc/cloudvps/backup.conf > /dev/null 2>&1 chattr +i /etc/cloudvps/backup.conf echo "100" | dialog --backtitle "$backtitle_upgrade" --title "$title" --gauge "\nUpgrade was successful!" 8 60 elif [ $? = 22 ]; then dialog --backtitle "$backtitle_upgrade" --title "$title" --msgbox "\nUpdating of the script failed.\n\nCould not download and execute the patch script.\n\nPlease try it manually." 11 60 logger -t backup_installer "Upgrade failed, could not download the patch script" clear exit fi else # This place will be used for future updates, this currently is not used or necessary: dialog --backtitle "$backtitle_upgrade" --title "$title" --msgbox "\nNo updates are available at the moment!\n\nVersion $VERSION is installed and up-to-date!" 9 60 logger -t backup_installer "No update available, version $VERSION is up-to-date" exit fi elif [ -f /etc/backups/xlsbackup.conf ]; then if [ $versionstripped = 16 ]; then genday while [ $genday = 0 ]; do genday done echo "9" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nMoving old configfile into place" 8 60; sleep 0.25 if [ -f /etc/backups/xlsbackup.conf ]; then if mkdir -p /etc/cloudvps/ > /dev/null 2>&1; chattr -i /etc/backups/xlsbackup.conf > /dev/null 2>&1; mv /etc/backups/xlsbackup.conf /etc/cloudvps/backup.conf > /dev/null 2>&1; rm -rf /etc/backups/ > /dev/null 2>&1 then echo "18" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nMoved old configfile into place" 8 60; sleep 0.25 logger -t backup_installer "Moved old configfile into new /etc/cloudvps/ directory" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nCould not move old configfile into place!\n\nPlease check the current config dir:\n/etc/backups/\n\nWill now exit!" 12 60 logger -t backup_installer "Could not move old configfile into new /etc/cloudvps/ directory, please check /etc/backups/" clear exit fi fi echo "27" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nPatching configfile" 8 60; sleep 0.25 # Load the configuration variables source /etc/cloudvps/backup.conf # Update version number in configfile if [[ $versionstripped < 200 ]]; then echo "VERSION=\"$newversion\"" >> /etc/cloudvps/backup.conf else perl -pi -w -e "s/VERSION=\"$version\"/VERSION=\"$newversion\"/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi # Patches for some old configfiles if [[ "$MYSQLBACKUPDIR" == "/var/sqlbackups" ]]; then perl -pi -w -e "s/MYSQLBACKUPDIR=\/var\/sqlbackups/MYSQLBACKUPDIR=\/var\/sqlbackups\//" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi if [[ $MYSQLBACKUP == 1 ]]; then perl -pi -w -e "s/MYSQLBACKUP=1/MYSQLBACKUP=N/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi if [[ $MYSQLBACKUP == 0 ]]; then perl -pi -w -e "s/MYSQLBACKUP=0/MYSQLBACKUP=Y/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi if [ -z $UPDATECHECK ]; then echo -e "UPDATECHECK=$day" >> /etc/cloudvps/backup.conf fi if [ -z $NOTIFICATIONS ]; then echo -e "NOTIFICATIONS=Y" >> /etc/cloudvps/backup.conf fi if [ -z $MAILLOG ]; then echo -e "MAILLOG=N" >> /etc/cloudvps/backup.conf fi if [ -z $LOGGING ]; then echo -e "LOGGING=Y" >> /etc/cloudvps/backup.conf fi if [ -z $AUTOUPDATE ]; then echo -e "AUTOUPDATE=Y" >> /etc/cloudvps/backup.conf fi if [ -d /usr/local/directadmin ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then source /usr/local/directadmin/conf/mysql.conf perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$user/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$passwd/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi elif [ -d /usr/local/cpanel ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER="root" MYSQLPASS="" perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$MYSQLUSER/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$MYSQLPASS/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi elif [ -d /usr/local/psa ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER="admin" MYSQLPASS=$(cat /etc/psa/.psa.shadow) perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$MYSQLUSER/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$MYSQLPASS/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi elif [ -d /var/openpanel ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER=$(grep ^user < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') MYSQLPASS=$(grep ^password < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$MYSQLUSER/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$MYSQLPASS/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi elif [ -f /usr/local/ispconfig/server/lib/mysql_clientdb.conf ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER=$(grep user < /usr/local/ispconfig/server/lib/mysql_clientdb.conf | awk '{print $3'} | sed "s/[';]//g") MYSQLPASS=$(grep password < /usr/local/ispconfig/server/lib/mysql_clientdb.conf | awk '{print $3'} | sed "s/[';]//g") perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$MYSQLUSER/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$MYSQLPASS/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi elif [ -f /etc/mysql/debian.cnf ]; then if [[ "$MYSQLBACKUP" == "Y" || "$MYSQLBACKUP" == 0 ]]; then if [ -z $MYSQLUSER ]; then MYSQLUSER=$(grep ^user < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') MYSQLPASS=$(grep ^password < /etc/mysql/debian.cnf | head -1 | awk '{print $3}') perl -pi -w -e "s/MYSQLUSER=/MYSQLUSER=$MYSQLUSER/" /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/MYSQLPASS=/MYSQLPASS=$MYSQLPASS/" /etc/cloudvps/backup.conf > /dev/null 2>&1 fi fi fi echo "36" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nPatched configfile" 8 60; sleep 0.25 logger -t backup_installer "Patched configfile /etc/cloudvps/backup.conf" echo "45" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nRemoving old backupscript" 8 60; sleep 0.25 # If old script exists, remove it and create a symlink: if [ -f /usr/local/bin/xlsbackup ]; then if rm -f /usr/local/bin/xlsbackup > /dev/null 2>&1 then echo "54" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nRemoved old backupscript" 8 60; sleep 0.25 logger -t backup_installer "Removed old XLS backupscript" else echo "54" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nCould not remove old backupscript" 8 60; sleep 0.25 logger -t backup_installer "Could not remove old XLS backupscript" fi echo "63" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nDownloading new backupscript" 8 60; sleep 0.25 if curl -f -s -o /usr/local/bin/cloudvpsbackup http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-script.txt then echo "72" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nDownloaded new backupscript" 8 60; sleep 0.25 logger -t backup_installer "Downloaded new backupscript" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nCould not download new backupscript!\n\nPlease check your network settings.\n\nInstallation halted." 11 60 logger -t backup_installer "Failed downloading new backupscript" clear exit fi echo "81" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nCreating symlink for old XLS script" 8 60; sleep 0.25 if ln -s /usr/local/bin/cloudvpsbackup /usr/local/bin/xlsbackup > /dev/null 2>&1 then echo "90" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nCreated symlink for old XLS script" 8 60; sleep 0.25 logger -t backup_installer "Created symlink for old to new backupscript" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nCould not create symlink!\nUpgrade cannot be finished, the symlink needs to be created for the cronjobs to function properly!\n\nWill now exit..." 11 60 logger -t backup_installer "Could not create symlink for old to new backupscript" clear exit fi echo "95" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nSetting executive permission on backupscript" 8 60; sleep 0.25 if chmod +x /usr/local/bin/cloudvpsbackup > /dev/null 2>&1 then echo "100" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nSet executive permission on backupscript" 8 60; sleep 0.25 logger -t backup_installer "Set executive permission on new backupscript" else echo "100" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nCould not set permissions on backupscript" 8 60; sleep 0.25 logger -t backup_installer "Could not set executive permission on new backupscript" fi fi # # Upgrade from 1.6 to 2.0 config complete, now continue patching to 2.1: echo "100" | dialog --backtitle "$backtitle_upgrade" --title "$title" --gauge "\nContinuing patch to 2.1 in 3 seconds, this will reset the progress bar!" 8 60; sleep 3 if curl -f -s -o /root/cloudvps-backup-patch http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-patch.txt then logger -t backup_installer "Downloading and executing patcher script" chmod +x /root/cloudvps-backup-patch > /dev/null 2>&1 /root/cloudvps-backup-patch --graphical chattr -i /etc/cloudvps/backup.conf > /dev/null 2>&1 perl -pi -w -e "s/VERSION=\"$version\"/VERSION=\"$newversion\"/" /etc/cloudvps/backup.conf > /dev/null 2>&1 chattr +i /etc/cloudvps/backup.conf dialog --backtitle "$backtitle_upgrade" --title "$title" --msgbox "\nUpgrade was successful!" 7 60 logger -t backup_installer "Upgrade from version 1.6 to version $newversion was successful" clear exit elif [ $? = 22 ]; then dialog --backtitle "$backtitle_upgrade" --title "$title" --msgbox "\nUpdating of the script failed.\n\nCould not download and execute the patch script.\n\nPlease try it manually." 11 60 logger -t backup_installer "Upgrade failed, could not download the patch script" clear exit fi else echo -e "Unsupported version found (< 1.6). Exiting..." exit fi else echo -e "Unsupported version found. Exiting..." fi ;; 1) clear logger -t backup_installer "Upgrade aborted by user" exit ;; esac fi ;; 1) clear logger -t backup_installer "Upgrade aborted by user" exit ;; esac ;; 6) logger -t backup_installer "Started the testing suite" clear dialog --backtitle "$backtitle_test" --title "$title" --yesno "\nDo you want to run the test suite, testing the backup options given?" 8 60 agree=$? case $agree in 0) source /etc/cloudvps/backup.conf ssh -i $PRIVKEY $BUSER@$BSERVER quota > ./quota 2> ./quota ssh=$? if [ $ssh = 0 ]; then sshcheck="OK" logger -t backup_installer "SSH is OK" elif [ $ssh = 127 ]; then sshcheck="OK, but no quota available" logger -t backup_installer "SSH is OK, but no quota is available" else sshcheck="Not OK" logger -t backup_installer "SSH is not OK, please check the network settings" fi if [[ $BSERVER == backup-*.xlshosting.nl || $BSERVER == backup-*.cloudvps.* ]] then currentsize=$(df -hT --exclude-type="tmpfs" --exclude-type="devtmpfs" --block-size=G | grep "/" | awk '{print $4}' | tr -d G | head -1) accsize=$(cat quota | grep / | awk '{print $1}' | tail -1 | sed 's/G//') accinuse=$(cat quota | grep / | awk '{print $2}' | tail -1) accinusepercent=$(cat quota | grep / | awk '{print $4}' | tail -1) accfree=$(cat quota | grep / | awk '{print $3}' | tail -1) # Calculate space needed by retention and see if it fits: basespace=$(echo $currentsize*2 | bc) extraspace=$(echo $WEKEN*$currentsize+$MAANDEN*$currentsize | bc) totalspace=$(echo $basespace+$extraspace | bc) if [ $totalspace -gt $accsize ]; then spacecheck="Not OK (Need $totalspace GB, have $accsize GB)" logger -t backup_installer "Backupspace is not OK, have $accsize GB, but need $totalspace GB" else spacecheck="OK (Need $totalspace GB, have $accsize GB)" logger -t backup_installer "Backupspace is OK, have $accsize GB and need $totalspace GB" fi else spacecheck="Not available" logger -t backup_installer "Backupspace check is not available (non-CloudVPS server)" fi if [ $MYSQLBACKUP = "Y" ]; then if [ -d /usr/local/cpanel/ ]; then if echo exit | mysql -u $MYSQLUSER > /dev/null 2>&1 then mysqlcheck="OK" logger -t backup_installer "MySQL connection was succesfull" else mysqlcheck="Not OK" logger -t backup_installer "MySQL connection was unsuccesfull" fi else if echo exit | mysql -u $MYSQLUSER -p$MYSQLPASS > /dev/null 2>&1 then mysqlcheck="OK" logger -t backup_installer "MySQL connection was succesfull" else mysqlcheck="Not OK" logger -t backup_installer "MySQL connection was unsuccesfull" fi fi else mysqlcheck="Not enabled" logger -t backup_installer "MySQL dumps are disabled and cannot be tested" fi # Create report: dialog --backtitle "$backtitle_test" --title "$title" --msgbox "\nBelow are the test results:\n\nSSH............: $sshcheck\nQuota fits.....: $spacecheck\nMySQL..........: $mysqlcheck" 12 60 logger -t backup_installer "Used testsuite: SSH = $sshcheck. Spacecheck = $spacecheck. MySQL = $mysqlcheck." clear ;; 1) clear ;; esac logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit ;; 7) logger -t backup_installer "Started the quota calculator" clear # Get current space and round it: currentsize=$(df -hT --exclude-type="tmpfs" --exclude-type="devtmpfs" --block-size=G | grep "/" | awk '{print $4}' | tr -d G | head -1) dialog --backtitle "$backtitle_quotacalc" --title "$title" --msgbox "\nWith this tool you can calculate the amount of space needed for your backups based on the given retention.\nIf the configfile already exists, it will use these settings and else you may enter it yourself.\n\nPlease note that the given quota is a recommendation." 12 60 if [ -f /etc/cloudvps/backup.conf ]; then source /etc/cloudvps/backup.conf dialog --backtitle "$backtitle_quotacalc" --title "$title" --form "\nBelow are the current configuration options:" 11 60 0 \ "Weeks.......:" 1 1 "$WEKEN" 1 15 2 0 \ "Months......:" 2 1 "$MAANDEN" 2 15 2 0 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options `) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi while [ ${#array[@]} -lt 2 ] do dialog --backtitle "$backtitle_quotacalc" --title "$title" --msgbox "\nNot all fields are populated, please check your input!" 7 60 dialog --backtitle "$backtitle_quotacalc" --title "$title" --form "\nBelow are the current configuration options." 8 60 0 \ "Weeks.......:" 1 1 "${array[0]}" 1 15 2 0 \ "Months......:" 2 1 "${array[1]}" 2 15 2 0 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options `) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi done case $choice in 0) if ! [ ${array[0]} = 0 ]; then weekly=$(echo ${array[0]}*$currentsize | bc) else weekly=0 fi if ! [ ${array[1]} = 0 ]; then monthly=$(echo ${array[1]}*$currentsize | bc) else monthly=0 fi totals=$(echo 2*$currentsize+$weekly+$monthly | bc) ;; 1) clear ;; esac echo "$log Quota lookup: ${array[0]} weekly + ${array[1]} monthly backups needs $totals Gb of backupspace" >> /var/log/backups/backup.log logger -t backup_installer "${array[0]} weekly + ${array[1]} monthly backups needs a total space of $totals GB on the backupserver" else dialog --backtitle "$backtitle_quotacalc" --title "$title" --form "\nBelow are the current configuration options." 8 60 0 \ "Weeks.......:" 1 1 "" 1 15 2 0 \ "Months......:" 2 1 "" 2 15 2 0 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options `) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi while [ ${#array[@]} -lt 2 ] do dialog --backtitle "$backtitle_quotacalc" --title "$title" --msgbox "\nNot all fields are populated, please check your input!" 7 60 dialog --backtitle "$backtitle_quotacalc" --title "$title" --form "\nBelow are the current configuration options." 8 60 0 \ "Weeks.......:" 1 1 "${array[0]}" 1 15 2 0 \ "Months......:" 2 1 "${array[1]}" 2 15 2 0 2> /tmp/$pid-options escaper choice=$? array=( `cat /tmp/$pid-options `) if [ -f /tmp/$pid-options ]; then rm -f /tmp/$pid-options > /dev/null 2> /dev/null fi done case $choice in 0) if ! [ ${array[0]} = 0 ]; then weekly=$(echo ${array[0]}*$currentsize | bc) else weekly=0 fi if ! [ ${array[1]} = 0 ]; then monthly=$(echo ${array[1]}*$currentsize | bc) else monthly=0 fi totals=$(echo 2*$currentsize+$weekly+$monthly | bc) ;; 1) clear ;; esac echo "$log Quota lookup: ${array[0]} weekly + ${array[1]} monthly backups needs $totals Gb of backupspace" >> /var/log/backups/backup.log logger -t backup_installer "${array[0]} weekly + ${array[1]} monthly backups needs a total space of $totals GB on the backupserver" fi dialog --backtitle "$backtitle_quotacalc" --title "$title" --msgbox "\nBased on the given retention you need a total of $totals GB of backupspace." 8 60 clear logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit ;; 8) logger -t backup_installer "Started the log cleaning procedure" space=$(du -sch /var/log/backups/ | grep total | awk '{print $1}') dialog --backtitle "$backtitle_clearlogs" --title "$title" --yesno "\nThis will clear all backup logfiles. You will save "$space"B of diskspace.\n\nDo you agree?" 10 60 agree=$? case $agree in 0) echo "50" | dialog --backtitle "$backtitle_clearlogs" --title "$title" --gauge "\nClearing logs: Clearing" 8 50 if rm -rf /var/log/backups/rsync/* > /dev/null 2>&1; rm -rf /var/log/backups/error/* > /dev/null 2>&1; rm -rf /var/log/backups/warn/* > /dev/null 2>&1; rm -rf /var/log/backups/temp/* > /dev/null 2>&1 then echo "100" | dialog --backtitle "$backtitle_clearlogs" --title "$title" --gauge "\nClearing logs: Done" 8 50;sleep 1 dialog --backtitle "$backtitle_clearlogs" --title "$title" --msgbox "\nAll logs are deleted and "$space"B of space is gained." 7 50 logger -t backup_installer "All logs ($logfiles items with a space of "$space"B is removed" clear else dialog --backtitle "$backtitle_clearlogs" --title "$title" --msgbox "\nCould not clear logs.\n\nWill now exit." 9 50 logger -t backup_installer "Could not clear logs" clear fi ;; 1) clear ;; esac logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit ;; 9) logger -t backup_installer "Started the usage procedure" if [ -f /etc/cloudvps/backup.conf]; then source /etc/cloudvps/backup.conf elif [ -f /etc/backups/xlsbackup.conf ]; then source /etc/backups/xlsbackup.conf fi if [[ "$BSERVER" == backup-*.xlshosting.* || "$BSERVER" == backup-*.cloudvps.* ]]; then # Get quota report and save it, then break it into variables: ssh -p $SSHPORT -i $PRIVKEY $BUSER@$BSERVER quota > ./quota 2>&1 accsize=$(cat quota | grep / | awk '{print $1}' | tail -1) if ! [[ $accsize =~ ^[0-9]+$ ]]; then accsize=$(cat quota | grep / | awk '{print $2}' | tail -1) accinuse=$(cat quota | grep / | awk '{print $3}' | tail -1) accinusepercent=$(cat quota | grep / | awk '{print $5}' | tail -1) accfree=$(cat quota | grep / | awk '{print $4}' | tail -1) else accinuse=$(cat quota | grep / | awk '{print $2}' | tail -1) accinusepercent=$(cat quota | grep / | awk '{print $4}' | tail -1) accfree=$(cat quota | grep / | awk '{print $3}' | tail -1) fi dialog --backtitle "$backtitle_quota" --title "$title" --msgbox "\nBelow are the quota details:\n\nServer....: $BSERVER\nUsername..: $BUSER\nSize......: "$accsize"B\nUsage.....: "$accinuse"B ($accinusepercent)\nFree......: "$accfree"B" 13 50 logger -t backup_installer "Quota lookup: $accinuse GB of $accsize GB" clear else dialog --backtitle "$backtitle_quota" --title "$title" --msgbox "\nQuota support is only available for CloudVPS backupservers.\n\nWill now exit." 10 60 logger -t backup_installer "Quota support is not available for $BSERVER as it is not a CloudVPS backupserver" clear fi logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit ;; 10) logger -t backup_installer "Started the recovery procedure" dialog --backtitle "$backtitle_restore" --title "$title" --yesno "\nThis will download and run the CloudVPS restore script.\n\nDo you want to continue?" 10 60 agree=$? case $agree in 0) echo "50" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nDownloading restore script" 8 50 0 if curl -f -s -o /root/cloudvps-backup-restore http://download.cloudvps.com/pub/files/scripts/backup/cloudvps-backup-restore.txt > /dev/null 2> /dev/null; chmod +x /root/cloudvps-backup-restore > /dev/null 2>&1 then echo "100" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nDownload of the restore script succeeded" 8 50 0 logger -t backup_installer "Succesfully downloaded the restorescript" else dialog --backtitle "$backtitle" --title "$title" --msgbox "\nDownload of the script failed!\nPlease check your network settings" 9 60 logger -t backup_installer "Failed to download the restorescript, please check your network setup" clear fi clear /root/cloudvps-backup-restore logger -t backup_installer "Finished using the recovery script" ;; 1) dialog --backtitle "$backtitle_restore" --title "$title" --msgbox "\nYou did not agree, will now exit" 8 50 logger -t backup_installer "User aborted the recovery procedure" clear ;; esac logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit ;; 11) logger -t backup_installer "Started the manual backup procedure" dialog --backtitle "$backtitle_runbackup" --title "$title" --yesno "\nDo you want to run the backupscript now?\n\nAfter the script is finished, it will exit." 9 60 agree=$? case $agree in 0) clear logger -t backup_installer "Started manual run of the backupscript" /usr/local/bin/cloudvpsbackup logger -t backup_installer "Finished manual run of the backupscript" ;; 1) clear exit ;; esac logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit ;; 12) clear logger -t backup_installer "Started the keyfile exchange procedure" if ! [ -f /etc/cloudvps/backup.conf ]; then dialog --backtitle "$backtitle_exchangekey" --title "$title" --msgbox "\nNo configfile found, the test suite cannot be started.\n\nPlease install the backupscript first." 9 50 clear exit fi dialog --backtitle "$backtitle_exchangekey" --title "$title" --msgbox "\nVia this tool it is possible to exchange the SSH key with the backupserver in case this has been lost.\n\nYou will only need the password associated with your backupaccount" 11 60 dialog --backtitle "$backtitle_exchangekey" --title "$title" --insecure --passwordbox "\nPlease enter your password (masked):" 9 50 2> /tmp/$pid-password escaper password=$(cat /tmp/$pid-password; rm /tmp/$pid-password > /dev/null 2>&1) while [ -z $password ]; do dialog --backtitle "$backtitle_exchangekey" --title "$title" --insecure --password "\nPlease enter your password (masked):" 9 50 2> /tmp/$pid-password logger -t backup_installer "Did not entered a password, showing password dialog again" escaper password=$(cat /tmp/$pid-password; rm /tmp/$pid-password > /dev/null 2>&1) done dialog --backtitle "$backtitle_exchangekey" --title "$title" --yesno "\nDo you want to exchange the publickey with the backupserver?" 8 60 exchange=$? case $exchange in 0) source /etc/cloudvps/backup.conf echo "25" | dialog --backtitle "$backtitle_exchangekey" --title "$title" --gauge "\nChecking for keyfile" 8 50; sleep 1 if [ -f "$PRIVKEY" ]; then echo "50" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile found, not generating a new one" 8 50 0; sleep 1 else echo "50" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nGenerating new key" 8 50 0; ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa.cloudvpsbackup > /dev/null 2> /dev/null fi echo "75" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nChecking for keyfile on the backupserver" 8 50 0 if /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oStrictHostKeyChecking=no -oPort=$SSHPORT $BUSER@$BSERVER expect "password:" send "$password\r" expect "sftp>" send "get .ssh/authorized_keys .\r" expect "sftp>" send "quit\r" EOF then if [ -f authorized_keys ] then echo "100" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile found, key added and uploading new keyfile" 8 50 0; cat /root/.ssh/id_rsa.cloudvpsbackup.pub >> authorized_keys; /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oStrictHostKeyChecking=no -oPort=$SSHPORT $BUSER@$BSERVER expect "password:" send "$password\r" expect "sftp>" send "put authorized_keys .ssh/authorized_keys\r" expect "sftp>" send "quit\r" EOF rm authorized_keys > /dev/null 2>&1 logger -t backup_installer "Keyfile found, added new key and uploading new keyfile" else echo "100" | dialog --backtitle "$backtitle" --title "$title" --gauge "\nKeyfile not found, creating and uploading new keyfile" 8 50 0 /usr/bin/expect > /dev/null 2> /dev/null << EOF spawn sftp -oStrictHostKeyChecking=no -oPort=$SSHPORT $BUSER@$BSERVER expect "password:" send "$password\r" expect "sftp>" send "mkdir .ssh\r" expect "sftp>" send "cd .ssh\r" expect "sftp>" send "put /root/.ssh/id_rsa.cloudvpsbackup.pub authorized_keys\r" expect "sftp>" send "quit\r" EOF logger -t backup_installer "Keyfile not found, uploading new keyfile" fi fi dialog --backtitle "$backtitle_exchangekey" --title "$title" --msgbox "\nThe SSH public key is now exchanged with $BSERVER for account $BUSER." 8 60 logger -t backup_installer "Exchanged keyfile for $BUSER on $BSERVER" clear ;; 1) logger -t backup_installer "Did not agree to the key exchange, exiting..." clear ;; esac exit ;; 13) if [ ! -f /etc/cloudvps/recipients.mail ]; then touch /etc/cloudvps/recipients.mail fi dialog --backtitle "$backtitle_mail" --title "$title" --msgbox "\nVia this tool you can add or remove mail recipients which will receive the notifications that the script sends out in case of updates, warnings and errors." 9 60 dialog --backtitle "$backtitle_mail" --title "$title" --yes-label " View list " --no-label " Edit list " --yesno "\nWhat action do you wish to take?\n\nView list = Show the current recipient list\nEdit list = Opens the nano editor and you can add or remove recipients\n" 11 60 if [[ $? == 0 ]]; then dialog --backtitle "$backtitle" --title "$title" --textbox /etc/cloudvps/recipients.mail 10 60 logger -t backup_installer "Viewed mail recipients list" clear else nano=$(which nano) $nano /etc/cloudvps/recipients.mail logger -t backup_installer "Edited mail recipients list" clear fi ;; 14) if [ ! -f /etc/cloudvps/excludes.rsync ]; then touch /etc/cloudvps/excludes.rsync fi dialog --backtitle "$backtitle_excludes" --title "$title" --msgbox "\nVia this tool you can add or remove rsync excludes. Excludes that are on the list will be ignored by rsync during the backup process" 9 60 dialog --backtitle "$backtitle_excludes" --title "$title" --yes-label " View list " --no-label " Edit list " --yesno "\nWhat action do you wish to take?\n\nView list = Show the current rsync exclude list\nEdit list = Opens the nano editor and you can add or remove excludes\n" 11 60 if [[ $? == 0 ]]; then dialog --backtitle "$backtitle_excludes" --title "$title" --textbox /etc/cloudvps/excludes.rsync 10 60 logger -t backup_installer "Viewed the rsync excludes list" clear else nano=$(which nano) $nano /etc/cloudvps/excludes.rsync logger -t backup_installer "Edited the rsync excludes list" clear fi ;; 15) dialog --backtitle "$backtitle_explorer" --title "$title" --msgbox "\nVia this tool it is possible to browse, recover and delete the content on the backupserver.\n\nPlease note that all actions are permanent when you execute them!" 11 60 source /etc/cloudvps/backup.conf if [ -d /mnt/ ]; then if ! mkdir -p /mnt/backup-"$BUSER" then echo -e "Could not create mountpoint, cannot continue!" logger -t backup_installer "Could not create mountpoint" exit fi else echo -e "No /mnt/ directory available, cannot continue!" logger -t backup_installer "No /mnt/ dir available" exit fi if sshfs -o ssh_command="ssh -p $SSHPORT -i $PRIVKEY" "$BUSER"@"$BSERVER":"$REMOTEPATH" /mnt/backup-"$BUSER" > /dev/null 2>&1 then logger -t backup_installer "Successfully mounted the backup account to /mnt/backup-$BUSER" else echo -e "Could not mount the backupaccount to /mnt/backup-$BUSER" logger -t backup_installer "Could not mount the backup account to folder /mnt/backup-$BUSER" exit fi clear mc /mnt/backup-"$BUSER" clear if ! umount /mnt/backup-"$BUSER" > /dev/null 2>&1 then echo -e "Could not unmount backup share, please do so manually:\numount /mnt/backup-$BUSER" logger -t backup_installer "Could not unmount backup share" fi exit ;; esac logger -t backup_installer "Stopped the CloudVPS Backup Installer" exit