mirror of
https://github.com/myvesta/vesta
synced 2025-08-14 18:49:21 -07:00
added upd backup function
This commit is contained in:
parent
add6ebe952
commit
7ba0758c4e
3 changed files with 320 additions and 37 deletions
|
@ -78,6 +78,7 @@ fi
|
|||
# Addding backup and vesta version
|
||||
echo "1.0" > $tmpdir/backup_version
|
||||
echo "$VERSION" > $tmpdir/vesta_version
|
||||
vst='yes'
|
||||
|
||||
# Vesta
|
||||
if [ -z "$output" ]; then
|
||||
|
@ -205,14 +206,14 @@ then
|
|||
echo -e "\t$(date +%H:%M:%S) $domain"
|
||||
fi
|
||||
|
||||
# Building directory tree
|
||||
mkdir -p $tmpdir/web/$domain/conf
|
||||
mkdir -p $tmpdir/web/$domain/ssl
|
||||
|
||||
# Defining domain variables
|
||||
domain_idn=$(idn -t --quiet -a "$domain")
|
||||
tpl_name=$(get_web_domain_value '$TPL')
|
||||
ssl_cert=$(get_web_domain_value '$SSL_CERT')
|
||||
nginx=$(get_web_domain_value '$NGINX')
|
||||
get_web_domain_values
|
||||
|
||||
# Building directory tree
|
||||
mkdir -p $tmpdir/web/$domain/conf $tmpdir/web/$domain/cert
|
||||
|
||||
# Packing data folders
|
||||
cd $V_HOME/$user/web/$domain
|
||||
|
@ -227,14 +228,14 @@ then
|
|||
# Apache config
|
||||
if [ "$WEB_SYSTEM" = 'apache' ]; then
|
||||
# Parsing httpd.conf
|
||||
tpl_file="$V_WEBTPL/apache_$tpl_name.tpl"
|
||||
tpl_file="$V_WEBTPL/apache_$TPL.tpl"
|
||||
conf="$V_HOME/$user/conf/httpd.conf"
|
||||
get_web_config_brds
|
||||
sed -n "$top_line,$bottom_line p" $conf > conf/httpd.conf
|
||||
|
||||
# SSL check
|
||||
if [ ! -z "$ssl_cert" ]; then
|
||||
tpl_file="$V_WEBTPL/apache_$tpl_name.stpl"
|
||||
if [ ! -z "$SSL" ]; then
|
||||
tpl_file="$V_WEBTPL/apache_$TPL.stpl"
|
||||
conf="$V_HOME/$user/conf/shttpd.conf"
|
||||
get_web_config_brds
|
||||
sed -n "$top_line,$bottom_line p" $conf > conf/shttpd.conf
|
||||
|
@ -242,15 +243,15 @@ then
|
|||
fi
|
||||
|
||||
# Nginx config
|
||||
if [ ! -z "$nginx" ] ; then
|
||||
tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.tpl"
|
||||
if [ ! -z "$NGINX" ] ; then
|
||||
tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.tpl"
|
||||
conf="$V_HOME/$user/conf/nginx.conf"
|
||||
get_web_config_brds
|
||||
sed -n "$top_line,$bottom_line p" $conf > conf/nginx.conf
|
||||
|
||||
# SSL check
|
||||
if [ ! -z "$ssl_cert" ] ; then
|
||||
tpl_file="$V_WEBTPL/ngingx_vhost_$nginx.stpl"
|
||||
if [ ! -z "$SSL" ] ; then
|
||||
tpl_file="$V_WEBTPL/ngingx_vhost_$NGINX.stpl"
|
||||
conf="$V_HOME/$user/conf/snginx.conf"
|
||||
get_web_config_brds
|
||||
sed -n "$top_line,$bottom_line p" $conf > conf/snginx.conf
|
||||
|
@ -263,11 +264,11 @@ then
|
|||
done
|
||||
|
||||
# SSL Certificates
|
||||
if [ ! -z "$ssl_cert" ] ; then
|
||||
cp $V_HOME/$user/conf/$ssl_cert.* cert/
|
||||
if [ ! -z "$SSL" ] ; then
|
||||
cp $V_HOME/$user/conf/$SSL.* ssl/
|
||||
fi
|
||||
|
||||
tar -rf $tmpdir/web/$domain/$domain.tar conf cert
|
||||
tar -rf $tmpdir/web/$domain/$domain.tar conf ssl
|
||||
mv $tmpdir/web/$domain/$domain.tar $tmpdir/web/
|
||||
rm -rf $tmpdir/web/$domain
|
||||
|
||||
|
@ -319,7 +320,7 @@ then
|
|||
grep "DOMAIN='$domain'" $conf > dns.conf
|
||||
|
||||
# Backingup dns recods
|
||||
cp $V_USERS/$user/zones/$domain $domain
|
||||
cp $V_USERS/$user/dns/$domain $domain
|
||||
cp /etc/namedb/$domain.db $domain.db
|
||||
done
|
||||
|
||||
|
@ -379,7 +380,6 @@ if [ ! -z "$DB_SYSTEM" ] && [ "$DB_SYSTEM" != 'no' ] && [ "$DB" != '*' ]; then
|
|||
if [ -z "$output" ]; then
|
||||
echo
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Cron jobs
|
||||
|
@ -414,12 +414,12 @@ fi
|
|||
# SSL CERTIFICATES
|
||||
if [ ! -z "$WEB_SSL" ] && [ "$WEB_SSL" != 'no' ] && [ "$SSL" != '*' ]; then
|
||||
if [ -z "$output" ]; then
|
||||
echo "-- CERTIFICATES --"
|
||||
echo "-- SSL --"
|
||||
fi
|
||||
mkdir $tmpdir/cert
|
||||
mkdir $tmpdir/ssl
|
||||
|
||||
# Backingup ssl certificates
|
||||
cert_list=$(ls $V_USERS/$user/cert/ | grep ".crt" |\
|
||||
cert_list=$(ls $V_USERS/$user/ssl/ | grep ".crt" |\
|
||||
sed -e "s/\.crt$//" |\
|
||||
tr '\n' ' ' |\
|
||||
sed -e 's/ $//' )
|
||||
|
@ -427,7 +427,7 @@ if [ ! -z "$WEB_SSL" ] && [ "$WEB_SSL" != 'no' ] && [ "$SSL" != '*' ]; then
|
|||
if [ -z "$output" ]; then
|
||||
echo -e "\t$(date +%H:%M:%S) $cert"
|
||||
fi
|
||||
cp $V_USERS/$user/cert/$cert.* $tmpdir/cert/
|
||||
cp $V_USERS/$user/ssl/$cert.* $tmpdir/ssl/
|
||||
done
|
||||
|
||||
if [ -z "$output" ]; then
|
||||
|
@ -500,7 +500,7 @@ local_backup(){
|
|||
# Defining ftp command function
|
||||
ftpc() {
|
||||
ftp -n $HOST $PORT <<EOF
|
||||
quote USER $USER
|
||||
quote USER $USERNAME
|
||||
quote PASS $PASSWORD
|
||||
binary
|
||||
cd $BPATH
|
||||
|
@ -516,16 +516,9 @@ ftp_backup(){
|
|||
fi
|
||||
|
||||
# Checking config
|
||||
if [ -e "$V_CONF/backup.conf" ]; then
|
||||
ftphost_str=$(grep "TYPE='FTP'" $V_CONF/backup.conf |head -n 1)
|
||||
fi
|
||||
|
||||
# Parsing config values
|
||||
if [ ! -z "$ftphost_str" ]; then
|
||||
for key in $ftphost_str; do
|
||||
eval ${key%%=*}=${key#*=}
|
||||
done
|
||||
else
|
||||
source $V_CONF/ftp.backup.conf
|
||||
if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ] ||\
|
||||
[ -z "$BPATH" ]; then
|
||||
echo "Error: Parsing error"
|
||||
log_event 'debug' "$E_PARSE_ERROR $V_EVENT"
|
||||
exit $E_PARSE_ERROR
|
||||
|
@ -533,7 +526,8 @@ ftp_backup(){
|
|||
|
||||
# Debug info
|
||||
if [ -z "$output" ]; then
|
||||
echo -e "\t$(date +%H:%M:%S) ftp://$USER@$HOST$BPATH/$user.$V_DATE.tar"
|
||||
echo -ne "\t$(date +%H:%M:%S) "
|
||||
echo -e "ftp://$USERNAME@$HOST$BPATH/$user.$V_DATE.tar"
|
||||
fi
|
||||
|
||||
# Checking ftp permission
|
||||
|
@ -592,7 +586,7 @@ done
|
|||
cd /
|
||||
rm -rf $tmpdir
|
||||
|
||||
# Calcilation run time
|
||||
# Calculation run time
|
||||
run_time=$((end_time - start_time))
|
||||
run_time=$((run_time / 60))
|
||||
current_time=$(date +'%H:%M:%S')
|
||||
|
@ -626,11 +620,12 @@ done
|
|||
# Concatenating string
|
||||
backup_str="DATE='$V_DATE' TIME='$current_time' RUNTIME='$run_time'"
|
||||
backup_str="$backup_str TYPE='$BACKUP_SYSTEM' SIZE='$size'"
|
||||
backup_str="$backup_str VESTA='$vst'"
|
||||
backup_str="$backup_str WEB='${web_list// /,}'"
|
||||
backup_str="$backup_str DNS='${dns_list// /,}'"
|
||||
backup_str="$backup_str MAIL='${mail_list// /,}'"
|
||||
backup_str="$backup_str DB='${db_list// /,}'"
|
||||
backup_str="$backup_str CERTIFICATES='${cert_list// /,}'"
|
||||
backup_str="$backup_str SSL='${cert_list// /,}'"
|
||||
backup_str="$backup_str CRON='$cron_list'"
|
||||
echo "$backup_str" >> $V_USERS/$user/backup.conf
|
||||
|
||||
|
|
|
@ -30,20 +30,22 @@ is_user_valid
|
|||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Checking config
|
||||
conf=$V_USERS/$user/backup.conf
|
||||
if [ ! -e "$conf" ]; then
|
||||
touch $conf
|
||||
fi
|
||||
|
||||
# Defining fileds to select
|
||||
fields="\$DATE \$TIME \$RUNTIME \$TYPE \$SIZE \$WEB \$DNS \$DB \$MAIL"
|
||||
fields="\$DATE \$TIME \$RUNTIME \$TYPE \$SIZE \$VESTA \$WEB \$DNS \$DB \$MAIL"
|
||||
fields="$fields \$CERTIFICATES \$CRON"
|
||||
|
||||
# Listing domains
|
||||
case $format in
|
||||
json) json_list ;;
|
||||
plain) nohead=1; shell_list ;;
|
||||
shell) fields='$DATE $TIME $RUNTIME $TYPE $SIZE';shell_list |column -t ;;
|
||||
shell) fields='$DATE $TIME $RUNTIME $TYPE $SIZE'; shell_list |column -t;;
|
||||
*) check_args '1' '0' '[format]' ;;
|
||||
esac
|
||||
|
||||
|
|
286
bin/v_upd_sys_user_backups
Executable file
286
bin/v_upd_sys_user_backups
Executable file
|
@ -0,0 +1,286 @@
|
|||
#!/bin/bash
|
||||
# info: updating current backups for
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Importing variables
|
||||
source $VESTA/conf/vars.conf
|
||||
source $V_CONF/vesta.conf
|
||||
source $V_FUNC/shared.func
|
||||
|
||||
# Argument defenition
|
||||
user=$1
|
||||
type="${2-$BACKUP_SYSTEM}"
|
||||
|
||||
# Defining tar parser function
|
||||
get_backup_info() {
|
||||
backup=$1 # full path to backup
|
||||
backup_type="$2" # backup type
|
||||
|
||||
backup_name=$(basename $backup )
|
||||
backup_date=$(echo $backup_name |cut -f 2 -d '.' )
|
||||
backup_time=$(stat --printf=%y $backup |cut -f 2 -d ' ' |cut -f 1 -d '.')
|
||||
backup_size=$(du -sm $backup |cut -f 1 )
|
||||
backup_data=$(tar -tf $backup)
|
||||
|
||||
# Checking system data
|
||||
vst_data=$(echo "$backup_data" |grep "^./vesta/" |grep -v "^./vesta/$")
|
||||
if [ -z "$vst_data" ]; then
|
||||
vst=''
|
||||
else
|
||||
vst='yes'
|
||||
fi
|
||||
|
||||
# Checking web data
|
||||
web_data=$(echo "$backup_data" |grep "^./web/" |grep -v "^./web/$" |sort)
|
||||
if [ -z "$web_data" ]; then
|
||||
web=''
|
||||
else
|
||||
i=1
|
||||
for domain in $web_data; do
|
||||
domain="$(basename $domain|sed -e 's/.tar.gz$//')"
|
||||
if [ "$i" -eq 1 ]; then
|
||||
web="$domain"
|
||||
i=2
|
||||
else
|
||||
web="$web,$domain"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Checking dns data
|
||||
dns_data=$(echo "$backup_data" |grep "^./dns/" |grep ".db$" |sort)
|
||||
if [ -z "$dns_data" ]; then
|
||||
dns=''
|
||||
else
|
||||
i=1
|
||||
for domain in $dns_data; do
|
||||
domain="$(basename $domain|sed -e 's/.db$//')"
|
||||
if [ "$i" -eq 1 ]; then
|
||||
dns="$domain"
|
||||
i=2
|
||||
else
|
||||
dns="$dns,$domain"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Checking mail
|
||||
mail_data=$(echo "$backup_data"|grep "^./mail/"|grep -v "^./mail/$"|sort)
|
||||
if [ -z "$mail_data" ]; then
|
||||
ml=''
|
||||
else
|
||||
i=1
|
||||
for domain in $mail_data; do
|
||||
domain="$(basename $domain|sed -e 's/.tar.gz$//')"
|
||||
if [ "$i" -eq 1 ]; then
|
||||
ml="$domain"
|
||||
i=2
|
||||
else
|
||||
ml="$ml,$domain"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Checking databases
|
||||
db_data=$(echo "$backup_data"|grep "^./db/"|grep ".sql.gz$"|sort)
|
||||
if [ -z "$db_data" ]; then
|
||||
db=''
|
||||
else
|
||||
i=1
|
||||
for dbase in $db_data; do
|
||||
dbase=$(basename $dbase|sed -e "s/.\(my\|pg\)sql.sql.gz$//")
|
||||
if [ "$i" -eq 1 ]; then
|
||||
db="$dbase"
|
||||
i=2
|
||||
else
|
||||
db="$db,$dbase"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Checking certificates
|
||||
ssl_data=$(echo "$backup_data"|grep "^./ssl/"|grep ".crt$"|sort)
|
||||
if [ -z "$ssl_data" ]; then
|
||||
ssl=''
|
||||
else
|
||||
i=1
|
||||
for certificate in $ssl_data; do
|
||||
certificate="$(basename $certificate|sed -e "s/.crt$//")"
|
||||
if [ "$i" -eq 1 ]; then
|
||||
ssl="$certificate"
|
||||
i=2
|
||||
else
|
||||
ssl="$ssl,$certificate"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Checking cron data
|
||||
cron_data=$(echo "$backup_data" |grep "^./cron/" |grep -v "^./cron/$")
|
||||
if [ -z "$cron_data" ]; then
|
||||
cron=''
|
||||
else
|
||||
cron='yes'
|
||||
fi
|
||||
|
||||
str="DATE='$backup_date' TIME='$backup_time' RUNTIME='0'"
|
||||
str="$str SIZE='$backup_size' TYPE='$backup_type' VESTA='$vst' WEB='$web'"
|
||||
str="$str DNS='$dns' MAIL='$ml' DB='$db' SSL='$ssl' CRON='$cron'"
|
||||
|
||||
echo "$str"
|
||||
}
|
||||
|
||||
# Defining ftp command function
|
||||
ftpc() {
|
||||
ftp -n $HOST $PORT <<EOF
|
||||
quote USER $USERNAME
|
||||
quote PASS $PASSWORD
|
||||
binary
|
||||
cd $BPATH
|
||||
$1
|
||||
quit
|
||||
EOF
|
||||
}
|
||||
|
||||
init_ftp_variables() {
|
||||
# Checking config
|
||||
source $V_CONF/ftp.backup.conf
|
||||
if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ] ||\
|
||||
[ -z "$BPATH" ]; then
|
||||
echo "Error: Parsing error"
|
||||
log_event 'debug' "$E_PARSE_ERROR $V_EVENT"
|
||||
exit $E_PARSE_ERROR
|
||||
fi
|
||||
}
|
||||
|
||||
check_ftp_connection(){
|
||||
# Checking ftp permission
|
||||
ftmpdir=$(mktemp -u -p $BPATH)
|
||||
command="mkdir $ftmpdir
|
||||
ls $ftmpdir
|
||||
rm $ftmpdir"
|
||||
if [ ! -z "$(ftpc "$command")" ] ; then
|
||||
echo "Error: FTP error"
|
||||
log_event 'debug' "$E_FTP_ERROR $V_EVENT"
|
||||
exit $E_FTP_ERROR
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Checking arg number
|
||||
check_args '1' "$#" 'user'
|
||||
|
||||
# Checking backup system is enabled
|
||||
is_system_enabled 'backup'
|
||||
|
||||
# Checking argument format
|
||||
format_validation 'user'
|
||||
|
||||
# Checking user
|
||||
is_user_valid
|
||||
|
||||
# Checking load averages
|
||||
la=$(cat /proc/loadavg |cut -f 1 -d ' '|cut -f 1 -d '.')
|
||||
if [ "$la" -ge "$V_BACKUP_LA_LIMIT" ]; then
|
||||
log_event 'debug' "$E_LOAD_AVERAGE $V_EVENT"
|
||||
exit $E_LOAD_AVERAGE
|
||||
fi
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Checking tmp file
|
||||
tmp_file="$V_USERS/$user/backup.conf_tmp"
|
||||
if [ -e "$tmp_file" ]; then
|
||||
rm -f $tmp_file
|
||||
fi
|
||||
|
||||
# Checking local
|
||||
if [ "$type" == 'local' ]; then
|
||||
backups=$(ls $V_BACKUP |grep "^$user."|sort)
|
||||
for backup in $backups; do
|
||||
get_backup_info $V_BACKUP/$backup $type >> $tmp_file
|
||||
done
|
||||
fi
|
||||
|
||||
# Checking ftp
|
||||
if [ "$type" == 'ftp' ]; then
|
||||
tmpdir=$(mktemp -p $V_TMP -d)
|
||||
ftmpdir=$(basename $tmpdir)
|
||||
init_ftp_variables
|
||||
check_ftp_connection
|
||||
backups=$(ftpc ls|awk '{print $9}'|grep "^$user.")
|
||||
|
||||
for backup in $backups; do
|
||||
cd $tmpdir
|
||||
if [ ! -z "$(ftpc "get $backup")" ]; then
|
||||
echo "Error: FTP transfer error"
|
||||
log_event 'debug' "$E_FTP_ERROR $V_EVENT"
|
||||
exit $E_FTP_ERROR
|
||||
fi
|
||||
get_backup_info $tmpdir/$backup $type >> $tmp_file
|
||||
rm -f $tmpdir/$backup
|
||||
done
|
||||
rm -rf $tmpdir
|
||||
fi
|
||||
|
||||
# Checking both local and ftp
|
||||
if [ "$type" == 'ftp,local' ] || [ "$type" == 'local,ftp' ]; then
|
||||
|
||||
tmpdir=$(mktemp -p $V_TMP -d)
|
||||
ftmpdir=$(basename $tmpdir)
|
||||
init_ftp_variables
|
||||
check_ftp_connection
|
||||
ftp_backups=$(ftpc ls|awk '{print $9}'|grep "^$user.")
|
||||
local_backups=$(ls $V_BACKUP/ |grep "^$user." |sort)
|
||||
backups=$(echo -e "$local_backups\n$ftp_backups" |\
|
||||
sort |uniq -c | awk '{print $1" "$2}')
|
||||
|
||||
for backup in $(echo "$backups"|grep "^1 "|cut -f 2 -d ' '); do
|
||||
check_ftp=$(echo $ftp_backups|grep -w $backup)
|
||||
if [ ! -z "$check_ftp" ]; then
|
||||
cd $tmpdir
|
||||
if [ ! -z "$(ftpc "get $backup")" ]; then
|
||||
echo "Error: FTP transfer error"
|
||||
log_event 'debug' "$E_FTP_ERROR $V_EVENT"
|
||||
exit $E_FTP_ERROR
|
||||
fi
|
||||
get_backup_info $tmpdir/$backup ftp >> $tmp_file
|
||||
rm -f $tmpdir/$backup
|
||||
else
|
||||
get_backup_info $V_BACKUP/$backup local >> $tmp_file
|
||||
fi
|
||||
done
|
||||
|
||||
for backup in $(echo "$backups"|grep "^2 "|cut -f 2 -d ' '); do
|
||||
get_backup_info $V_BACKUP/$backup $type >> $tmp_file
|
||||
done
|
||||
rm -rf $tmpdir
|
||||
fi
|
||||
|
||||
# Checking if there was any output
|
||||
if [ -e "$tmp_file" ]; then
|
||||
cat $tmp_file | sort > $V_USERS/$user/backup.conf
|
||||
rm $tmp_file
|
||||
fi
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Logging
|
||||
log_event 'system' "$V_EVENT"
|
||||
|
||||
exit
|
Loading…
Add table
Add a link
Reference in a new issue