From 65db51189c8810dd3fc1f390fcfbdcd1848e029e Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Thu, 28 Mar 2013 01:12:57 +0200 Subject: [PATCH] backup restoration 90% completed --- bin/v-backup-user | 30 +++-- bin/v-list-user-backup | 4 +- bin/v-list-user-backups | 4 +- bin/v-restore-user | 67 +++++++++- ...add-user-backup => v-schedule-user-backup} | 4 +- bin/v-schedule-user-restore | 56 ++++++++ func/main.sh | 6 +- web/bulk/restore/index.php | 41 ++++++ web/inc/i18n/en.php | 3 + web/inc/i18n/es.php | 2 + web/inc/i18n/ru.php | 2 + web/inc/i18n/ua.php | 2 + web/{add => schedule}/backup/index.php | 2 +- web/schedule/restore/index.php | 40 ++++++ web/templates/admin/list_backup.html | 46 ++++--- web/templates/admin/list_backup_detail.html | 120 ++++++++++-------- 16 files changed, 330 insertions(+), 99 deletions(-) rename bin/{v-add-user-backup => v-schedule-user-backup} (94%) create mode 100755 bin/v-schedule-user-restore create mode 100644 web/bulk/restore/index.php rename web/{add => schedule}/backup/index.php (88%) create mode 100644 web/schedule/restore/index.php diff --git a/bin/v-backup-user b/bin/v-backup-user index 13a3ee1e0..a5fe223bc 100755 --- a/bin/v-backup-user +++ b/bin/v-backup-user @@ -402,7 +402,7 @@ then cron_record=$(wc -l $USER_DATA/cron.conf|cut -f 1 -d ' ') if [ -e "/var/spool/cron/$user" ]; then - cron_list='yes' + cron_list="$cron_record" cp /var/spool/cron/$user $tmpdir/cron/ fi if [ "$cron_record" -eq 1 ]; then @@ -417,22 +417,28 @@ then fi # User Directories -echo "-- User Directories --" -msg="$msg\n-- User Directories --" -mkdir $tmpdir/user_dirs -user_dirs=$(ls $HOMEDIR/$user | \ +echo "-- User Dir --" +msg="$msg\n-- User Dir --" +mkdir $tmpdir/user_dir +user_dir=$(ls $HOMEDIR/$user | \ grep -v conf | \ grep -v web | \ grep -v dns | \ grep -v mail | \ grep -v tmp) i=0 -for user_dir in $user_dirs; do +for udir in $user_dir; do + udir_list="$udir_list $udir" ((i ++)) - echo -e "$(date "+%F %T") $user_dir" - msg="$msg\n$(date "+%F %T") $user_dir" - cp -pr $HOMEDIR/$user/$user_dir $tmpdir/user_dirs/ + echo -e "$(date "+%F %T") $udir" + msg="$msg\n$(date "+%F %T") $udir" + cp -pr $HOMEDIR/$user/$udir $tmpdir/user_dir/ + cd $tmpdir/user_dir/ + tar -czpf $udir.tar.gz $udir + rm -rf $udir done +udir_list=$(echo "$udir_list" | sed -e "s/ */\ /g" -e "s/^ //") + if [ "$i" -eq 1 ]; then echo -e "$(date "+%F %T") $i user directory" msg="$msg\n$(date "+%F %T") $i directory" @@ -508,7 +514,7 @@ local_backup(){ # Defining ftp command function ftpc() { - ftp -n $HOST $FTP_PORT <> $USER_DATA/backup.conf chmod 660 $USER_DATA/backup.conf # Clean backup queue -sed -i "/ $user /d" $VESTA/data/queue/backup.pipe +sed -i "/v-backup-user $user /d" $VESTA/data/queue/backup.pipe # Send notification if [ "$notify" != 'no' ]; then diff --git a/bin/v-list-user-backup b/bin/v-list-user-backup index 4bdd5fd99..6fa99af65 100755 --- a/bin/v-list-user-backup +++ b/bin/v-list-user-backup @@ -88,8 +88,8 @@ is_object_valid 'backup' 'BACKUP' "$backup" # Defining config and fields to select conf=$USER_DATA/backup.conf -fields="\$BACKUP \$TYPE \$SIZE \$VESTA \$PAM \$WEB \$DNS \$DB" -fields="$fields \$MAIL \$CRON \$RUNTIME \$TIME \$DATE" +fields="\$BACKUP \$TYPE \$SIZE \$WEB \$DNS \$DB \$MAIL \$CRON \$UDIR" +fields="$fields \$RUNTIME \$TIME \$DATE" # Listing backup case $format in diff --git a/bin/v-list-user-backups b/bin/v-list-user-backups index c08c79f53..80ed675be 100755 --- a/bin/v-list-user-backups +++ b/bin/v-list-user-backups @@ -36,8 +36,8 @@ if [ ! -e "$conf" ]; then fi # Defining fileds to select -fields="\$BACKUP \$TYPE \$SIZE \$VESTA \$PAM \$WEB \$DNS \$DB" -fields="$fields \$MAIL \$CRON \$RUNTIME \$TIME \$DATE" +fields="\$BACKUP \$TYPE \$SIZE \$WEB \$DNS \$DB \$MAIL \$CRON \$UDIR" +fields="$fields \$RUNTIME \$TIME \$DATE" # Listing domains case $format in diff --git a/bin/v-restore-user b/bin/v-restore-user index 96d0ed4d3..1bdf1302f 100755 --- a/bin/v-restore-user +++ b/bin/v-restore-user @@ -1,6 +1,6 @@ #!/bin/bash # info: restore user -# options: USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIRS] [NOTIFY] +# options: USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIR] [NOTIFY] # # The function for resotring user from backup. @@ -17,7 +17,7 @@ dns=$4 mail=$5 db=$6 cron=$7 -u_dirs=$8 +udir=$8 notify=${9-no} # Define backup dir @@ -47,7 +47,7 @@ is_backup_valid() { # Verifications # #----------------------------------------------------------# -args='USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIRS] [NOTIFY]' +args='USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIR] [NOTIFY]' check_args '2' "$#" $args validate_format 'user' 'backup' is_object_valid 'user' 'USER' "$user" @@ -574,7 +574,7 @@ if [ "$cron" != 'no' ]; then echo -e "$(date "+%F %T") $db" msg="$msg\n$(date "+%F %T") $db" - # unpack db container + # unpack cron container tar xf $BACKUP/$backup -C $tmpdir ./cron if [ "$?" -ne 0 ]; then echo "Error: can't unpack cron contaner" @@ -593,9 +593,68 @@ if [ "$cron" != 'no' ]; then msg="$msg\n" fi +# Restore user directories +if [ "$udir" != 'no' ]; then + echo "-- USER DIR --" + msg="$msg\n-- USER DIR --" + + # unpack user dir container + if [ ! -z "$(tar -tf $BACKUP/$backup |grep './user_dir')" ]; then + + # Create user dir list + udir_list=$(tar -tf $BACKUP/$backup | grep "^./user_dir" |\ + grep tar.gz | cut -f 3 -d '/' | sed -e "s/.tar.gz//") + + if [ ! -z "$udir" ]; then + udir_include_list=$(mktemp) + for udir_include in ${udir//,/ }; do + echo "^$udir_include$" >> $udir_include_list + done + udir_list=$(echo "$udir_list" | egrep -f $udir_include_list ) + rm -f $udir_include_list + fi + + for user_dir in $udir_list; do + echo -e "$(date "+%F %T") $user_dir" + msg="$msg\n$(date "+%F %T") $user_dir" + + # unpack user_dir container + tar xf $BACKUP/$backup -C $tmpdir ./user_dir/$user_dir.tar.gz + if [ "$?" -ne 0 ]; then + echo "Error: can't unpack $user_dir user dir contaner" + echo "Can't unpack $user_dir user dir contaner" |\ + $send_mail -s "$subj" $email + rm -rf $tmpdir + exit $E_PARSING + fi + + tar xzf $tmpdir/user_dir/$user_dir.tar.gz -C $HOMEDIR/$user + if [ "$?" -ne 0 ]; then + echo "Error: can't unpack $user_dir user dir contaner" + echo "Can't unpack $user_dir user dir contaner" |\ + $send_mail -s "$subj" $email + rm -rf $tmpdir + exit $E_PARSING + fi + done + fi + echo + msg="$msg\n" +fi + # Remove temporary data rm -rf $tmpdir +# Clean restore queue +sed -i "/v-restore-user $user /d" $VESTA/data/queue/backup.pipe + +# Send notification +if [ "$notify" != 'no' ]; then + subj="$user → restore has been completed" + email=$(get_user_value '$CONTACT') + echo -e "$msg" | $send_mail -s "$subj" $email +fi + #----------------------------------------------------------# # Vesta # diff --git a/bin/v-add-user-backup b/bin/v-schedule-user-backup similarity index 94% rename from bin/v-add-user-backup rename to bin/v-schedule-user-backup index 69af3d600..3d5a8eff4 100755 --- a/bin/v-add-user-backup +++ b/bin/v-schedule-user-backup @@ -26,14 +26,14 @@ validate_format 'user' is_system_enabled "$BACKUP_SYSTEM" is_object_valid 'user' 'USER' "$user" is_backup_enabled -is_backup_scheduled +is_backup_scheduled 'backup' #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Adding backup to pipe +# Adding backup task to the queue echo "$BIN/v-backup-user $user yes" >> $VESTA/data/queue/backup.pipe diff --git a/bin/v-schedule-user-restore b/bin/v-schedule-user-restore new file mode 100755 index 000000000..9b1ba17f5 --- /dev/null +++ b/bin/v-schedule-user-restore @@ -0,0 +1,56 @@ +#!/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 defenition +user=$1 +backup=$2 +web=$3 +dns=$4 +mail=$5 +db=$6 +cron=$7 +udir=$8 + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '2' "$#" 'USER BACKUP [WEB] [DNS] [MAIL] [DB] [CRON] [UDIR]' +validate_format 'user' +is_system_enabled "$BACKUP_SYSTEM" +is_object_valid 'user' 'USER' "$user" +is_backup_enabled +is_backup_scheduled 'restore' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Adding restore task to the queue +options="'$web' '$dns' '$mail' '$db' '$cron' '$udir'" +echo "$BIN/v-restore-user $user $backup $options yes" \ + >> $VESTA/data/queue/backup.pipe + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Logging +log_event "$OK" "$EVENT" + +exit diff --git a/func/main.sh b/func/main.sh index 305e573d0..b62fa273e 100644 --- a/func/main.sh +++ b/func/main.sh @@ -161,9 +161,9 @@ is_backup_enabled() { # Check user backup settings is_backup_scheduled() { if [ -e "$VESTA/data/queue/backup.pipe" ]; then - check_backup=$(grep " $user " $VESTA/data/queue/backup.pipe) - if [ ! -z "$check_backup" ]; then - echo "Error: backup is already scheduled" + check_q=$(grep " $user " $VESTA/data/queue/backup.pipe | grep $1) + if [ ! -z "$check_q" ]; then + echo "Error: $1 is already scheduled" log_event "$E_EXISTS" "$EVENT" exit $E_EXISTS fi diff --git a/web/bulk/restore/index.php b/web/bulk/restore/index.php new file mode 100644 index 000000000..ff19146ab --- /dev/null +++ b/web/bulk/restore/index.php @@ -0,0 +1,41 @@ +', $output); + if (empty($_SESSION['restore_msg'])) { + $_SESSION['restore_msg'] = _('Error: vesta did not return any output.'); + } + if ($return_var == 4) { + $_SESSION['restore_msg'] = _('RESTORE_EXISTS'); + } + } +} + +header("Location: /list/backup/?backup=" . $_POST['backup']); diff --git a/web/inc/i18n/en.php b/web/inc/i18n/en.php index 8f6378c8c..80b1e15c6 100644 --- a/web/inc/i18n/en.php +++ b/web/inc/i18n/en.php @@ -367,6 +367,9 @@ $LANG['en'] = array( 'IP address is in use' => 'IP address is in use', 'BACKUP_SCHEDULED' => 'Task has been added to the queue. You will receive an email notification when your backup is ready for download.', 'BACKUP_EXISTS' => 'An existing backup is already running. Please wait for that backup to finish.', + 'RESTORE_SCHEDULED' => 'Task has been added to the queue. You will receive an email notification when your backup is ready for download.', + 'RESTORE_EXISTS' => 'An existing restoration task is already running. Please wait for it to finish before launching it again.', + 'Welcome to Vesta Control Panel' => 'Welcome to Vesta Control Panel', 'MAIL_FROM' => 'Vesta Control Panel ', diff --git a/web/inc/i18n/es.php b/web/inc/i18n/es.php index 6fe4afa30..d9f5af4f3 100644 --- a/web/inc/i18n/es.php +++ b/web/inc/i18n/es.php @@ -366,6 +366,8 @@ $LANG['es'] = array( 'IP address is in use' => 'La IP esta en uso', '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.", 'BACKUP_EXISTS' => "Se esta realizando una copia de seguridad en este momento.Por favor espere a que esta termine.", + '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.", + 'RESTORE_EXISTS' => "Una tarea se está ejecutando. Por favor espere a que esta termine.", 'Welcome to Vesta Control Panel' => 'Bienvenido al Panel de Control Vesta', 'MAIL_FROM' => 'Panel de Control Vesta ', diff --git a/web/inc/i18n/ru.php b/web/inc/i18n/ru.php index 8d10491a6..be2948780 100644 --- a/web/inc/i18n/ru.php +++ b/web/inc/i18n/ru.php @@ -368,6 +368,8 @@ $LANG['ru'] = array( 'IP address is in use' => 'IP адрес используется', 'BACKUP_SCHEDULED' => 'Задание успешно добавлено в очередь. После завершения вы получите полный отчет по почте.', 'BACKUP_EXISTS' => 'Резервное копирование уже выполняется, полжалуйста дождитесь окончания.', + 'RESTORE_SCHEDULED' => 'Задание успешно добавлено в очередь. После завершения вы получите полный отчет по почте.', + 'RESTORE_EXISTS' => 'Задание уже выполняется, полжалуйста дождитесь окончания.', 'Welcome to Vesta Control Panel' => 'Добро пожаловать в панель управления Vesta', 'MAIL_FROM' => 'Vesta Control Panel ', diff --git a/web/inc/i18n/ua.php b/web/inc/i18n/ua.php index 60fe2d983..5aae2199e 100644 --- a/web/inc/i18n/ua.php +++ b/web/inc/i18n/ua.php @@ -368,6 +368,8 @@ $LANG['ua'] = array( 'IP address is in use' => 'IP адреса використовується', 'BACKUP_SCHEDULED' => 'Завдання успішно додано в чергу. Після завершення ви отримаєте повний звіт по пошті.', 'BACKUP_EXISTS' => 'Резервне копіювання вже виконується, будь-ласка дочекайтесь закінчення.', + 'RESTORE_SCHEDULED' => 'Завдання успішно додано в чергу. Після завершення ви отримаєте повний звіт по пошті.', + 'RESTORE_EXISTS' => 'Завдання вже виконується, будь-ласка дочекайтесь закінчення.', 'Welcome to Vesta Control Panel' => 'Вітаємо в панелі керування Vesta', 'MAIL_FROM' => 'Vesta Control Panel ', diff --git a/web/add/backup/index.php b/web/schedule/backup/index.php similarity index 88% rename from web/add/backup/index.php rename to web/schedule/backup/index.php index e4f77d8ae..a548d1603 100644 --- a/web/add/backup/index.php +++ b/web/schedule/backup/index.php @@ -6,7 +6,7 @@ session_start(); include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); $v_username = escapeshellarg($user); -exec (VESTA_CMD."v-add-user-backup ".$v_username, $output, $return_var); +exec (VESTA_CMD."v-schedule-user-backup ".$v_username, $output, $return_var); if ($return_var == 0) { $_SESSION['backup_msg'] = _('BACKUP_SCHEDULED'); } else { diff --git a/web/schedule/restore/index.php b/web/schedule/restore/index.php new file mode 100644 index 000000000..cf7ed6d95 --- /dev/null +++ b/web/schedule/restore/index.php @@ -0,0 +1,40 @@ +', $output); + if (empty($_SESSION['restore_msg'])) { + $_SESSION['restore_msg'] = _('Error: vesta did not return any output.'); + } + if ($return_var == 4) { + $_SESSION['restore_msg'] = _('RESTORE_EXISTS'); + } + } +} + +header("Location: /list/backup/?backup=" . $_GET['backup']); diff --git a/web/templates/admin/list_backup.html b/web/templates/admin/list_backup.html index 8bfaf341b..dfbfb20ed 100644 --- a/web/templates/admin/list_backup.html +++ b/web/templates/admin/list_backup.html @@ -2,7 +2,7 @@ @@ -61,11 +61,16 @@ $dns = _('no'); $mail = _('no'); $db = _('no'); + $cron = _('no'); + $udir = _('no'); if (!empty($data[$key]['WEB'])) $web = _('yes').' ¨'; if (!empty($data[$key]['DNS'])) $dns = _('yes').' ¨'; if (!empty($data[$key]['MAIL'])) $mail = _('yes').' ¨'; if (!empty($data[$key]['DB'])) $db = _('yes').' ¨'; + if (!empty($data[$key]['CRON'])) $cron = _('yes').' ¨'; + if (!empty($data[$key]['UDIR'])) $udir = _('yes').' ¨'; + ?> @@ -127,16 +132,6 @@ - - - - -
- : - - - - -
: @@ -157,10 +152,6 @@
- - - +
: @@ -171,8 +162,12 @@
+ + + - - + + + + +
+ : @@ -182,15 +177,26 @@
+ : - +
+ : + + + + +
diff --git a/web/templates/admin/list_backup_detail.html b/web/templates/admin/list_backup_detail.html index 5c7b517d2..a6553e1aa 100644 --- a/web/templates/admin/list_backup_detail.html +++ b/web/templates/admin/list_backup_detail.html @@ -2,7 +2,7 @@
-

+

@@ -63,55 +64,22 @@
+ - - - - - - - - - -
- - -
-
- " class="data-controls"> - - - - - - - - - - -
- - - -
-
- +
- " class="data-controls"> + @@ -120,7 +88,7 @@ + + + + + + + + +
- + @@ -131,22 +99,24 @@
- +
- " class="data-controls"> + @@ -166,22 +136,24 @@
- +
- " class="data-controls"> + @@ -201,22 +173,24 @@
- +
- " class="data-controls"> + @@ -236,22 +210,24 @@
- +
- " class="data-controls"> + @@ -271,6 +247,44 @@
+ + +
+
+ + + + + + + + + + + +
+ + + +
+