vesta/bin/v-schedule-user-restore
2021-10-30 22:26:42 +03:00

72 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# info: schedule user backup restoration
# options: USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIR]
#
# The function for scheduling user backup restoration.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
backup=$2
web=$3
dns=$4
mail=$5
db=$6
cron=$7
udir=$8
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
# Check backup ownership function
is_backup_available() {
passed=false
if [[ $2 =~ ^$1.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9]-[0-9][0-9]-[0-9][0-9].tar$ ]]; then
passed=true
elif [[ $2 =~ ^$1.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].tar$ ]]; then
passed=true
fi
if [ $passed = false ]; then
check_result $E_FORBIDEN "permission denied"
fi
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIR]'
is_format_valid 'user'
is_system_enabled "$BACKUP_SYSTEM" 'BACKUP_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_backup_enabled
is_backup_scheduled 'restore'
is_backup_available "$user" "$backup"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Adding restore task to the queue
log=$VESTA/log/restore.log
options="'$web' '$dns' '$mail' '$db' '$cron' '$udir'"
echo "$BIN/v-restore-user $user $backup $options yes >> $log 2>&1" >>\
$VESTA/data/queue/backup.pipe
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit