diff --git a/bin/v-add-backup-ftp-host b/bin/v-add-backup-ftp-host new file mode 100755 index 000000000..2c7218b6e --- /dev/null +++ b/bin/v-add-backup-ftp-host @@ -0,0 +1,95 @@ +#!/bin/bash +# info: add backup ftp host +# options: HOST USERNAME PASSWORD [PATH] +# +# The function adds ftp host for system backups + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +host=$1 +ftp_user=$2 +ftp_password=$3 +ftp_path=${4-/backup} +A3='******' + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/main.sh + +# Defining ftp command function +ftpc() { + ftp -n $host < /dev/null 2>&1 +ftmpdir=$(mktemp -u -p "$ftp_path") +ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir") +if [ ! -z "$ftp_result" ] ; then + rm -rf $tmpdir + echo "Error: can't create temp folder on the ftp" + log_event "$E_FTP" "$EVENT" + exit $E_FTP +fi + +# Adding backup host +echo "HOST='$host' +USERNAME='$ftp_user' +PASSWORD='$ftp_password' +TIME='$TIME' +DATE='$DATE'" > $VESTA/conf/ftp.backup.conf +chmod 660 $VESTA/conf/ftp.backup.conf + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Update vesta.conf +if [ -z "$(grep LANGUAGE $VESTA/conf/vesta.conf)" ]; then + echo "BACKUP_SYSTEM='ftp'" >> $VESTA/conf/vesta.conf +else + bckp=$(echo "$BACKUP_SYSTEM,ftp" |\ + sed -e "s/,/\n/g"|\ + sort -r -u |\ + sed -e "/^$/d"|\ + sed -e ':a;N;$!ba;s/\n/,/g') + sed -i "s/BACKUP_SYSTEM=.*/BACKUP_SYSTEM='$bckp'/g" $VESTA/conf/vesta.conf +fi + +# Logging +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v-delete-backup-ftp-host b/bin/v-delete-backup-ftp-host new file mode 100755 index 000000000..0e92e26e1 --- /dev/null +++ b/bin/v-delete-backup-ftp-host @@ -0,0 +1,45 @@ +#!/bin/bash +# info: delete backup ftp server +# options: NONE +# +# The function deletes ftp backup host + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Checking network connection +rm -f $VESTA/conf/ftp.backup.conf + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Update vesta.conf +bckp=$(echo "$BACKUP_SYSTEM" |\ + sed -e "s/,/\n/g"|\ + sed -e "s/ftp//" |\ + sed -e "/^$/d"|\ + sed -e ':a;N;$!ba;s/\n/,/g') +sed -i "s/BACKUP_SYSTEM=.*/BACKUP_SYSTEM='$bckp'/g" $VESTA/conf/vesta.conf + +# Logging +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v-list-backup-ftp-host b/bin/v-list-backup-ftp-host new file mode 100755 index 000000000..066d07078 --- /dev/null +++ b/bin/v-list-backup-ftp-host @@ -0,0 +1,87 @@ +#!/bin/bash +# info: list backup host +# options: [FORMAT] +# +# The function for obtaining the list of back fto host. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +format=${1-shell} + +# Includes +source $VESTA/func/main.sh + +# Json function +json_list_ftp_host() { + i=1 + fileds_count=$(echo "$fields" | wc -w) + ip_data=$(cat $VESTA/conf/ftp.backup.conf) + echo '{' + eval $ip_data + for field in $fields; do + eval value=$field + if [ $i -eq 1 ]; then + echo -e "\t\"$value\": {" + else + if [ $fileds_count -eq $i ]; then + echo -e "\t\t\"${field//$/}\": \"${value//,/, }\"" + else + echo -e "\t\t\"${field//$/}\": \"${value//,/, }\"," + fi + fi + (( ++i)) + done + if [ -n "$value" ]; then + echo -e ' }' + fi + echo -e '}' +} + +# Shell function +shell_list_ftp_host() { + line=$(cat $VESTA/conf/ftp.backup.conf) + eval $line + for field in $fields; do + eval key="$field" + if [ -z "$key" ]; then + key='NULL' + fi + echo "${field//$/}: $key " + done +} + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +if [ ! -e "$VESTA/conf/ftp.backup.conf" ]; then + exit +fi + +# Defining fileds to select +fields='$HOST $USERNAME $TIME $DATE' + +# Listing database +case $format in + json) json_list_ftp_host ;; + plain) nohead=1; shell_list_ftp_host;; + shell) shell_list_ftp_host | column -t ;; + *) check_args '2' '0' '[FORMAT]' +esac + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit