Skip to content

Commit 65db511

Browse files
committed
backup restoration 90% completed
1 parent 1155e90 commit 65db511

File tree

16 files changed

+317
-86
lines changed

16 files changed

+317
-86
lines changed

bin/v-backup-user

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ then
402402
cron_record=$(wc -l $USER_DATA/cron.conf|cut -f 1 -d ' ')
403403

404404
if [ -e "/var/spool/cron/$user" ]; then
405-
cron_list='yes'
405+
cron_list="$cron_record"
406406
cp /var/spool/cron/$user $tmpdir/cron/
407407
fi
408408
if [ "$cron_record" -eq 1 ]; then
@@ -417,22 +417,28 @@ then
417417
fi
418418

419419
# User Directories
420-
echo "-- User Directories --"
421-
msg="$msg\n-- User Directories --"
422-
mkdir $tmpdir/user_dirs
423-
user_dirs=$(ls $HOMEDIR/$user | \
420+
echo "-- User Dir --"
421+
msg="$msg\n-- User Dir --"
422+
mkdir $tmpdir/user_dir
423+
user_dir=$(ls $HOMEDIR/$user | \
424424
grep -v conf | \
425425
grep -v web | \
426426
grep -v dns | \
427427
grep -v mail | \
428428
grep -v tmp)
429429
i=0
430-
for user_dir in $user_dirs; do
430+
for udir in $user_dir; do
431+
udir_list="$udir_list $udir"
431432
((i ++))
432-
echo -e "$(date "+%F %T") $user_dir"
433-
msg="$msg\n$(date "+%F %T") $user_dir"
434-
cp -pr $HOMEDIR/$user/$user_dir $tmpdir/user_dirs/
433+
echo -e "$(date "+%F %T") $udir"
434+
msg="$msg\n$(date "+%F %T") $udir"
435+
cp -pr $HOMEDIR/$user/$udir $tmpdir/user_dir/
436+
cd $tmpdir/user_dir/
437+
tar -czpf $udir.tar.gz $udir
438+
rm -rf $udir
435439
done
440+
udir_list=$(echo "$udir_list" | sed -e "s/ */\ /g" -e "s/^ //")
441+
436442
if [ "$i" -eq 1 ]; then
437443
echo -e "$(date "+%F %T") $i user directory"
438444
msg="$msg\n$(date "+%F %T") $i directory"
@@ -508,7 +514,7 @@ local_backup(){
508514

509515
# Defining ftp command function
510516
ftpc() {
511-
ftp -n $HOST $FTP_PORT <<EOF
517+
ftp -n $HOST <<EOF
512518
quote USER $USERNAME
513519
quote PASS $PASSWORD
514520
binary
@@ -648,18 +654,18 @@ done
648654
# Concatenating string
649655
backup_str="BACKUP='$user.$DATE.tar'"
650656
backup_str="$backup_str TYPE='$BACKUP_SYSTEM' SIZE='$size'"
651-
backup_str="$backup_str VESTA='yes'"
652657
backup_str="$backup_str WEB='${web_list// /,}'"
653658
backup_str="$backup_str DNS='${dns_list// /,}'"
654659
backup_str="$backup_str MAIL='${mail_list// /,}'"
655660
backup_str="$backup_str DB='${db_list// /,}'"
656661
backup_str="$backup_str CRON='$cron_list'"
662+
backup_str="$backup_str UDIR='${udir_list// /,}'"
657663
backup_str="$backup_str RUNTIME='$run_time' TIME='$TIME' DATE='$DATE'"
658664
echo "$backup_str" >> $USER_DATA/backup.conf
659665
chmod 660 $USER_DATA/backup.conf
660666

661667
# Clean backup queue
662-
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
668+
sed -i "/v-backup-user $user /d" $VESTA/data/queue/backup.pipe
663669

664670
# Send notification
665671
if [ "$notify" != 'no' ]; then

bin/v-list-user-backup

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ is_object_valid 'backup' 'BACKUP' "$backup"
8888
# Defining config and fields to select
8989
conf=$USER_DATA/backup.conf
9090

91-
fields="\$BACKUP \$TYPE \$SIZE \$VESTA \$PAM \$WEB \$DNS \$DB"
92-
fields="$fields \$MAIL \$CRON \$RUNTIME \$TIME \$DATE"
91+
fields="\$BACKUP \$TYPE \$SIZE \$WEB \$DNS \$DB \$MAIL \$CRON \$UDIR"
92+
fields="$fields \$RUNTIME \$TIME \$DATE"
9393

9494
# Listing backup
9595
case $format in

bin/v-list-user-backups

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ if [ ! -e "$conf" ]; then
3636
fi
3737

3838
# Defining fileds to select
39-
fields="\$BACKUP \$TYPE \$SIZE \$VESTA \$PAM \$WEB \$DNS \$DB"
40-
fields="$fields \$MAIL \$CRON \$RUNTIME \$TIME \$DATE"
39+
fields="\$BACKUP \$TYPE \$SIZE \$WEB \$DNS \$DB \$MAIL \$CRON \$UDIR"
40+
fields="$fields \$RUNTIME \$TIME \$DATE"
4141

4242
# Listing domains
4343
case $format in

bin/v-restore-user

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: restore user
3-
# options: USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIRS] [NOTIFY]
3+
# options: USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIR] [NOTIFY]
44
#
55
# The function for resotring user from backup.
66

@@ -17,7 +17,7 @@ dns=$4
1717
mail=$5
1818
db=$6
1919
cron=$7
20-
u_dirs=$8
20+
udir=$8
2121
notify=${9-no}
2222

2323
# Define backup dir
@@ -47,7 +47,7 @@ is_backup_valid() {
4747
# Verifications #
4848
#----------------------------------------------------------#
4949

50-
args='USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIRS] [NOTIFY]'
50+
args='USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIR] [NOTIFY]'
5151
check_args '2' "$#" $args
5252
validate_format 'user' 'backup'
5353
is_object_valid 'user' 'USER' "$user"
@@ -574,7 +574,7 @@ if [ "$cron" != 'no' ]; then
574574
echo -e "$(date "+%F %T") $db"
575575
msg="$msg\n$(date "+%F %T") $db"
576576

577-
# unpack db container
577+
# unpack cron container
578578
tar xf $BACKUP/$backup -C $tmpdir ./cron
579579
if [ "$?" -ne 0 ]; then
580580
echo "Error: can't unpack cron contaner"
@@ -593,9 +593,68 @@ if [ "$cron" != 'no' ]; then
593593
msg="$msg\n"
594594
fi
595595

596+
# Restore user directories
597+
if [ "$udir" != 'no' ]; then
598+
echo "-- USER DIR --"
599+
msg="$msg\n-- USER DIR --"
600+
601+
# unpack user dir container
602+
if [ ! -z "$(tar -tf $BACKUP/$backup |grep './user_dir')" ]; then
603+
604+
# Create user dir list
605+
udir_list=$(tar -tf $BACKUP/$backup | grep "^./user_dir" |\
606+
grep tar.gz | cut -f 3 -d '/' | sed -e "s/.tar.gz//")
607+
608+
if [ ! -z "$udir" ]; then
609+
udir_include_list=$(mktemp)
610+
for udir_include in ${udir//,/ }; do
611+
echo "^$udir_include$" >> $udir_include_list
612+
done
613+
udir_list=$(echo "$udir_list" | egrep -f $udir_include_list )
614+
rm -f $udir_include_list
615+
fi
616+
617+
for user_dir in $udir_list; do
618+
echo -e "$(date "+%F %T") $user_dir"
619+
msg="$msg\n$(date "+%F %T") $user_dir"
620+
621+
# unpack user_dir container
622+
tar xf $BACKUP/$backup -C $tmpdir ./user_dir/$user_dir.tar.gz
623+
if [ "$?" -ne 0 ]; then
624+
echo "Error: can't unpack $user_dir user dir contaner"
625+
echo "Can't unpack $user_dir user dir contaner" |\
626+
$send_mail -s "$subj" $email
627+
rm -rf $tmpdir
628+
exit $E_PARSING
629+
fi
630+
631+
tar xzf $tmpdir/user_dir/$user_dir.tar.gz -C $HOMEDIR/$user
632+
if [ "$?" -ne 0 ]; then
633+
echo "Error: can't unpack $user_dir user dir contaner"
634+
echo "Can't unpack $user_dir user dir contaner" |\
635+
$send_mail -s "$subj" $email
636+
rm -rf $tmpdir
637+
exit $E_PARSING
638+
fi
639+
done
640+
fi
641+
echo
642+
msg="$msg\n"
643+
fi
644+
596645
# Remove temporary data
597646
rm -rf $tmpdir
598647

648+
# Clean restore queue
649+
sed -i "/v-restore-user $user /d" $VESTA/data/queue/backup.pipe
650+
651+
# Send notification
652+
if [ "$notify" != 'no' ]; then
653+
subj="$user → restore has been completed"
654+
email=$(get_user_value '$CONTACT')
655+
echo -e "$msg" | $send_mail -s "$subj" $email
656+
fi
657+
599658

600659
#----------------------------------------------------------#
601660
# Vesta #
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ validate_format 'user'
2626
is_system_enabled "$BACKUP_SYSTEM"
2727
is_object_valid 'user' 'USER' "$user"
2828
is_backup_enabled
29-
is_backup_scheduled
29+
is_backup_scheduled 'backup'
3030

3131

3232
#----------------------------------------------------------#
3333
# Action #
3434
#----------------------------------------------------------#
3535

36-
# Adding backup to pipe
36+
# Adding backup task to the queue
3737
echo "$BIN/v-backup-user $user yes" >> $VESTA/data/queue/backup.pipe
3838

3939

bin/v-schedule-user-restore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# info: schedule user backup restoration
3+
# options: USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIR]
4+
#
5+
# The function for scheduling user backup restoration.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
backup=$2
15+
web=$3
16+
dns=$4
17+
mail=$5
18+
db=$6
19+
cron=$7
20+
udir=$8
21+
22+
# Includes
23+
source $VESTA/conf/vesta.conf
24+
source $VESTA/func/main.sh
25+
26+
27+
#----------------------------------------------------------#
28+
# Verifications #
29+
#----------------------------------------------------------#
30+
31+
check_args '2' "$#" 'USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIR]'
32+
validate_format 'user'
33+
is_system_enabled "$BACKUP_SYSTEM"
34+
is_object_valid 'user' 'USER' "$user"
35+
is_backup_enabled
36+
is_backup_scheduled 'restore'
37+
38+
39+
#----------------------------------------------------------#
40+
# Action #
41+
#----------------------------------------------------------#
42+
43+
# Adding restore task to the queue
44+
options="'$web' '$dns' '$mail' '$db' '$cron' '$udir'"
45+
echo "$BIN/v-restore-user $user $backup $options yes" \
46+
>> $VESTA/data/queue/backup.pipe
47+
48+
49+
#----------------------------------------------------------#
50+
# Vesta #
51+
#----------------------------------------------------------#
52+
53+
# Logging
54+
log_event "$OK" "$EVENT"
55+
56+
exit

func/main.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ is_backup_enabled() {
161161
# Check user backup settings
162162
is_backup_scheduled() {
163163
if [ -e "$VESTA/data/queue/backup.pipe" ]; then
164-
check_backup=$(grep " $user " $VESTA/data/queue/backup.pipe)
165-
if [ ! -z "$check_backup" ]; then
166-
echo "Error: backup is already scheduled"
164+
check_q=$(grep " $user " $VESTA/data/queue/backup.pipe | grep $1)
165+
if [ ! -z "$check_q" ]; then
166+
echo "Error: $1 is already scheduled"
167167
log_event "$E_EXISTS" "$EVENT"
168168
exit $E_EXISTS
169169
fi

web/bulk/restore/index.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
ob_start();
5+
session_start();
6+
7+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
8+
9+
$action = $_POST['action'];
10+
$backup = escapeshellarg($_POST['backup']);
11+
12+
$web = 'no';
13+
$dns = 'no';
14+
$mail = 'no';
15+
$db = 'no';
16+
$cron = 'no';
17+
$udir = 'no';
18+
19+
if (!empty($_POST['web'])) $web = escapeshellarg(implode(",",$_POST['web']));
20+
if (!empty($_POST['dns'])) $dns = escapeshellarg(implode(",",$_POST['dns']));
21+
if (!empty($_POST['mail'])) $mail = escapeshellarg(implode(",",$_POST['mail']));
22+
if (!empty($_POST['db'])) $db = escapeshellarg(implode(",",$_POST['db']));
23+
if (!empty($_POST['cron'])) $cron = 'yes';
24+
if (!empty($_POST['udir'])) $udir = escapeshellarg(implode(",",$_POST['udir']));
25+
26+
if ($action == 'restore') {
27+
exec (VESTA_CMD."v-schedule-user-restore ".$user." ".$backup." ".$web." ".$dns." ".$mail." ".$db." ".$cron." ".$udir, $output, $return_var);
28+
if ($return_var == 0) {
29+
$_SESSION['restore_msg'] = _('RESTORE_SCHEDULED');
30+
} else {
31+
$_SESSION['restore_msg'] = implode('<br>', $output);
32+
if (empty($_SESSION['restore_msg'])) {
33+
$_SESSION['restore_msg'] = _('Error: vesta did not return any output.');
34+
}
35+
if ($return_var == 4) {
36+
$_SESSION['restore_msg'] = _('RESTORE_EXISTS');
37+
}
38+
}
39+
}
40+
41+
header("Location: /list/backup/?backup=" . $_POST['backup']);

web/inc/i18n/en.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@
367367
'IP address is in use' => 'IP address is in use',
368368
'BACKUP_SCHEDULED' => 'Task has been added to the queue. You will receive an email notification when your backup is ready for download.',
369369
'BACKUP_EXISTS' => 'An existing backup is already running. Please wait for that backup to finish.',
370+
'RESTORE_SCHEDULED' => 'Task has been added to the queue. You will receive an email notification when your backup is ready for download.',
371+
'RESTORE_EXISTS' => 'An existing restoration task is already running. Please wait for it to finish before launching it again.',
372+
370373

371374
'Welcome to Vesta Control Panel' => 'Welcome to Vesta Control Panel',
372375
'MAIL_FROM' => 'Vesta Control Panel <noreply@%s>',

web/inc/i18n/es.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@
366366
'IP address is in use' => 'La IP esta en uso',
367367
'BACKUP_SCHEDULED' => "La tarea se ha añadido a la cola. Usted recibirá un correo de notificación cuando el respaldo de seguridad este listo para su descarga.",
368368
'BACKUP_EXISTS' => "Se esta realizando una copia de seguridad en este momento.Por favor espere a que esta termine.",
369+
'RESTORE_SCHEDULED' => "La tarea se ha añadido a la cola. Usted recibirá un correo de notificación cuando el respaldo de seguridad este listo para su descarga.",
370+
'RESTORE_EXISTS' => "Una tarea se está ejecutando. Por favor espere a que esta termine.",
369371

370372
'Welcome to Vesta Control Panel' => 'Bienvenido al Panel de Control Vesta',
371373
'MAIL_FROM' => 'Panel de Control Vesta <noreply@%s>',

0 commit comments

Comments
 (0)