mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-21 05:44:07 -07:00
tools for ftp backup
This commit is contained in:
parent
a52993fe40
commit
c2ccccf142
3 changed files with 227 additions and 0 deletions
95
bin/v-add-backup-ftp-host
Executable file
95
bin/v-add-backup-ftp-host
Executable file
|
@ -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 <<EOF
|
||||
quote USER $ftp_user
|
||||
quote PASS $ftp_password
|
||||
binary
|
||||
$1
|
||||
$2
|
||||
$3
|
||||
quit
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '3' "$#" "HOST USERNAME PASSWORD [PATH]"
|
||||
validate_format 'host' 'ftp_user' 'ftp_password'
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Checking network connection
|
||||
if [ ! -z "$(ftpc)" ]; then
|
||||
echo "Error: can't login to ftp"
|
||||
log_event "$E_FTP" "$EVENT"
|
||||
exit $E_FTP
|
||||
fi
|
||||
|
||||
# Checking write permissions
|
||||
ftpc "mkdir $ftp_path" > /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
|
45
bin/v-delete-backup-ftp-host
Executable file
45
bin/v-delete-backup-ftp-host
Executable file
|
@ -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
|
87
bin/v-list-backup-ftp-host
Executable file
87
bin/v-list-backup-ftp-host
Executable file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue