2024-03-22 04:54:28 +01:00
|
|
|
package SrvMngr::Controller::Backup;
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# heading : System
|
|
|
|
# description : Backup or restore
|
|
|
|
# navigation : 4000 200
|
|
|
|
# Copyright (C) 2002 Mitel Networks Corporation
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# routes : end
|
|
|
|
# for information - routes
|
|
|
|
# $if_admin->get('/backup')->to('backup#main')->name('backup');
|
|
|
|
# $if_admin->post('/backup')->to('backup#do_display')->name('backupd');
|
|
|
|
# $if_admin->get('/backupd')->to('backup#do_display')->name('backupc');
|
|
|
|
# $if_admin->post('/backupd')->to('backup#do_update')->name('backupu');
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Mojo::Base 'Mojolicious::Controller';
|
|
|
|
use utf8;
|
|
|
|
use Locale::gettext;
|
|
|
|
use SrvMngr::I18N;
|
|
|
|
use SrvMngr qw(theme_list init_session ip_number_or_blank);
|
|
|
|
use Quota;
|
|
|
|
use esmith::ConfigDB;
|
|
|
|
use esmith::AccountsDB;
|
|
|
|
use esmith::util;
|
|
|
|
use File::Basename;
|
|
|
|
use File::Find;
|
|
|
|
use File::Path qw(make_path remove_tree);
|
|
|
|
use esmith::Backup;
|
|
|
|
use esmith::BackupHistoryDB;
|
|
|
|
use esmith::util;
|
|
|
|
use esmith::lockfile;
|
2024-04-30 19:23:52 +02:00
|
|
|
use esmith::BlockDevices;
|
2024-03-22 04:54:28 +01:00
|
|
|
use constant DEBUG => $ENV{MOJO_SMANAGER_DEBUG} || 0;
|
2025-01-14 13:49:31 +01:00
|
|
|
our $cdb = esmith::ConfigDB->open || die "Couldn't open config db";
|
2024-03-22 04:54:28 +01:00
|
|
|
our $adb = esmith::AccountsDB->open || die "Couldn't open accounts db";
|
|
|
|
our $rdb = esmith::ConfigDB->open('/etc/e-smith/restore')
|
2025-01-14 13:49:31 +01:00
|
|
|
|| die "Couldn't open restore db";
|
2024-03-22 04:54:28 +01:00
|
|
|
my $es_backup = new esmith::Backup or die "Couldn't create Backup object\n";
|
|
|
|
my @directories = $es_backup->restore_list;
|
|
|
|
@directories = grep { -e "/$_" } @directories;
|
|
|
|
my @backup_excludes = $es_backup->excludes;
|
|
|
|
|
|
|
|
# Unbuffer standard output so that files and directories are listed as
|
|
|
|
# they are restored
|
|
|
|
$| = 1;
|
|
|
|
|
|
|
|
# Store away current gid of 'www' group.
|
|
|
|
my $www_gid = getgrnam("www");
|
|
|
|
|
|
|
|
sub main {
|
|
|
|
my $c = shift;
|
|
|
|
$c->app->log->info($c->log_req);
|
|
|
|
my %bac_datas = ();
|
2025-01-14 13:49:31 +01:00
|
|
|
my $title = $c->l('bac_BACKUP_TITLE');
|
2024-03-22 04:54:28 +01:00
|
|
|
my $notif;
|
|
|
|
$bac_datas{'function'} = 'desktop_backup';
|
|
|
|
my ($tarsize, $dumpsize, undef, undef) = $c->CalculateSizes();
|
|
|
|
my $module = $cdb->get('backup');
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($module) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$module = $module->prop('Program');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# The default e-smith backup program is flexbackup.
|
|
|
|
unless (defined $module) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$module = "flexbackup";
|
2024-03-22 04:54:28 +01:00
|
|
|
} elsif ($module eq '') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$module = "flexbackup";
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
$bac_datas{'tarsize'} = $tarsize;
|
2024-03-22 04:54:28 +01:00
|
|
|
$bac_datas{'dumpsize'} = $dumpsize;
|
2025-01-14 13:49:31 +01:00
|
|
|
$bac_datas{'module'} = $module;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
if ($tarsize =~ /Tb/ or $tarsize =~ /(\d+)Gb/ and $1 >= 2) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$notif = $c->l("bac_BACKUP_DESKTOP_TOO_BIG") . ' : ' . $tarsize;
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
my $rec = $cdb->get('backup');
|
|
|
|
my ($backup_status, $backupwk_status) = 'disabled';
|
|
|
|
|
|
|
|
if ($rec) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$backup_status = $rec->prop('status') || 'disabled';
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($backup_status eq "enabled") {
|
2025-01-14 13:49:31 +01:00
|
|
|
$bac_datas{'backupTime'} = $rec->prop('backupTime');
|
|
|
|
$bac_datas{'reminderTime'} = $rec->prop('reminderTime');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
$rec = $cdb->get('backupwk');
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($rec) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$backupwk_status = $rec->prop('status') || 'disabled';
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($backupwk_status eq "enabled") {
|
2025-01-14 13:49:31 +01:00
|
|
|
$bac_datas{'backupwkTime'} = $rec->prop('BackupTime');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
$bac_datas{'backupStatus'} = $backup_status;
|
2024-03-22 04:54:28 +01:00
|
|
|
$bac_datas{'backupwkStatus'} = $backupwk_status;
|
2025-01-14 13:49:31 +01:00
|
|
|
$c->stash(warning => $notif) if ($notif);
|
|
|
|
$c->stash(title => $title, bac_datas => \%bac_datas);
|
2024-03-22 04:54:28 +01:00
|
|
|
$c->render(template => 'backup');
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub main
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub do_display {
|
|
|
|
my $c = shift;
|
|
|
|
$c->app->log->info($c->log_req);
|
|
|
|
my $rt = $c->current_route;
|
|
|
|
my ($res, $result) = '';
|
|
|
|
my $function = $c->param('Function');
|
|
|
|
|
|
|
|
if ($function =~ /^(\S+)$/) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$function = $1;
|
2024-03-22 04:54:28 +01:00
|
|
|
} elsif ($function =~ /^\s*$/) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$function = "zoverall";
|
|
|
|
} else {
|
|
|
|
$result = $c->l('bac_INVALID_FUNCTION') . $function;
|
|
|
|
$function = undef;
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
DEBUG && warn("do_display $function");
|
2024-03-22 04:54:28 +01:00
|
|
|
my %bac_datas = ();
|
|
|
|
$bac_datas{'function'} = $function;
|
|
|
|
my $title = $c->l('bac_BACKUP_TITLE');
|
2025-01-14 13:49:31 +01:00
|
|
|
my $dest = '';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'desktop_backup') {
|
|
|
|
my $CompressionLevel = $cdb->get_prop("backupconsole", "CompressionLevel") || "-6";
|
|
|
|
my @exclude = map (" --exclude=$_", @backup_excludes);
|
|
|
|
$c->stash(compressionlevel => $CompressionLevel, exclude => \@exclude, directories => \@directories);
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# streaming download in template
|
|
|
|
return $c->render("/backdown");
|
|
|
|
} ## end if ($function eq 'desktop_backup')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'tape_configure') {
|
|
|
|
$bac_datas{'status'} = 'unchecked';
|
|
|
|
my $backupTime = "2:00";
|
|
|
|
my $rec = $cdb->get('backup');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($rec) {
|
|
|
|
$backupTime = $rec->prop('backupTime') || "2:00";
|
|
|
|
my $backup_status = $rec->prop('status');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (defined $backup_status && $backup_status eq "enabled") {
|
|
|
|
$bac_datas{'status'} = "checked";
|
|
|
|
}
|
|
|
|
} ## end if ($rec)
|
|
|
|
($bac_datas{backupAMPM}, $bac_datas{reminderAMPM}) = 'AM';
|
|
|
|
($bac_datas{backupHour}, $bac_datas{backupMin}) = split(":", $backupTime, -1);
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($bac_datas{backupHour} > 11) {
|
|
|
|
if ($bac_datas{backupHour} > 12) {
|
|
|
|
$bac_datas{backupHour} -= 12;
|
|
|
|
}
|
|
|
|
$bac_datas{backupAMPM} = 'PM';
|
|
|
|
} ## end if ($bac_datas{backupHour...})
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# Obtain time for reminder notice from the backup cron template
|
|
|
|
my $reminderTime = "14:00";
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($rec) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$reminderTime = $rec->prop('reminderTime') || "14:00";
|
|
|
|
}
|
|
|
|
($bac_datas{reminderHour}, $bac_datas{reminderMin}) = split(":", $reminderTime, -1);
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
if ($bac_datas{reminderHour} > 12) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$bac_datas{reminderHour} -= 12;
|
|
|
|
$bac_datas{reminderAMPM} = 'PM';
|
|
|
|
}
|
|
|
|
} ## end if ($function eq 'tape_configure')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_configure') {
|
2024-03-22 04:54:28 +01:00
|
|
|
my $rec = $cdb->get('backupwk');
|
2025-01-14 13:49:31 +01:00
|
|
|
$bac_datas{vfstype} = $rec->prop('VFSType') || 'cifs';
|
|
|
|
$bac_datas{status} = $rec->prop('status');
|
|
|
|
} ## end if ($function eq 'workstn_configure')
|
|
|
|
|
|
|
|
if ($function eq 'workstn_configure1') {
|
|
|
|
$bac_datas{vfstype} = $c->param('VFSType');
|
|
|
|
$bac_datas{'status'} = '';
|
|
|
|
$bac_datas{ampm} = 'AM';
|
|
|
|
$bac_datas{min} = '';
|
|
|
|
$bac_datas{hour} = '';
|
|
|
|
$bac_datas{login} = 'backup';
|
|
|
|
$bac_datas{password} = 'backup';
|
|
|
|
$bac_datas{station} = 'host';
|
|
|
|
$bac_datas{folder} = 'share';
|
|
|
|
$bac_datas{mount} = '';
|
|
|
|
$bac_datas{setsNumber} = '';
|
|
|
|
$bac_datas{filesinset} = '';
|
|
|
|
$bac_datas{timeout} = '';
|
|
|
|
$bac_datas{incOnlyTimeout} = '';
|
|
|
|
$bac_datas{compression} = '';
|
|
|
|
$bac_datas{dof} = '';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# Obtain backup informations from configuration
|
|
|
|
my $rec = $cdb->get('backupwk');
|
|
|
|
my $Time = '2:00';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($rec) {
|
|
|
|
$Time = $rec->prop('BackupTime') || '2:00';
|
|
|
|
$bac_datas{login} = $rec->prop('Login') || 'backup';
|
|
|
|
$bac_datas{password} = $rec->prop('Password') || 'backup';
|
|
|
|
$bac_datas{station} = $rec->prop('SmbHost') || 'host';
|
|
|
|
$bac_datas{folder} = $rec->prop('SmbShare') || 'share';
|
|
|
|
$bac_datas{mount} = $rec->prop('Mount') || '';
|
|
|
|
$bac_datas{setsNumber} = $rec->prop('SetsMax') || '1';
|
|
|
|
$bac_datas{filesinset} = $rec->prop('DaysInSet') || '1';
|
|
|
|
$bac_datas{timeout} = $rec->prop('Timeout') || '12';
|
|
|
|
$bac_datas{incOnlyTimeout} = $rec->prop('IncOnlyTimeout') || 'yes';
|
|
|
|
$bac_datas{compression} = $rec->prop('Compression') || '0';
|
|
|
|
$bac_datas{dof} = (defined $rec->prop('FullDay')) ? $rec->prop('FullDay') : '7';
|
|
|
|
} ## end if ($rec)
|
|
|
|
($bac_datas{hour}, $bac_datas{min}) = split(':', $Time, -1);
|
|
|
|
|
|
|
|
if ($bac_datas{hour} > 12) {
|
|
|
|
$bac_datas{hour} -= 12;
|
|
|
|
$bac_datas{ampm} = 'PM';
|
|
|
|
}
|
|
|
|
my $backupwk_status;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($rec) {
|
|
|
|
$backupwk_status = $rec->prop('status');
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (defined $backupwk_status && $backupwk_status eq 'enabled') {
|
|
|
|
$bac_datas{status} = 'checked';
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (defined $bac_datas{incOnlyTimeout} && $bac_datas{incOnlyTimeout} eq 'yes') {
|
|
|
|
$bac_datas{incOnlyTimeout} = 'checked';
|
|
|
|
}
|
|
|
|
} ## end if ($function eq 'workstn_configure1')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_verify') {
|
|
|
|
my $rec = $cdb->get('backupwk');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($rec) {
|
|
|
|
$bac_datas{status} = $rec->prop('status') || 'disabled';
|
|
|
|
}
|
|
|
|
} ## end if ($function eq 'workstn_verify')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_verify1') {
|
|
|
|
$res = '';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (!$result) {
|
|
|
|
$bac_datas{function} = $function;
|
|
|
|
}
|
|
|
|
} ## end if ($function eq 'workstn_verify1')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_restore') {
|
|
|
|
my $rec = $cdb->get('backupwk');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($rec) {
|
|
|
|
$bac_datas{status} = $rec->prop('status') || 'disabled';
|
|
|
|
}
|
|
|
|
} ## end if ($function eq 'workstn_restore')
|
2024-03-22 04:54:28 +01:00
|
|
|
$dest = "back_$function";
|
2025-01-14 13:49:31 +01:00
|
|
|
$c->stash(error => $result);
|
|
|
|
$c->stash(title => $title, bac_datas => \%bac_datas);
|
|
|
|
return $c->render(template => $dest);
|
|
|
|
} ## end sub do_display
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub do_update {
|
|
|
|
my $c = shift;
|
|
|
|
$c->app->log->info($c->log_req);
|
2025-01-14 13:49:31 +01:00
|
|
|
my $rt = $c->current_route;
|
2024-03-22 04:54:28 +01:00
|
|
|
my $function = $c->param('Function');
|
2025-01-14 13:49:31 +01:00
|
|
|
DEBUG && warn("do_update $function");
|
2024-03-22 04:54:28 +01:00
|
|
|
my %bac_datas = ();
|
|
|
|
$bac_datas{function} = $function;
|
|
|
|
my $title = $c->l('bac_BACKUP_TITLE');
|
|
|
|
my ($dest, $res, $result) = '';
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'desktop_backup') {
|
|
|
|
|
|
|
|
# should not happen !! no desktop_backup template !!
|
|
|
|
$result .= ' ** Function error for desktop backup ** !';
|
|
|
|
} ## end if ($function eq 'desktop_backup')
|
|
|
|
|
|
|
|
if ($function eq 'tape_configure') {
|
|
|
|
my $status = $c->param('Tapebackup');
|
|
|
|
my $backupHour = $c->param('BackupHour');
|
|
|
|
my $backupMin = $c->param('BackupMin');
|
|
|
|
my $bampm = $c->param('BackupAMPM');
|
|
|
|
my $reminderHour = $c->param('ReminderHour');
|
|
|
|
my $reminderMin = $c->param('ReminderMin');
|
|
|
|
my $rampm = $c->param('ReminderAMPM');
|
|
|
|
|
|
|
|
if (defined $status && $status eq "on") {
|
|
|
|
if ($backupHour =~ /^(.*)$/) {
|
|
|
|
$backupHour = $1;
|
|
|
|
} else {
|
|
|
|
$backupHour = "12";
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($backupHour < 1) || ($backupHour > 12)) {
|
|
|
|
$result .= $c->l('bac_ERR_INVALID_HOUR') . $backupHour . ' ' . $c->l('bac_BETWEEN_0_AND_12') . ' ';
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($backupMin =~ /^(.*)$/) {
|
|
|
|
$backupMin = $1;
|
|
|
|
} else {
|
|
|
|
$backupMin = "0";
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($backupMin < 0) || ($backupMin > 59)) {
|
|
|
|
$result .= $c->l('bac_ERR_INVALID_MINUTE') . $backupMin . ' ' . $c->l('bac_BETWEEN_0_AND_59') . ' ';
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($reminderHour =~ /^(.*)$/) {
|
|
|
|
$reminderHour = $1;
|
|
|
|
} else {
|
|
|
|
$reminderHour = "12";
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($reminderHour < 1) || ($reminderHour > 12)) {
|
|
|
|
$result
|
|
|
|
.= $c->l('bac_ERR_INVALID_REMINDER_HOUR')
|
|
|
|
. $reminderHour . ' '
|
|
|
|
. $c->l('bac_BETWEEN_0_AND_12') . ' ';
|
|
|
|
} ## end if (($reminderHour < 1...))
|
|
|
|
|
|
|
|
if ($reminderMin =~ /^(.*)$/) {
|
|
|
|
$reminderMin = $1;
|
|
|
|
} else {
|
|
|
|
$reminderMin = "0";
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($reminderMin < 0) || ($reminderMin > 59)) {
|
|
|
|
$result
|
|
|
|
.= $c->l('bac_ERR_INVALID_REMINDER_MINUTE')
|
|
|
|
. $reminderMin . ' '
|
|
|
|
. $c->l('bac_BETWEEN_0_AND_59') . ' ';
|
|
|
|
} ## end if (($reminderMin < 0)...)
|
|
|
|
} else {
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# service disabled no controls
|
|
|
|
}
|
|
|
|
##$result .= ' ** Blocked for testing ** !';
|
|
|
|
$res = '';
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
$res = $c->tapeBackupConfig($status, $backupHour, $backupMin, $bampm, $reminderHour, $reminderMin, $rampm);
|
|
|
|
$result .= $res unless $res eq 'OK';
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
if (defined $status && $status eq "on") {
|
|
|
|
$result
|
|
|
|
.= ( $c->l('bac_SUCCESSFULLY_ENABLED_TAPE') . ' '
|
|
|
|
. $c->l('bac_WITH_BACKUP_TIME')
|
|
|
|
. "$backupHour:$backupMin" . ' '
|
|
|
|
. $c->l('bac_WITH_REMINDER_TIME')
|
|
|
|
. "$reminderHour:$reminderMin");
|
|
|
|
} else {
|
|
|
|
$result .= $c->l('bac_SUCCESSFULLY_DISABLED');
|
|
|
|
}
|
|
|
|
$cdb->reload;
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($function eq 'tape_configure')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'tape_restore') {
|
|
|
|
my $lock_file = "/var/lock/subsys/e-smith-restore";
|
|
|
|
my $file_handle = &esmith::lockfile::LockFileOrReturn($lock_file);
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
unless ($file_handle) {
|
|
|
|
$result .= $c->l('bac_UNABLE_TO_RESTORE_CONF') . ' ' . $c->l('bac_ANOTHER_RESTORE_IN_PROGRESS');
|
|
|
|
}
|
|
|
|
##$result .= ' ** Blocked for testing ** !';
|
|
|
|
$res = '';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (!$result) {
|
|
|
|
$res = $c->tapeRestore($lock_file, $file_handle);
|
|
|
|
$result .= $res unless $res eq 'OK';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
#if ( ! $result ) {
|
|
|
|
#$result = $c->l('bac_SUCCESS');
|
|
|
|
#}
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($function eq 'tape_restore')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_configure') {
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# should not happen !!
|
|
|
|
$result .= ' ** Function error for workstation configure *** !';
|
|
|
|
} ## end if ($function eq 'workstn_configure')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_configure1') {
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
#$result .= ' ** Blocked for testing ** !';
|
|
|
|
$res = '';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (!$result) {
|
|
|
|
$res = $c->updateWorkstnBackupConfig();
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($result = $res) =~ s|^#OK#||) {
|
|
|
|
$res = 'OK';
|
|
|
|
$cdb->reload;
|
|
|
|
}
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($function eq 'workstn_configure1')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_verify') {
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# should not happen !!
|
|
|
|
$result .= ' ** Function error for workstation verify *** !';
|
|
|
|
} ## end if ($function eq 'workstn_verify')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_verify1') {
|
|
|
|
##$result .= ' ** Blocked for testing ** !';
|
|
|
|
$res = 'OK';
|
|
|
|
$result = '';
|
|
|
|
} ## end if ($function eq 'workstn_verify1')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_restore') {
|
|
|
|
##$result .= ' ** Blocked for testing ** !';
|
|
|
|
$res = 'NOK';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (!$result) {
|
|
|
|
$res = $c->workstnRestore();
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($result = $res) =~ s|^#OK#||) {
|
|
|
|
$bac_datas{restore_log} = $result;
|
|
|
|
$res = 'OK';
|
|
|
|
} else {
|
|
|
|
$c->stash(error => $result);
|
|
|
|
}
|
|
|
|
$bac_datas{function} = 'workstn_restore1';
|
|
|
|
$res = 'NEXT';
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($function eq 'workstn_restore')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_restore1') {
|
|
|
|
my $state = 'unknown';
|
|
|
|
my $rec = $rdb->get('restore');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($rec) {
|
|
|
|
$state = $rec->prop('state') || 'unknown';
|
|
|
|
}
|
|
|
|
$result .= "Restore state unexpected: $state" if ($state ne 'complete');
|
|
|
|
$res = 'NOK';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (!$result) {
|
|
|
|
$res = $c->performReboot();
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($result = $res) =~ s|^#OK#||) {
|
|
|
|
$res = 'OK';
|
|
|
|
} else {
|
|
|
|
$c->stash(error => $result);
|
|
|
|
}
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($function eq 'workstn_restore1')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_sel_restore') {
|
|
|
|
my $backupset = $c->param('Backupset');
|
|
|
|
my $filterexp = $c->param('Filterexp');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
if ($filterexp =~ /^(.*)$/) {
|
|
|
|
$filterexp = $1;
|
2025-01-14 13:49:31 +01:00
|
|
|
} else {
|
|
|
|
$filterexp = '';
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
#$result .= ' ** Blocked for testing 1 ** !';
|
|
|
|
$res = '';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (!$result) {
|
|
|
|
$bac_datas{function} = 'workstn_sel_restore1';
|
|
|
|
$bac_datas{backupset} = $backupset;
|
|
|
|
$bac_datas{filterexp} = $filterexp;
|
|
|
|
$res = 'NEXT';
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($function eq 'workstn_sel_restore')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_sel_restore1') {
|
|
|
|
$bac_datas{backupset} = $c->param('Backupset');
|
|
|
|
$bac_datas{filterexp} = $c->param('Filterexp');
|
|
|
|
my @restorefiles = @{ $c->every_param('Restorefiles') };
|
|
|
|
my $seldatebefore = $c->param('Seldatebefore');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
if ($seldatebefore =~ /^(.*)$/) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$seldatebefore = $1;
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$result .= 'Unsecure data : ' . $seldatebefore;
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
my $tymd = qr/((19|20)\d\d\/(?=\d\d\/\d\d-))?((0?[1-9]|1[0-2])\/(?=\d\d-))?((31|[123]0|[012]?[1-9])-)?/;
|
|
|
|
my $thms = qr/([01]?[0-9]|2[0-3]):([0-5][0-9])(:[0-5][0-9])?/;
|
|
|
|
$result .= " $seldatebefore : " . $c->l('bac_ERR_INVALID_SELDATE')
|
|
|
|
unless (($seldatebefore =~ m/^$tymd$thms$/) || ($seldatebefore eq ""));
|
|
|
|
##$result .= ' ** Blocked for testing 2 ** !';
|
|
|
|
$res = '';
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
$res = $c->performWorkstnSelRestore($seldatebefore, \@restorefiles); # restore log returned
|
|
|
|
|
|
|
|
if (($result = $res) =~ s|^#OK#||) {
|
|
|
|
$bac_datas{restore_log} = $result;
|
|
|
|
$res = 'OK';
|
|
|
|
} else {
|
|
|
|
$c->stash(error => $result);
|
|
|
|
}
|
|
|
|
$bac_datas{function} = 'workstn_sel_restore2';
|
|
|
|
$res = 'NEXT';
|
|
|
|
} ## end if (!$result)
|
|
|
|
} ## end if ($function eq 'workstn_sel_restore1')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($function eq 'workstn_sel_restore2') {
|
|
|
|
##$result .= ' ** Blocked for testing 3 ** !';
|
|
|
|
$res = 'OK';
|
|
|
|
$result = '';
|
|
|
|
} ## end if ($function eq 'workstn_sel_restore2')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# common part for all functions
|
|
|
|
if ($res ne 'OK') {
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($res eq 'NEXT') {
|
|
|
|
$dest = 'back_' . $bac_datas{"function"};
|
|
|
|
} else {
|
|
|
|
$c->stash(error => $result);
|
|
|
|
$dest = "back_$function";
|
|
|
|
}
|
|
|
|
$c->stash(title => $title, bac_datas => \%bac_datas);
|
|
|
|
return $c->render($dest);
|
|
|
|
} ## end if ($res ne 'OK')
|
2024-03-22 04:54:28 +01:00
|
|
|
my $message = "'Backup' $function updates DONE";
|
|
|
|
$c->app->log->info($message);
|
|
|
|
$c->flash(success => $result);
|
|
|
|
$c->redirect_to('backup');
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub do_update
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub tapeBackupConfig {
|
2025-01-14 13:49:31 +01:00
|
|
|
my ($c, $status, $backupHour, $backupMin, $bampm, $reminderHour, $reminderMin, $rampm) = @_;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
if (defined $status && $status eq "on") {
|
2025-01-14 13:49:31 +01:00
|
|
|
$backupMin = sprintf("%02d", $backupMin);
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($bampm =~ /^(.*)$/) {
|
|
|
|
$bampm = $1;
|
|
|
|
} else {
|
|
|
|
$bampm = "AM";
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# convert to 24 hour time
|
|
|
|
$backupHour = $backupHour % 12;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($bampm eq "PM") {
|
|
|
|
$backupHour = $backupHour + 12;
|
|
|
|
}
|
|
|
|
$reminderMin = sprintf("%02d", $reminderMin);
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($rampm =~ /^(.*)$/) {
|
|
|
|
$rampm = $1;
|
|
|
|
} else {
|
|
|
|
$rampm = "AM";
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# convert to 24 hour time
|
|
|
|
$reminderHour = $reminderHour % 12;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($rampm eq "PM") {
|
|
|
|
$reminderHour = $reminderHour + 12;
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# variables passed validity checks, set configuration database values
|
|
|
|
my $oldUnsav = $cdb->get('UnsavedChanges')->value;
|
|
|
|
my $rec = $cdb->get('backup');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
unless (defined $rec) {
|
|
|
|
$rec = $cdb->new_record('backup', { type => 'service' });
|
|
|
|
}
|
|
|
|
$rec->set_prop('status', 'enabled');
|
|
|
|
my $module = $rec->prop('Program');
|
|
|
|
|
|
|
|
# The default e-smith backup program is flexbackup.
|
|
|
|
unless (defined $module) {
|
|
|
|
$module = "flexbackup";
|
|
|
|
} elsif ($module eq '') {
|
|
|
|
$module = "flexbackup";
|
|
|
|
}
|
|
|
|
$rec->set_prop('Program', $module);
|
|
|
|
$rec->set_prop('backupTime', "$backupHour:$backupMin");
|
|
|
|
$rec->set_prop('reminderTime', "$reminderHour:$reminderMin");
|
|
|
|
$cdb->get('UnsavedChanges')->set_value($oldUnsav);
|
|
|
|
system("/sbin/e-smith/signal-event", "conf-backup") == 0
|
|
|
|
or return ($c->l('bac_ERR_CONF_BACKUP'), "\n");
|
|
|
|
return 'OK';
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# set service to disabled
|
|
|
|
my $oldUnsav = $cdb->get('UnsavedChanges')->value;
|
|
|
|
my $rec = $cdb->get('backup');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
unless ($rec) {
|
|
|
|
$rec = $cdb->new_record('backup', { type => 'service' });
|
|
|
|
}
|
|
|
|
$rec->set_prop('status', 'disabled');
|
|
|
|
$cdb->get('UnsavedChanges')->set_value($oldUnsav);
|
|
|
|
system("/sbin/e-smith/signal-event", "conf-backup") == 0
|
|
|
|
or return ($c->l('bac_ERR_CONF_BACKUP') . "\n");
|
|
|
|
return 'OK';
|
|
|
|
} ## end else [ if (defined $status &&...)]
|
2024-03-22 04:54:28 +01:00
|
|
|
return undef;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub tapeBackupConfig
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub tapeRestore {
|
|
|
|
my ($c, $lock_file, $file_handle) = @_;
|
|
|
|
my $rec = $rdb->get('restore');
|
|
|
|
$rec->set_prop('state', 'running');
|
|
|
|
$rec->set_prop('start', time);
|
|
|
|
my $child;
|
|
|
|
|
|
|
|
if ($child = fork) {
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
# Parent
|
|
|
|
$SIG{'CHLD'} = 'IGNORE';
|
|
|
|
&esmith::lockfile::UnlockFile($file_handle);
|
|
|
|
return 'OK';
|
2024-03-22 04:54:28 +01:00
|
|
|
} elsif (defined $child) {
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
# Child
|
|
|
|
# Re-establish the lock. Wait till it is relinquished by the parent.
|
|
|
|
$file_handle = &esmith::lockfile::LockFileOrWait($lock_file);
|
|
|
|
|
|
|
|
# Close STDOUT so that the web server connection is closed.
|
|
|
|
close STDOUT;
|
|
|
|
|
|
|
|
# Now reopen STDOUT for the child. Redirect it to STDERR.
|
|
|
|
open(STDOUT, ">&STDERR");
|
|
|
|
|
|
|
|
unless (system("/sbin/e-smith/signal-event", "pre-restore") == 0) {
|
|
|
|
$rec->set_prop('errmsg', $c->l('bac_ERR_PRE_RESTORE'));
|
|
|
|
$rec->delete_prop('state');
|
|
|
|
die($c->l('bac_ERR_PRE_RESTORE'), "\n");
|
|
|
|
} ## end unless (system("/sbin/e-smith/signal-event"...))
|
|
|
|
|
|
|
|
unless (system("/sbin/e-smith/signal-event", "restore-tape") == 0) {
|
|
|
|
$rec->set_prop('errmsg', $c->l('bac_ERR_RESTORING_FROM_TAPE'));
|
|
|
|
$rec->delete_prop('state');
|
|
|
|
die($c->l('bac_ERR_RESTORING_FROM_TAPE') . "\n");
|
|
|
|
} ## end unless (system("/sbin/e-smith/signal-event"...))
|
|
|
|
|
|
|
|
#----------------------------------------
|
|
|
|
# regenerate configuration files
|
|
|
|
#----------------------------------------
|
|
|
|
unless (system("/usr/sbin/groupmod", "-g", "$www_gid", "www") == 0) {
|
|
|
|
$rec->set_prop('errmsg', $rec->prop('errmsg') . ', ' . $c->l('bac_ERR_RESTORING_GID'));
|
|
|
|
warn($c->l('bac_ERR_RESTORING_GID') . "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
unless (system("/usr/sbin/usermod", "-g", "$www_gid", "www") == 0) {
|
|
|
|
$rec->set_prop('errmsg', $rec->prop('errmsg') . ', ' . $c->l('bac_ERR_RESTORING_INITIAL_GRP'));
|
|
|
|
warn($c->l('bac_ERR_RESTORING_INITIAL_GRP') . "\n");
|
|
|
|
}
|
|
|
|
esmith::util::backgroundCommand(0, "/sbin/e-smith/signal-event", "post-upgrade");
|
|
|
|
|
|
|
|
#unless(system("/sbin/e-smith/signal-event", "post-upgrade") == 0) {
|
|
|
|
# $rec->set_prop('errmsg', $rec->prop('errmsg').', '.
|
|
|
|
# $c->l('bac_ERR_UPDATING_CONF_AFTER_TAPE_RESTORE'));
|
|
|
|
# $rec->delete_prop('state');
|
|
|
|
# die ($c->l('bac_ERR_UPDATING_CONF_AFTER_TAPE_RESTORE'));
|
|
|
|
#}
|
|
|
|
my $finish = time;
|
|
|
|
$rec->set_prop('state', 'complete');
|
|
|
|
$rec->set_prop('finish', $finish);
|
|
|
|
my $start = $rec->prop('start');
|
|
|
|
$start = scalar localtime($start);
|
|
|
|
$finish = scalar localtime($finish);
|
|
|
|
&esmith::lockfile::UnlockFile($file_handle);
|
|
|
|
exit;
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# Error
|
|
|
|
$rec->delete_prop('state');
|
|
|
|
$rec->set_prop('errmsg', $c->l('bac_COULD_NOT_FORK'));
|
|
|
|
die($c->l("bac_COULD_NOT_FORK") . " $!\n");
|
|
|
|
} ## end else [ if ($child = fork) ]
|
|
|
|
} ## end sub tapeRestore
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub workstnBackupConfig {
|
|
|
|
|
|
|
|
# called by template
|
|
|
|
my ($c) = @_;
|
|
|
|
my $out;
|
|
|
|
my $backupwk_status;
|
|
|
|
my $enabledIncOnlyTimeout = "";
|
2025-01-14 13:49:31 +01:00
|
|
|
my $backupwkLogin = 'backup';
|
|
|
|
my $backupwkPassword = 'backup';
|
|
|
|
my $backupwkStation = 'host';
|
|
|
|
my $backupwkFolder = 'share';
|
|
|
|
my $backupwkMount = '/mnt/smb';
|
2024-03-22 04:54:28 +01:00
|
|
|
my $setsNumber;
|
|
|
|
my $filesinset;
|
|
|
|
my $backupwkTime;
|
|
|
|
my $backupwkTimeout;
|
|
|
|
my $backupwkIncOnlyTimeout;
|
|
|
|
my $VFSType;
|
|
|
|
my $compression;
|
|
|
|
my $dof;
|
|
|
|
my @dlabels = split(' ', $c->l('bac_DOW'));
|
|
|
|
|
|
|
|
# Obtain backup informations from configuration
|
|
|
|
my $rec = $cdb->get('backupwk');
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($rec) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$backupwkTime = $rec->prop('BackupTime') || '2:00';
|
|
|
|
$backupwkLogin = $rec->prop('Login') || 'backup';
|
|
|
|
$backupwkPassword = $rec->prop('Password') || 'backup';
|
|
|
|
$backupwkStation = $rec->prop('SmbHost') || 'host';
|
|
|
|
$backupwkFolder = $rec->prop('SmbShare') || 'share';
|
|
|
|
$backupwkMount = $rec->prop('Mount') || '/mnt/smb';
|
|
|
|
$VFSType = $rec->prop('VFSType') || 'cifs';
|
|
|
|
$setsNumber = $rec->prop('SetsMax') || '1';
|
|
|
|
$filesinset = $rec->prop('DaysInSet') || '1';
|
|
|
|
$backupwkTimeout = $rec->prop('Timeout') || '12';
|
|
|
|
$backupwkIncOnlyTimeout = $rec->prop('IncOnlyTimeout') || 'yes';
|
|
|
|
$compression = $rec->prop('Compression') || '0';
|
|
|
|
$dof = (defined $rec->prop('FullDay')) ? $rec->prop('FullDay') : '7';
|
|
|
|
$backupwk_status = $rec->prop('status');
|
|
|
|
} ## end if ($rec)
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
if ($rec) {
|
|
|
|
if ($VFSType eq 'usb') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_USB') . ' ' . $backupwkFolder . '<br/>';
|
2024-03-22 04:54:28 +01:00
|
|
|
} elsif ($VFSType eq 'mnt') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_MNT') . ' ' . $backupwkMount . '<br/>';
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_HOST') . ' ' . $backupwkStation . ' ';
|
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_VFSTYPE') . ' ' . $VFSType . '<br/>';
|
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_SHARE') . ' ' . $backupwkFolder . '<br/>';
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($VFSType eq 'cifs') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$out .= $c->l('bac_LOGIN') . ' ' . $backupwkLogin . '<br/>';
|
|
|
|
$out .= $c->l('PASSWORD') . ' ********<br/>';
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_SETSNUM') . ' ' . $setsNumber . '<br/>';
|
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_DAYSINSET') . ' ' . $filesinset . '<br/>';
|
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_COMPRESSION') . ' ' . $compression . '<br/>';
|
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_TOD') . ' ' . $backupwkTime . '<br/>';
|
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_TIMEOUT') . ' ' . $backupwkTimeout . ' ' . $c->l('bac_HOURS');
|
|
|
|
|
|
|
|
if ($backupwkIncOnlyTimeout eq 'yes') {
|
|
|
|
$out .= $c->l('bac_WORKSTN_BACKUP_INCONLY_TIMEOUT');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
$out .= '<br/>';
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($dof eq '7') {
|
|
|
|
$out .= $c->l('bac_WORKSTN_FULL_BACKUP_EVERYDAY') . '<br/>';
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$out .= $c->l('bac_WORKSTN_FULL_BACKUP_DAY') . ' ' . $dlabels[$dof] . '<br/>';
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$out = $c->l('bac_WORKSTN_BACKUP_NOT_CONFIGURED');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
return $out;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub workstnBackupConfig
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub workstnVerify {
|
|
|
|
my ($c) = @_;
|
|
|
|
my $out;
|
|
|
|
my $backupwkrec = $cdb->get('backupwk');
|
2025-01-14 13:49:31 +01:00
|
|
|
my $smbhost = $backupwkrec->prop('SmbHost');
|
|
|
|
my $smbshare = $backupwkrec->prop('SmbShare');
|
|
|
|
my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb';
|
2024-03-22 04:54:28 +01:00
|
|
|
my $key;
|
|
|
|
my $error_message;
|
2025-01-14 13:49:31 +01:00
|
|
|
my $id = $backupwkrec->prop('Id')
|
|
|
|
|| $cdb->get('SystemName')->value . '.' . $cdb->get('DomainName')->value;
|
2024-03-22 04:54:28 +01:00
|
|
|
my $err;
|
|
|
|
my $VFSType = $backupwkrec->prop('VFSType') || 'cifs';
|
2025-01-14 13:49:31 +01:00
|
|
|
my $verifyref = $c->param('Backupset');
|
|
|
|
$mntdir = "/$smbshare" if ($VFSType eq 'usb');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# Mounting backup shared folder
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType);
|
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($error_message) {
|
2025-01-14 13:49:31 +01:00
|
|
|
return $error_message . ' ' . $id;
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Test if backup subdirectory for our server
|
|
|
|
my $mntbkdir = $mntdir . "/$id";
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
unless (-d $mntbkdir) {
|
|
|
|
$error_message = $c->l('bac_ERR_NO_HOST_DIR') . "\n";
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
|
|
|
return $error_message . ' ' . $id;
|
|
|
|
} ## end unless (-d $mntbkdir)
|
2024-03-22 04:54:28 +01:00
|
|
|
my $fullverify = $c->param('Verifyall') || '';
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($fullverify eq "on") {
|
|
|
|
|
|
|
|
# Test all backups needed to full restore
|
2024-03-22 04:54:28 +01:00
|
|
|
my %backupsetfiles = ();
|
2025-01-14 13:49:31 +01:00
|
|
|
my @restorefiles;
|
2024-03-22 04:54:28 +01:00
|
|
|
my $set = $verifyref;
|
|
|
|
$set =~ s/\/[^\/]*$//;
|
|
|
|
my $backupsetlist = sub {
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($_ =~ /\.dar/) {
|
|
|
|
my $backupref = $File::Find::name;
|
|
|
|
$backupref =~ s/\.[0-9]+\.dar//;
|
|
|
|
$_ =~ s/\..*\.dar//;
|
|
|
|
$_ =~ s/.*-//;
|
|
|
|
$backupsetfiles{$_} = $backupref;
|
|
|
|
} ## end if ($_ =~ /\.dar/)
|
|
|
|
};
|
|
|
|
|
|
|
|
# find list of available backups and verify
|
|
|
|
# it contains all backups needed for full restore
|
|
|
|
find { wanted => \&$backupsetlist, untaint => 1, untaint_pattern => qr|^([-+@\w\s./]+)$| }, $set;
|
|
|
|
my $key;
|
|
|
|
my $num = 0;
|
|
|
|
|
|
|
|
foreach $key (sort keys %backupsetfiles) {
|
|
|
|
push @restorefiles, $backupsetfiles{$key};
|
|
|
|
|
|
|
|
if ($num == 0) {
|
|
|
|
unless ($backupsetfiles{$key} =~ /\/full-/) {
|
|
|
|
$out .= $c->l('bac_ERR_NO_FULL_BACKUP');
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
my $numf = sprintf("%03d", $num);
|
|
|
|
|
|
|
|
unless ($backupsetfiles{$key} =~ /\/inc-$numf-/) {
|
|
|
|
$out .= $c->l('bac_ERR_NO_INC_BACKUP') . " " . $numf;
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
} ## end else [ if ($num == 0) ]
|
|
|
|
$num++;
|
|
|
|
last if ($backupsetfiles{$key} eq $verifyref);
|
|
|
|
} ## end foreach $key (sort keys %backupsetfiles)
|
|
|
|
|
|
|
|
if (open(RD, "-|")) {
|
|
|
|
$out .= '<b>' . $c->l('bac_TESTING_NEEDED_BACKUPS_FOR_RESTORE') . '</b><UL>';
|
|
|
|
|
|
|
|
while (<RD>) {
|
|
|
|
$out .= "<li>$_</li>";
|
|
|
|
}
|
|
|
|
$out .= '</UL>';
|
|
|
|
my $message;
|
|
|
|
$out .= '<b>';
|
|
|
|
|
|
|
|
if (!close RD) {
|
|
|
|
$out .= $c->l('bac_RESTORE_VERIFY_FAILED');
|
|
|
|
} else {
|
|
|
|
$out .= $c->l('bac_VERIFY_COMPLETE');
|
|
|
|
}
|
|
|
|
$out .= '</b>';
|
|
|
|
} else {
|
|
|
|
select(STDOUT);
|
|
|
|
$| = 1;
|
|
|
|
my $file;
|
|
|
|
|
|
|
|
foreach $file (@restorefiles) {
|
|
|
|
if ($file =~ /^(.*)$/) {
|
|
|
|
$file = $1;
|
|
|
|
} else {
|
|
|
|
$error_message = "Unsecure data : $file\n";
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
|
|
|
die($error_message);
|
|
|
|
}
|
|
|
|
print $c->l('bac_TESTED_BACKUP') . ' ' . $file;
|
|
|
|
system("/usr/bin/dar", "-Q", "--test", "$file", "--noconf");
|
|
|
|
} ## end foreach $file (@restorefiles)
|
|
|
|
$error_message = $c->bunmount($mntdir, $VFSType);
|
|
|
|
die($error_message) if $error_message;
|
|
|
|
exit(0);
|
|
|
|
} ## end else [ if (open(RD, "-|")) ]
|
|
|
|
|
|
|
|
#return;
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
# verify selected backup only
|
|
|
|
# and display files saved in the backup
|
|
|
|
my $backupkey = $verifyref;
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($backupkey =~ /^(.*)$/) {
|
|
|
|
$backupkey = $1;
|
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message = "Unsecure data : $backupkey\n";
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
|
|
|
die($error_message);
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (open(RD, "-|")) {
|
|
|
|
$out .= '<b>' . $c->l('bac_FILES_IN_BACKUP') . '</b><UL>';
|
|
|
|
my $complete = 0;
|
|
|
|
|
|
|
|
while (<RD>) {
|
|
|
|
$complete++ if /etc\/samba\/smbpasswd$/;
|
|
|
|
$out .= "<li>$_</li>";
|
|
|
|
}
|
|
|
|
$out .= '</UL>';
|
|
|
|
my $status
|
|
|
|
= close RD
|
|
|
|
? (
|
|
|
|
$complete
|
|
|
|
? $c->l('bac_VERIFY_COMPLETE')
|
|
|
|
: $c->l('bac_BACKUP_FILE_INCOMPLETE')
|
|
|
|
)
|
|
|
|
: ($c->l('bac_ERROR_READING_FILE') . ' : ' . $backupkey);
|
|
|
|
$out .= "<b> $status </b>";
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
|
|
|
select(STDOUT);
|
|
|
|
$| = 1;
|
2025-01-14 13:49:31 +01:00
|
|
|
system("/usr/bin/dar", "-Q", "--list", "$backupkey", "--noconf") == 0
|
|
|
|
or die($c->l('bac_ERR_EXTRACT') . " : " . $!);
|
|
|
|
$error_message = $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
die($error_message) if $error_message;
|
|
|
|
exit(0);
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end else [ if (open(RD, "-|")) ]
|
|
|
|
} ## end else [ if ($fullverify eq "on")]
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return $out;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub workstnVerify
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub workstnRestore {
|
|
|
|
my ($c) = @_;
|
|
|
|
my $out;
|
|
|
|
my $restoreref = $c->param('Backupset');
|
2025-01-14 13:49:31 +01:00
|
|
|
my $set = $restoreref;
|
2024-03-22 04:54:28 +01:00
|
|
|
$set =~ s/\/[^\/]*$//;
|
|
|
|
my %backupsetfiles = ();
|
|
|
|
my @restorefiles;
|
|
|
|
my $backupsetlist = sub {
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if ($_ =~ /\.dar/) {
|
|
|
|
my $backupref = $File::Find::name;
|
2024-03-22 04:54:28 +01:00
|
|
|
$backupref =~ s/\.[0-9]+\.dar//;
|
|
|
|
$_ =~ s/\..*\.dar//;
|
2025-01-14 13:49:31 +01:00
|
|
|
$_ =~ s/.*-//;
|
|
|
|
$backupsetfiles{$_} = $backupref;
|
|
|
|
} ## end if ($_ =~ /\.dar/)
|
2024-03-22 04:54:28 +01:00
|
|
|
};
|
2025-01-14 13:49:31 +01:00
|
|
|
my $lock_file = "/var/lock/subsys/e-smith-restore";
|
2024-03-22 04:54:28 +01:00
|
|
|
my $file_handle = &esmith::lockfile::LockFileOrReturn($lock_file);
|
|
|
|
|
|
|
|
unless ($file_handle) {
|
|
|
|
return "$c->l('bac_RESTORE_CANNOT_PROCEED') <br> ($c->l('bac_ANOTHER_RESTORE_IN_PROGRESS')";
|
|
|
|
}
|
|
|
|
my $backupwkrec = $cdb->get('backupwk');
|
2025-01-14 13:49:31 +01:00
|
|
|
my $id = $backupwkrec->prop('Id')
|
|
|
|
|| $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value;
|
|
|
|
my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb';
|
2024-03-22 04:54:28 +01:00
|
|
|
my $VFSType = $backupwkrec->prop('VFSType') || 'cifs';
|
|
|
|
my $smbhost = $backupwkrec->prop('SmbHost');
|
|
|
|
my $smbshare = $backupwkrec->prop('SmbShare');
|
2025-01-14 13:49:31 +01:00
|
|
|
$mntdir = "/$smbshare" if ($VFSType eq 'usb');
|
2024-03-22 04:54:28 +01:00
|
|
|
my $err;
|
|
|
|
my $error_message;
|
|
|
|
|
|
|
|
# Mounting backup shared folder
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType);
|
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($error_message) {
|
|
|
|
return "$c->l('bac_RESTORE_CANNOT_PROCEED') $error_message : $id";
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
# Test if backup subdirectory for our server
|
|
|
|
my $mntbkdir = $mntdir . "/$id";
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
unless (-d $mntbkdir) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message = $c->l('bac_ERR_NO_HOST_DIR') . "\n";
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return "$c->l('bac_RESTORE_CANNOT_PROCEED') $error_message : $id";
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end unless (-d $mntbkdir)
|
|
|
|
|
|
|
|
# finding list of available backups
|
2024-03-22 04:54:28 +01:00
|
|
|
# and verifying all needed backup files are available
|
2025-01-14 13:49:31 +01:00
|
|
|
find { wanted => \&$backupsetlist, untaint => 1, untaint_pattern => qr|^([-+@\w\s./]+)$| }, $set;
|
2024-03-22 04:54:28 +01:00
|
|
|
my $key;
|
|
|
|
my $num = 0;
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
foreach $key (sort keys %backupsetfiles) {
|
2025-01-14 13:49:31 +01:00
|
|
|
push @restorefiles, $backupsetfiles{$key};
|
|
|
|
|
|
|
|
if ($num == 0) {
|
|
|
|
unless ($backupsetfiles{$key} =~ /\/full-/) {
|
|
|
|
return "$c->l('bac_RESTORE_CANNOT_PROCEED') $c->l('bac_ERR_NO_FULL_BACKUP')";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
my $numf = sprintf("%03d", $num);
|
|
|
|
|
|
|
|
unless ($backupsetfiles{$key} =~ /\/inc-$numf-/) {
|
|
|
|
return "$c->l('bac_RESTORE_CANNOT_PROCEED') $c->l('bac_ERR_NO_INC_BACKUP') . $numf";
|
|
|
|
}
|
|
|
|
} ## end else [ if ($num == 0) ]
|
|
|
|
$num++;
|
|
|
|
last if ($backupsetfiles{$key} eq $restoreref);
|
|
|
|
} ## end foreach $key (sort keys %backupsetfiles)
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# backup is online, restoring now
|
2024-03-22 04:54:28 +01:00
|
|
|
my $rec = $rdb->get('restore');
|
2025-01-14 13:49:31 +01:00
|
|
|
$rec->set_prop('state', 'running');
|
2024-03-22 04:54:28 +01:00
|
|
|
$rec->set_prop('start', time);
|
|
|
|
$cdb->get('bootstrap-console')->set_prop('Run', 'yes');
|
|
|
|
|
|
|
|
unless (system("/sbin/e-smith/signal-event", "pre-restore") == 0) {
|
2025-01-14 13:49:31 +01:00
|
|
|
return "$c->l('bac_OPERATION_STATUS_REPORT') $c->l('bac_ERR_PRE_RESTORE')";
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
$| = 1;
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if (open(RD, "-|")) {
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
#-----------------------------------------------------
|
|
|
|
# restore system from uploaded workstation backup file
|
|
|
|
#-----------------------------------------------------
|
|
|
|
$out .= $c->l('bac_FILES_HAVE_BEEN_RESTORED') . "\n";
|
|
|
|
$out .= '<UL>';
|
|
|
|
my $complete = 0;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
while (<RD>) {
|
|
|
|
$complete++ if /etc\/samba\/smbpasswd$/;
|
|
|
|
$out .= "<li>$_</li>\n";
|
|
|
|
}
|
|
|
|
$out .= '</UL>';
|
|
|
|
my $message;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (!close RD) {
|
|
|
|
$message = $c->l('bac_RESTORE_FAILED_MSG');
|
|
|
|
} else {
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
#-----------------------------------------------------
|
|
|
|
# if restore completed, regenerate configuration files
|
|
|
|
#-----------------------------------------------------
|
|
|
|
if ($complete) {
|
|
|
|
$out .= $c->l('bac_RESTORE_COMPLETE');
|
|
|
|
system("/usr/sbin/groupmod", "-g", "$www_gid", "www") == 0
|
|
|
|
or warn($c->l('bac_ERR_RESTORING_GID') . "\n");
|
|
|
|
system("/usr/sbin/usermod", "-g", "$www_gid", "www") == 0
|
|
|
|
or warn($c->l('bac_ERR_RESTORING_INITIAL_GRP') . "\n");
|
|
|
|
esmith::util::backgroundCommand(0, "/sbin/e-smith/signal-event", "post-upgrade");
|
|
|
|
|
|
|
|
# system("/sbin/e-smith/signal-event", "post-upgrade") == 0
|
|
|
|
# or die ($c->l('bac_ERROR_UPDATING_CONFIGURATION')."\n");
|
|
|
|
} else {
|
|
|
|
$message = $c->l('bac_RESTORE_FAILED');
|
|
|
|
}
|
|
|
|
} ## end else [ if (!close RD) ]
|
|
|
|
return $message if $message;
|
|
|
|
$rec->set_prop('state', 'complete');
|
|
|
|
$rec->set_prop('finish', time);
|
|
|
|
&esmith::lockfile::UnlockFile($file_handle);
|
|
|
|
} else {
|
|
|
|
select(STDOUT);
|
|
|
|
$| = 1;
|
|
|
|
my $file;
|
|
|
|
|
|
|
|
foreach $file (@restorefiles) {
|
|
|
|
if ($file =~ /^(.*)$/) {
|
|
|
|
$file = $1;
|
|
|
|
} else {
|
|
|
|
$error_message = "Unsecure data : $file\n";
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
|
|
|
die($error_message);
|
|
|
|
}
|
|
|
|
system("/usr/bin/dar", "-Q", "-x", "$file", "-v", "-N", "-R", "/", "-wa");
|
|
|
|
} ## end foreach $file (@restorefiles)
|
|
|
|
$error_message = $c->bunmount($mntdir, $VFSType);
|
|
|
|
die($error_message) if $error_message;
|
|
|
|
exit(0);
|
|
|
|
} ## end else [ if (open(RD, "-|")) ]
|
2024-03-22 04:54:28 +01:00
|
|
|
$rdb->reload;
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return '#OK#' . $out;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub workstnRestore
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub workstnSelRestore() {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
|
|
|
my $rec = $cdb->get('backupwk');
|
2024-03-22 04:54:28 +01:00
|
|
|
my %backupfiles = ();
|
2025-01-14 13:49:31 +01:00
|
|
|
my $mntdir = $rec->prop('Mount') || '/mnt/smb';
|
2024-03-22 04:54:28 +01:00
|
|
|
my $mntbkdir;
|
|
|
|
my $key;
|
2025-01-14 13:49:31 +01:00
|
|
|
my $id = $rec->prop('Id')
|
|
|
|
|| $cdb->get('SystemName')->value . '.' . $cdb->get('DomainName')->value;
|
2024-03-22 04:54:28 +01:00
|
|
|
my %blabels = ();
|
|
|
|
my @blabels;
|
|
|
|
my $backups = 0;
|
|
|
|
my $filterexp;
|
2025-01-14 13:49:31 +01:00
|
|
|
my $VFSType = $rec->prop('VFSType') || 'cifs';
|
|
|
|
my $smbhost = $rec->prop('SmbHost');
|
2024-03-22 04:54:28 +01:00
|
|
|
my $smbshare = $rec->prop('SmbShare');
|
2025-01-14 13:49:31 +01:00
|
|
|
$mntdir = "/$smbshare" if ($VFSType eq 'usb');
|
2024-03-22 04:54:28 +01:00
|
|
|
my $err;
|
|
|
|
my $error_message;
|
|
|
|
my $setbackuplist = sub {
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if ($_ =~ /\.dar/) {
|
|
|
|
my $dir = $File::Find::dir;
|
|
|
|
my $backupref;
|
|
|
|
$dir =~ s/$mntbkdir\///;
|
2024-03-22 04:54:28 +01:00
|
|
|
$_ =~ s/\..*\.dar//;
|
2025-01-14 13:49:31 +01:00
|
|
|
$backupref = $_;
|
|
|
|
$_ =~ s/.*-//;
|
|
|
|
@{ $backupfiles{$_} }[0] = $dir;
|
|
|
|
@{ $backupfiles{$_} }[1] = $backupref;
|
|
|
|
} ## end if ($_ =~ /\.dar/)
|
2024-03-22 04:54:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
# Mounting backup shared folder
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType);
|
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($error_message) {
|
|
|
|
return ($error_message, $id);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test if backup subdirectory for our server
|
|
|
|
$mntbkdir = $mntdir . "/$id";
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
unless (-d $mntbkdir) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message = $c->l('bac_ERR_NO_HOST_DIR') . "\n";
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return ($error_message, $id);
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end unless (-d $mntbkdir)
|
2024-03-22 04:54:28 +01:00
|
|
|
my $catalog = "$mntbkdir/dar-catalog";
|
2025-01-14 13:49:31 +01:00
|
|
|
my $i = 0;
|
|
|
|
my $j = 0;
|
2024-03-22 04:54:28 +01:00
|
|
|
my @bknum;
|
|
|
|
my @setd;
|
|
|
|
my @bkname;
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# update backups list from current catalog
|
|
|
|
open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |");
|
2024-03-22 04:54:28 +01:00
|
|
|
$i = 0;
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
while (<DAR_LIST>) {
|
|
|
|
next unless m/set/;
|
|
|
|
chomp;
|
|
|
|
($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3);
|
|
|
|
$i++;
|
|
|
|
} ## end while (<DAR_LIST>)
|
|
|
|
close(DAR_LIST);
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# set drop down list of backups
|
|
|
|
push @blabels, "0";
|
|
|
|
$blabels{"0"} = $c->l('ALL_BACKUPS');
|
|
|
|
$j = 0;
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
while ($j < $i) {
|
|
|
|
push @blabels, $bknum[$j];
|
|
|
|
$blabels{ $bknum[$j] } = $bkname[$j];
|
|
|
|
$j++;
|
|
|
|
} ## end while ($j < $i)
|
|
|
|
} ## end sub workstnSelRestore
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub updateWorkstnBackupConfig {
|
|
|
|
my ($c) = @_;
|
2025-01-14 13:49:31 +01:00
|
|
|
my $status = $c->param('Workstnbackup') || "";
|
2024-03-22 04:54:28 +01:00
|
|
|
my $inconly = $c->param('IncOnlyTimeout');
|
2025-01-14 13:49:31 +01:00
|
|
|
my $dof = $c->param('Dof');
|
2024-03-22 04:54:28 +01:00
|
|
|
my $ampm;
|
|
|
|
my $incOnlyTimeout;
|
|
|
|
my $rec = $cdb->get('backupwk');
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
unless (defined $rec) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$rec = $cdb->new_record('backupwk', { type => 'service' });
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
my $backupwkMount = $rec->prop('Mount') || '/mnt/smb';
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
unless ($status eq 'on') {
|
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
# set service to disabled
|
|
|
|
my $old = $cdb->get('UnsavedChanges')->value;
|
|
|
|
$rec->set_prop('status', 'disabled');
|
|
|
|
$cdb->get('UnsavedChanges')->set_value($old);
|
|
|
|
system("/sbin/e-smith/signal-event", "conf-backup") == 0
|
2025-01-14 13:49:31 +01:00
|
|
|
or die($c->l('bac_ERR_CONF_BACKUP') . "\n");
|
|
|
|
return '#OK#' . $c->l('bac_SUCCESSFULLY_DISABLED_WORKSTN');
|
|
|
|
} ## end unless ($status eq 'on')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
#--------------------------------------------------
|
|
|
|
# Untaint parameters and check for validity
|
|
|
|
#--------------------------------------------------
|
2024-03-22 04:54:28 +01:00
|
|
|
my $VFSType = $c->param('VFSType');
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if ($VFSType eq 'nousb') {
|
|
|
|
return $c->l('bac_ERR_NO_USB_DISK');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($VFSType eq 'nomnt') {
|
|
|
|
return $c->l('bac_ERR_NO_MOUNTED_DISK');
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
my $backupwkStation = $c->param('BackupwkStation');
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($VFSType =~ m/usb|mnt/s) { $backupwkStation = 'localhost' }
|
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($backupwkStation =~ /^\s*(\S+)\s*$/) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$backupwkStation = $1;
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
|
|
|
$backupwkStation = "";
|
|
|
|
}
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($backupwkStation eq "") {
|
|
|
|
return $c->l('bac_ERR_INVALID_WORKSTN');
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
my $backupwkFolder = $c->param('BackupwkFolder');
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($backupwkFolder =~ /^(.*)$/) {
|
|
|
|
$backupwkFolder = $1;
|
|
|
|
} else {
|
|
|
|
$backupwkFolder = '';
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if ($VFSType eq 'usb') {
|
2024-03-22 04:54:28 +01:00
|
|
|
$backupwkFolder = 'media/' . $backupwkFolder;
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if ($VFSType eq 'mnt') {
|
|
|
|
$backupwkMount = $backupwkFolder;
|
|
|
|
if (checkMount($backupwkMount)) { $backupwkFolder = ''; }
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$backupwkFolder =~ s/^\///; # remove leading /
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($backupwkFolder eq '') {
|
|
|
|
return $c->l('bac_ERR_INVALID_FOLDER');
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
my $backupwkLogin = $c->param('BackupwkLogin') || '';
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($backupwkLogin =~ /^(.*)$/) {
|
|
|
|
$backupwkLogin = $1;
|
|
|
|
} else {
|
|
|
|
$backupwkLogin = "";
|
|
|
|
}
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($backupwkLogin eq "") && ($VFSType eq 'cifs')) {
|
|
|
|
return $c->l('bac_ERR_INVALID_LOGIN');
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
my $backupwkPassword = $c->param('BackupwkPassword') || '';
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($backupwkPassword =~ /^(.*)$/) {
|
|
|
|
$backupwkPassword = $1;
|
|
|
|
} else {
|
|
|
|
$backupwkPassword = "";
|
|
|
|
}
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($backupwkPassword eq "") && ($VFSType eq 'cifs')) {
|
|
|
|
return $c->l('bac_ERR_INVALID_PASSWORD');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
my $setsNumber = $c->param('SetsNumber');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
unless ($setsNumber > 0) {
|
|
|
|
return $c->l('bac_ERR_INVALID_SETS_NUMBERFOLDER');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
my $filesinset = $c->param('Filesinset');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
unless ($filesinset > 0) {
|
|
|
|
return $c->l('bac_ERR_INVALID_FILES_IN_SET_NUMBER');
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
my $timeout = $c->param('BackupwkTimeout');
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($timeout eq '') || ($timeout == 0)) { $timeout = 24 }
|
|
|
|
|
|
|
|
if (($timeout < 1) || ($timeout > 24)) {
|
|
|
|
return $c->l('bac_ERR_INVALID_TIMEOUT');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $inconly && $inconly eq 'on') {
|
2025-01-14 13:49:31 +01:00
|
|
|
$incOnlyTimeout = 'yes';
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$incOnlyTimeout = 'no';
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
my $compression = $c->param('Compression');
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($compression < 0) || ($compression > 9)) {
|
|
|
|
return $c->l('bac_ERR_INVALID_COMPRESSION');
|
|
|
|
}
|
|
|
|
$rec->set_prop('SmbHost', $backupwkStation);
|
|
|
|
$rec->set_prop('SmbShare', $backupwkFolder);
|
|
|
|
$rec->set_prop('Mount', $backupwkMount);
|
|
|
|
$rec->set_prop('Login', $backupwkLogin);
|
|
|
|
$rec->set_prop('Password', $backupwkPassword);
|
|
|
|
$rec->set_prop('SetsMax', $setsNumber);
|
|
|
|
$rec->set_prop('DaysInSet', $filesinset);
|
|
|
|
$rec->set_prop('Timeout', $timeout);
|
2024-03-22 04:54:28 +01:00
|
|
|
$rec->set_prop('IncOnlyTimeout', $incOnlyTimeout);
|
2025-01-14 13:49:31 +01:00
|
|
|
$rec->set_prop('Compression', $compression);
|
|
|
|
$rec->set_prop('FullDay', $dof);
|
|
|
|
$rec->set_prop('VFSType', $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
my $module = $rec->prop('Program');
|
|
|
|
|
|
|
|
# The default workstation backup program is dar.
|
|
|
|
unless (defined $module) {
|
|
|
|
$module = 'dar';
|
|
|
|
} elsif ($module eq '') {
|
|
|
|
$module = 'dar';
|
|
|
|
}
|
|
|
|
$rec->set_prop('Program', $module);
|
2025-01-14 13:49:31 +01:00
|
|
|
my $backupwkHour = $c->param('BackupwkHour');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($backupwkHour =~ /^(.*)$/) {
|
|
|
|
$backupwkHour = $1;
|
|
|
|
} else {
|
|
|
|
$backupwkHour = '12';
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($backupwkHour < 0) || ($backupwkHour > 12)) {
|
|
|
|
return $c->l('bac_ERR_INVALID_HOUR') . $backupwkHour . $c->l('bac_BETWEEN_0_AND_12');
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
my $backupwkMin = $c->param('BackupwkMin');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($backupwkMin =~ /^(.*)$/) {
|
|
|
|
$backupwkMin = $1;
|
|
|
|
} else {
|
|
|
|
$backupwkMin = '0';
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (($backupwkMin < 0) || ($backupwkMin > 59)) {
|
|
|
|
return $c->l('bac_ERR_INVALID_MINUTE') . $backupwkMin . $c->l('bac_BETWEEN_0_AND_59');
|
|
|
|
}
|
|
|
|
$backupwkMin = sprintf("%02d", $backupwkMin);
|
|
|
|
$ampm = $c->param('BackupwkAMPM');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($ampm =~ /^(.*)$/) {
|
|
|
|
$ampm = $1;
|
|
|
|
} else {
|
|
|
|
$ampm = 'AM';
|
|
|
|
}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# convert to 24 hour time
|
|
|
|
$backupwkHour = $backupwkHour % 12;
|
|
|
|
|
|
|
|
if ($ampm eq 'PM') {
|
|
|
|
$backupwkHour = $backupwkHour + 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
# variables passed validity checks, set configuration database values
|
|
|
|
my $old = $cdb->get('UnsavedChanges')->value;
|
|
|
|
$rec->set_prop('status', 'enabled');
|
|
|
|
$rec->set_prop('BackupTime', "$backupwkHour:$backupwkMin");
|
|
|
|
$cdb->get('UnsavedChanges')->set_value($old);
|
|
|
|
system("/sbin/e-smith/signal-event", "conf-backup") == 0
|
|
|
|
or die($c->l('bac_ERR_CONF_BACKUP'), "\n");
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# we test if the remote host is reachable, else we simply display a warning
|
|
|
|
if ($VFSType =~ m/cifs|nfs/s) {
|
|
|
|
my $error_message = vmount($backupwkStation, $backupwkFolder, $backupwkMount, $VFSType);
|
|
|
|
|
|
|
|
if (!$error_message) {
|
|
|
|
$c->bunmount($backupwkMount, $VFSType);
|
|
|
|
} elsif ($error_message) {
|
|
|
|
return $c->l('bac_ERROR_WHEN_TESTING_REMOTE_SERVER') . "<br>$error_message";
|
|
|
|
}
|
|
|
|
} ## end if ($VFSType =~ m/cifs|nfs/s)
|
|
|
|
return
|
|
|
|
'#OK#'
|
|
|
|
. $c->l('bac_SUCCESSFULLY_ENABLED_WORKSTN') . '<br>'
|
|
|
|
. $c->l('bac_WITH_BACKUP_TIME')
|
|
|
|
. " $backupwkHour:$backupwkMin";
|
|
|
|
} ## end sub updateWorkstnBackupConfig
|
|
|
|
|
|
|
|
sub performWorkstnSelRestore {
|
|
|
|
my ($c, $seldatebefore, $restorefiles) = @_;
|
2024-03-22 04:54:28 +01:00
|
|
|
my $out;
|
|
|
|
my @restorelist;
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
foreach (@{$restorefiles}) {
|
|
|
|
push @restorelist, "\"" . $1 . "\"" if ($_ =~ /^(.*)$/);
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
my $backupwkrec = $cdb->get('backupwk');
|
2025-01-14 13:49:31 +01:00
|
|
|
my $id = $backupwkrec->prop('Id')
|
|
|
|
|| $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value;
|
|
|
|
my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb';
|
2024-03-22 04:54:28 +01:00
|
|
|
my $VFSType = $backupwkrec->prop('VFSType') || 'cifs';
|
|
|
|
my $smbhost = $backupwkrec->prop('SmbHost');
|
|
|
|
my $smbshare = $backupwkrec->prop('SmbShare');
|
|
|
|
my $err;
|
|
|
|
my $error_message;
|
2025-01-14 13:49:31 +01:00
|
|
|
$mntdir = "/$smbshare" if ($VFSType eq 'usb');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# Mounting backup shared folder
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType);
|
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($error_message) {
|
|
|
|
$error_message .= " : $id";
|
|
|
|
return $error_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test if backup subdirectory for our server
|
|
|
|
my $mntbkdir = $mntdir . "/$id";
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
unless (-d $mntbkdir) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message = $c->l('bac_ERR_NO_HOST_DIR') . "\n";
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
$error_message .= " : $id";
|
|
|
|
return $error_message;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end unless (-d $mntbkdir)
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# backup is online, restoring now
|
|
|
|
$| = 1;
|
|
|
|
my $restorerr;
|
|
|
|
|
|
|
|
if (open(RD, "-|")) {
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
#-----------------------------------------------------
|
|
|
|
# restore system from uploaded workstation backup file
|
|
|
|
#-----------------------------------------------------
|
|
|
|
$out .= "<b>" . $c->l('bac_FILES_HAVE_BEEN_RESTORED') . "</b> \n";
|
|
|
|
$out .= '<UL>';
|
|
|
|
|
|
|
|
while (<RD>) {
|
|
|
|
$out .= "<li>$_</li>\n";
|
|
|
|
}
|
|
|
|
$out .= '</UL>';
|
|
|
|
my $message;
|
|
|
|
|
|
|
|
if (!close RD) {
|
|
|
|
$message = $c->l('bac_RESTORE_FAILED_MSG');
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ($restorerr) {
|
|
|
|
$message = $c->l('bac_RESTORE_FAILED');
|
|
|
|
} else {
|
|
|
|
$message = $c->l('bac_RESTORE_COMPLETE');
|
|
|
|
}
|
|
|
|
} ## end else [ if (!close RD) ]
|
|
|
|
$out .= "<b>$message </b>\n";
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
select(STDOUT);
|
|
|
|
$| = 1;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($seldatebefore) {
|
|
|
|
$restorerr
|
|
|
|
= system(
|
|
|
|
"/usr/bin/dar_manager -B \"$mntbkdir/dar-catalog\" -Q -w $seldatebefore -e '-v -N -R / -w' -r @restorelist"
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$restorerr
|
|
|
|
= system("/usr/bin/dar_manager -B \"$mntbkdir/dar-catalog\" -Q -k -e '-v -N -R / -w' -r @restorelist");
|
|
|
|
}
|
|
|
|
$error_message = $c->bunmount($mntdir, $VFSType);
|
|
|
|
die($error_message) if $error_message;
|
|
|
|
exit(0);
|
|
|
|
} ## end else [ if (open(RD, "-|")) ]
|
|
|
|
return "#OK#" . $out;
|
|
|
|
} ## end sub performWorkstnSelRestore
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub performReboot {
|
|
|
|
my ($c) = @_;
|
|
|
|
|
|
|
|
#print "$c->l('bac_SERVER_REBOOT')";
|
|
|
|
#print "$c->l('bac_SERVER_WILL_REBOOT')";
|
2025-01-14 13:49:31 +01:00
|
|
|
esmith::util::backgroundCommand(2, "/sbin/e-smith/signal-event", "reboot");
|
2024-03-22 04:54:28 +01:00
|
|
|
return "#OK#" . $c->l('bac_SERVER_WILL_REBOOT');
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub performReboot
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_VFSType_options {
|
|
|
|
my $c = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
return [
|
|
|
|
[ $c->l('cifs') => 'cifs' ],
|
|
|
|
[ $c->l('nfs') => 'nfs' ],
|
|
|
|
[ $c->l('local removable disk') => 'usb' ],
|
|
|
|
[ $c->l('Mounted disk') => 'mnt' ]
|
|
|
|
];
|
|
|
|
} ## end sub get_VFSType_options
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_dow_list {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $c = shift;
|
|
|
|
my @list = ();
|
2024-03-22 04:54:28 +01:00
|
|
|
my @dlabels = split(' ', $c->l('bac_DOW'));
|
2025-01-14 13:49:31 +01:00
|
|
|
my $i = 0;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
foreach (@dlabels) {
|
2025-01-14 13:49:31 +01:00
|
|
|
push @list, [ "$_" => "$i" ];
|
|
|
|
$i++;
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# put 'everyday' first
|
2024-03-22 04:54:28 +01:00
|
|
|
my $lastr = pop @list;
|
|
|
|
unshift @list, $lastr;
|
|
|
|
return \@list;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_dow_list
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_BackupwkDest_options {
|
|
|
|
my ($c, $VFSType) = @_;
|
|
|
|
my @usbdisks = ();
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($VFSType eq 'usb') {
|
|
|
|
my $devices = esmith::BlockDevices->new('allowmount' => 'disabled');
|
2024-04-30 19:23:52 +02:00
|
|
|
my ($valid, $invalid) = $devices->checkBackupDrives(0);
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (${$valid}[0]) {
|
|
|
|
foreach (@{$valid}) {
|
2024-04-30 19:23:52 +02:00
|
|
|
push @usbdisks, $devices->label($_);
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end if (${$valid}[0])
|
|
|
|
|
|
|
|
if (!$usbdisks[0]) {
|
|
|
|
push(@usbdisks, $c->l('bac_No suitable local devices found'));
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2024-04-30 19:23:52 +02:00
|
|
|
$devices->destroy;
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
#foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) {
|
|
|
|
#$udi =~ m/^(\S+)/;
|
|
|
|
#my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted);
|
|
|
|
#if ($is_mounted eq "false\n") {
|
|
|
|
#my $vollbl = qx(hal-get-property --udi $1 --key volume.label);
|
|
|
|
#$vollbl =~ m/^(\S+)/;
|
|
|
|
#if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';}
|
|
|
|
#chomp $vollbl;
|
|
|
|
#push @usbdisks, $vollbl;
|
2024-04-30 19:23:52 +02:00
|
|
|
#}
|
2025-01-14 13:49:31 +01:00
|
|
|
#}
|
|
|
|
# return undef unless ($usbdisks[0]);
|
|
|
|
} ## end if ($VFSType eq 'usb')
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($VFSType eq 'mnt') {
|
|
|
|
@usbdisks = findmnt();
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# return undef unless ($usbdisks[0]);
|
|
|
|
} ## end if ($VFSType eq 'mnt')
|
|
|
|
return \@usbdisks;
|
|
|
|
} ## end sub get_BackupwkDest_options
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_function_options {
|
|
|
|
my $c = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
return [
|
|
|
|
[ $c->l('bac_DESKTOP_BACKUP') => 'desktop_backup' ],
|
|
|
|
[ $c->l('bac_TAPE_CONFIGURE') => 'tape_configure' ],
|
|
|
|
[ $c->l('bac_TAPE_RESTORE') => 'tape_restore' ],
|
|
|
|
[ $c->l('bac_WORKSTN_CONFIGURE') => 'workstn_configure' ],
|
|
|
|
[ $c->l('bac_WORKSTN_VERIFY') => 'workstn_verify' ],
|
|
|
|
[ $c->l('bac_WORKSTN_RESTORE') => 'workstn_restore' ],
|
|
|
|
[ $c->l('bac_WORKSTN_SEL_RESTORE') => 'workstn_sel_restore' ]
|
|
|
|
];
|
|
|
|
} ## end sub get_function_options
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_shared_folder_to_verify () {
|
|
|
|
my ($c) = @_;
|
|
|
|
my $rec = $cdb->get('backupwk');
|
|
|
|
return undef unless $rec;
|
2025-01-14 13:49:31 +01:00
|
|
|
my $id = $rec->prop('Id') || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value;
|
|
|
|
my $smbhost = $rec->prop('SmbHost');
|
2024-03-22 04:54:28 +01:00
|
|
|
my $smbshare = $rec->prop('SmbShare');
|
|
|
|
return "$smbhost/$smbshare/$id";
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_shared_folder_to_verify
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_Backupset_options () {
|
|
|
|
my ($c) = @_;
|
|
|
|
my $rec = $cdb->get('backupwk');
|
|
|
|
return undef unless $rec;
|
|
|
|
my %backupfiles = ();
|
2025-01-14 13:49:31 +01:00
|
|
|
my $mntdir = $rec->prop('Mount') || '/mnt/smb';
|
|
|
|
my $id = $rec->prop('Id') || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value;
|
|
|
|
my $smbhost = $rec->prop('SmbHost');
|
|
|
|
my $smbshare = $rec->prop('SmbShare');
|
2024-03-22 04:54:28 +01:00
|
|
|
my $mntbkdir;
|
|
|
|
my $key;
|
|
|
|
my $VFSType = $rec->prop('VFSType') || 'cifs';
|
|
|
|
my $err;
|
2025-01-14 13:49:31 +01:00
|
|
|
$mntdir = "/$smbshare" if ($VFSType eq 'usb');
|
2024-03-22 04:54:28 +01:00
|
|
|
my $setbackuplist = sub {
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if ($_ =~ /\.dar/) {
|
|
|
|
my $dir = $File::Find::dir;
|
|
|
|
my $backupref;
|
|
|
|
$dir =~ s/$mntbkdir\///;
|
2024-03-22 04:54:28 +01:00
|
|
|
$_ =~ s/\..*\.dar//;
|
2025-01-14 13:49:31 +01:00
|
|
|
$backupref = $_;
|
|
|
|
$_ =~ s/.*-//;
|
|
|
|
@{ $backupfiles{$_} }[0] = $dir;
|
|
|
|
@{ $backupfiles{$_} }[1] = $backupref;
|
|
|
|
} ## end if ($_ =~ /\.dar/)
|
2024-03-22 04:54:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
# Mounting backup shared folder
|
2025-01-14 13:49:31 +01:00
|
|
|
my $error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return [] if $error_message;
|
|
|
|
|
|
|
|
# Test if backup subdirectory for our server
|
|
|
|
$mntbkdir = $mntdir . "/$id";
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
unless (-d $mntbkdir) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
# Finding existing backups
|
2025-01-14 13:49:31 +01:00
|
|
|
find { wanted => \&$setbackuplist, untaint => 1, untaint_pattern => qr|^([-+@\w\s./]+)$| }, $mntbkdir;
|
2024-03-22 04:54:28 +01:00
|
|
|
my %blabels = ();
|
|
|
|
my @list;
|
|
|
|
|
|
|
|
foreach $key (sort keys %backupfiles) {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $labkey = $mntbkdir . '/' . $backupfiles{$key}[0] . '/' . $backupfiles{$key}[1];
|
|
|
|
$blabels{$labkey} = $backupfiles{$key}[1] . " (" . $backupfiles{$key}[0] . ")";
|
|
|
|
push @list, [ "$blabels{$labkey}" => "$labkey" ];
|
|
|
|
} ## end foreach $key (sort keys %backupfiles)
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return \@list;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_Backupset_options
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_Restoreset_options () {
|
|
|
|
my ($c) = @_;
|
|
|
|
my $rec = $cdb->get('backupwk');
|
|
|
|
return [] unless $rec;
|
|
|
|
my %backupfiles = ();
|
2025-01-14 13:49:31 +01:00
|
|
|
my $mntdir = $rec->prop('Mount') || '/mnt/smb';
|
|
|
|
my $id = $rec->prop('Id') || $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value;
|
|
|
|
my $smbhost = $rec->prop('SmbHost');
|
|
|
|
my $smbshare = $rec->prop('SmbShare');
|
2024-03-22 04:54:28 +01:00
|
|
|
my $mntbkdir;
|
|
|
|
my $key;
|
|
|
|
my $VFSType = $rec->prop('VFSType') || 'cifs';
|
|
|
|
my $err;
|
2025-01-14 13:49:31 +01:00
|
|
|
$mntdir = "/$smbshare" if ($VFSType eq 'usb');
|
2024-03-22 04:54:28 +01:00
|
|
|
my $setbackuplist = sub {
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if ($_ =~ /\.dar/) {
|
|
|
|
my $dir = $File::Find::dir;
|
|
|
|
my $backupref;
|
|
|
|
$dir =~ s/$mntbkdir\///;
|
2024-03-22 04:54:28 +01:00
|
|
|
$_ =~ s/\..*\.dar//;
|
2025-01-14 13:49:31 +01:00
|
|
|
$backupref = $_;
|
|
|
|
$_ =~ s/.*-//;
|
|
|
|
@{ $backupfiles{$_} }[0] = $dir;
|
|
|
|
@{ $backupfiles{$_} }[1] = $backupref;
|
|
|
|
} ## end if ($_ =~ /\.dar/)
|
2024-03-22 04:54:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
# Mounting backup shared folder
|
2025-01-14 13:49:31 +01:00
|
|
|
my $error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return [] if $error_message;
|
|
|
|
|
|
|
|
# Test if backup subdirectory for our server
|
|
|
|
$mntbkdir = $mntdir . "/$id";
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
unless (-d $mntbkdir) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
my $catalog = "$mntbkdir/dar-catalog";
|
2025-01-14 13:49:31 +01:00
|
|
|
my $i = 0;
|
|
|
|
my $j = 0;
|
|
|
|
my @bknum;
|
|
|
|
my @setd;
|
|
|
|
my @bkname;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# update backups list from current catalog
|
|
|
|
open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |");
|
2024-03-22 04:54:28 +01:00
|
|
|
$i = 0;
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
while (<DAR_LIST>) {
|
|
|
|
next unless m/set/;
|
|
|
|
chomp;
|
|
|
|
($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3);
|
|
|
|
$i++;
|
|
|
|
} ## end while (<DAR_LIST>)
|
|
|
|
close(DAR_LIST);
|
2024-03-22 04:54:28 +01:00
|
|
|
my @list;
|
|
|
|
|
|
|
|
# set drop down list of backups
|
|
|
|
push @list, [ $c->l('bac_ALL_BACKUPS') => "0" ];
|
|
|
|
$j = 0;
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
while ($j < $i) {
|
2025-01-14 13:49:31 +01:00
|
|
|
push @list, [ $bkname[$j] => "$bknum[$j]" ];
|
|
|
|
$j++;
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return \@list;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_Restoreset_options
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub get_Restorefiles_options {
|
|
|
|
my ($c, $filterexp, $backupkey) = @_;
|
|
|
|
my $rgfilter;
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($filterexp =~ /^(.*)$/) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$filterexp = $1;
|
|
|
|
$rgfilter = qr/$filterexp/;
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
|
|
|
$filterexp = "";
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($backupkey =~ /^(.*)$/) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$backupkey = $1;
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
die('Unsecure data : ' . $backupkey);
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
my $seldatebf;
|
|
|
|
my $backupwkrec = $cdb->get('backupwk');
|
2025-01-14 13:49:31 +01:00
|
|
|
my $smbhost = $backupwkrec->prop('SmbHost');
|
|
|
|
my $smbshare = $backupwkrec->prop('SmbShare');
|
|
|
|
my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb';
|
2024-03-22 04:54:28 +01:00
|
|
|
my $key;
|
2025-01-14 13:49:31 +01:00
|
|
|
my $id = $backupwkrec->prop('Id')
|
|
|
|
|| $cdb->get('SystemName')->value . "." . $cdb->get('DomainName')->value;
|
2024-03-22 04:54:28 +01:00
|
|
|
my @flabels;
|
|
|
|
my %flabels = ();
|
|
|
|
my $VFSType = $backupwkrec->prop('VFSType') || 'cifs';
|
|
|
|
my $err;
|
|
|
|
my $error_message;
|
2025-01-14 13:49:31 +01:00
|
|
|
$mntdir = "/$smbshare" if ($VFSType eq 'usb');
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# Mounting backup shared folder
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message = $c->bmount($mntdir, $smbhost, $smbshare, $VFSType);
|
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($error_message) {
|
|
|
|
warn "Backup - restore files: $error_message, $id \n";
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test if backup subdirectory for our server
|
|
|
|
my $mntbkdir = $mntdir . "/$id";
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
unless (-d $mntbkdir) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$error_message = $c->l('bac_ERR_NO_HOST_DIR') . "\n";
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
warn "Backup - restore files: $error_message, $id \n";
|
|
|
|
return undef;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end unless (-d $mntbkdir)
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# Read wanted file list from selected backup
|
|
|
|
if (open(RD, "-|")) {
|
2025-01-14 13:49:31 +01:00
|
|
|
my $regex = qr/\[.*\] */;
|
|
|
|
|
|
|
|
while (<RD>) {
|
|
|
|
chomp;
|
|
|
|
$_ =~ s/$regex//;
|
|
|
|
if ($filterexp) { next unless m/$rgfilter/ }
|
|
|
|
push @flabels, $_;
|
|
|
|
} ## end while (<RD>)
|
|
|
|
my $status
|
|
|
|
= close RD
|
|
|
|
? $c->l('bac_READ_COMPLETE')
|
|
|
|
: ($c->l('bac_ERROR_READING_FILE') . ' : ' . $backupkey);
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
|
|
|
select(STDOUT);
|
|
|
|
$| = 1;
|
|
|
|
system("/usr/bin/dar_manager", "-B", "$mntbkdir/dar-catalog", "-u", "$backupkey") == 0
|
2025-01-14 13:49:31 +01:00
|
|
|
or die($c->l('bac_ERR_EXTRACT') . " : " . $!);
|
|
|
|
$error_message = $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
die($error_message) if $error_message;
|
|
|
|
exit(0);
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end else [ if (open(RD, "-|")) ]
|
|
|
|
$error_message .= $c->bunmount($mntdir, $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return \@flabels;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub get_Restorefiles_options
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub CalculateSizes () {
|
|
|
|
my $c = shift;
|
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# figure out the size of the tar file.
|
|
|
|
#------------------------------------------------------------
|
|
|
|
my $tarsize = 0;
|
|
|
|
|
|
|
|
# It takes way too much time to do a du on /home/e-smith. So we'll
|
|
|
|
# estimate the current size.
|
|
|
|
# We do this by checking the quota used by each user on the system.
|
|
|
|
# Get a $dev value appropriate for use in Quota::query call.
|
|
|
|
my $dev = Quota::getqcarg("/home/e-smith/files");
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
foreach my $user ($adb->users()) {
|
|
|
|
my $name = $user->key;
|
|
|
|
my $uid = getpwnam($name);
|
|
|
|
|
|
|
|
unless ($uid) {
|
|
|
|
warn($c->l('bac_NO_UID_FOR_NAME') . $name . "\n");
|
|
|
|
|
|
|
|
# We shouldn't ever get here. If we do, we can't get
|
|
|
|
# the quota value for this user, so we just skip to
|
|
|
|
# the next one.
|
|
|
|
next;
|
|
|
|
} ## end unless ($uid)
|
|
|
|
|
|
|
|
# Get current quota settings.
|
|
|
|
my ($blocks) = Quota::query($dev, $uid, 0);
|
|
|
|
$tarsize += $blocks;
|
|
|
|
} ## end foreach my $user ($adb->users...)
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# We add to this the size of root owned firectories, estimated using du.
|
|
|
|
# If this takes too long, then the admin only has his or
|
|
|
|
# herself to blame!
|
|
|
|
# Remove /home/e-smith from backup list, and make paths absolute
|
2025-01-14 13:49:31 +01:00
|
|
|
my @list = map {"/$_"} grep { !/home\/e-smith/ } @directories;
|
2024-03-22 04:54:28 +01:00
|
|
|
open(DU, "-|")
|
2025-01-14 13:49:31 +01:00
|
|
|
or exec '/usr/bin/du', '-s', @list;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
while (<DU>) {
|
|
|
|
my ($du) = split(/\s+/);
|
|
|
|
$tarsize += $du;
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
close DU;
|
|
|
|
$tarsize = showSize($tarsize);
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
#------------------------------------------------------------
|
|
|
|
# figure out the size of the dump files
|
|
|
|
#------------------------------------------------------------
|
|
|
|
my $dumpsize = 0;
|
|
|
|
open(DF, "-|")
|
2025-01-14 13:49:31 +01:00
|
|
|
or exec '/bin/df', '-P', '-t', 'ext4', '-t', 'xfs';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
while (<DF>) {
|
2025-01-14 13:49:31 +01:00
|
|
|
next unless (/^\//);
|
|
|
|
(undef, undef, my $s, undef) = split(/\s+/, $_);
|
|
|
|
$dumpsize += $s;
|
|
|
|
} ## end while (<DF>)
|
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
# increase size by 10% to cope with dump overhead.
|
|
|
|
$dumpsize *= 1.1;
|
|
|
|
close DF;
|
|
|
|
$dumpsize = showSize($dumpsize);
|
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# how much free space is in /tmp
|
|
|
|
#------------------------------------------------------------
|
2025-01-14 13:49:31 +01:00
|
|
|
my $tmpfree = 0;
|
2024-03-22 04:54:28 +01:00
|
|
|
my $halffree = 0;
|
|
|
|
open(DF, "-|")
|
2025-01-14 13:49:31 +01:00
|
|
|
or exec '/bin/df', '-P', '-t', 'ext4', '-t', 'xfs', '/tmp';
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
while (<DF>) {
|
2025-01-14 13:49:31 +01:00
|
|
|
next unless (/^\//);
|
|
|
|
(undef, undef, undef, my $s) = split(/\s+/, $_);
|
|
|
|
$tmpfree += $s;
|
|
|
|
} ## end while (<DF>)
|
2024-03-22 04:54:28 +01:00
|
|
|
close DF;
|
|
|
|
$halffree = $tmpfree / 2;
|
2025-01-14 13:49:31 +01:00
|
|
|
$tmpfree = showSize($tmpfree);
|
2024-03-22 04:54:28 +01:00
|
|
|
$halffree = showSize($halffree);
|
|
|
|
return ($tarsize, $dumpsize, $tmpfree, $halffree);
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub CalculateSizes
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub showSize {
|
|
|
|
|
|
|
|
# convert size to Mb or Gb or Tb :) Remember, df reports in kb.
|
|
|
|
my $size = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
my $Mb = 1024;
|
|
|
|
my $Gb = $Mb * $Mb;
|
|
|
|
my $Tb = $Mb * $Mb * $Mb;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
if ($size >= $Tb) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$size /= $Tb;
|
|
|
|
$size = int($size) . "Tb";
|
2024-03-22 04:54:28 +01:00
|
|
|
} elsif ($size >= $Gb) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$size /= $Gb;
|
|
|
|
$size = int($size) . "Gb";
|
2024-03-22 04:54:28 +01:00
|
|
|
} elsif ($size >= $Mb) {
|
2025-01-14 13:49:31 +01:00
|
|
|
$size /= $Mb;
|
|
|
|
$size = int($size) . "Mb";
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
$size .= "kb";
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
|
|
|
return $size;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub showSize
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub desktopBackupRecordStatus {
|
|
|
|
my ($backup, $phase, $status) = @_;
|
|
|
|
my $now = time();
|
|
|
|
warn("Backup terminated: $phase failed - status: $status\n");
|
|
|
|
$backup->set_prop('EndEpochTime', "$now");
|
2025-01-14 13:49:31 +01:00
|
|
|
$backup->set_prop('Result', "$phase:$status");
|
|
|
|
} ## end sub desktopBackupRecordStatus
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub dmount {
|
|
|
|
|
|
|
|
# mount dar unit according to dar-workstation configuration
|
|
|
|
# return nothing if mount successfull
|
2025-01-14 13:49:31 +01:00
|
|
|
my ($host, $share, $mountdir, $login, $password, $VFSType) = @_;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if ($VFSType eq 'cifs') {
|
|
|
|
return (qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1));
|
|
|
|
} elsif ($VFSType eq 'nfs') {
|
|
|
|
return (qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1));
|
|
|
|
} elsif ($VFSType eq 'usb') {
|
|
|
|
my $device = "";
|
|
|
|
my $vollbl = "";
|
|
|
|
my $devices = esmith::BlockDevices->new('allowmount' => 'disabled');
|
2024-04-30 19:23:52 +02:00
|
|
|
my ($valid, $invalid) = $devices->checkBackupDrives(0);
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (${$valid}[0]) {
|
|
|
|
foreach (@{$valid}) {
|
2024-04-30 19:23:52 +02:00
|
|
|
$vollbl = $devices->label($_);
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if ($share eq "media/$vollbl") {
|
2024-04-30 19:23:52 +02:00
|
|
|
$device = "/dev/$_";
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end foreach (@{$valid})
|
|
|
|
} ## end if (${$valid}[0])
|
2024-04-30 19:23:52 +02:00
|
|
|
$devices->destroy;
|
2025-01-14 13:49:31 +01:00
|
|
|
return (qx (mount $device /$share 2>&1));
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------------------------------
|
2024-04-30 19:23:52 +02:00
|
|
|
#my $device = "";
|
|
|
|
#my $blkdev = "";
|
|
|
|
#my $vollbl = "";
|
|
|
|
#foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) {
|
2025-01-14 13:49:31 +01:00
|
|
|
#$udi =~ m/^(\S+)/;
|
|
|
|
#my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted);
|
|
|
|
#if ($is_mounted eq "false\n") {
|
|
|
|
#$blkdev = qx(hal-get-property --udi $1 --key block.device);
|
|
|
|
#if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;}
|
|
|
|
#}
|
|
|
|
#if ($is_mounted eq "false\n") {
|
|
|
|
#$vollbl = qx(hal-get-property --udi $1 --key volume.label);
|
|
|
|
#$vollbl =~ m/^(\S+)/;
|
|
|
|
#if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';}
|
2024-04-30 19:23:52 +02:00
|
|
|
#}
|
2025-01-14 13:49:31 +01:00
|
|
|
#chomp $vollbl;
|
|
|
|
#chomp $blkdev;
|
|
|
|
#$vollbl = "media/$vollbl";
|
|
|
|
#if ($vollbl eq $share) {
|
|
|
|
#$device = $blkdev;
|
|
|
|
#}
|
|
|
|
#}
|
|
|
|
#return ( qx(/bin/mount $device "/$share" 2>&1) );
|
|
|
|
#-------------------------------------------------------------------------------------------------------
|
2024-03-22 04:54:28 +01:00
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
return ("Error while mounting $host/$share : $VFSType not supported.\n");
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub dmount
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub checkMount {
|
|
|
|
|
|
|
|
# check if $mountdir is mounted
|
|
|
|
my $mountdir = shift;
|
2025-01-14 13:49:31 +01:00
|
|
|
$| = 1; # Auto-flush
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# copy STDOUT to another filehandle
|
2025-01-14 13:49:31 +01:00
|
|
|
open(my $STDOLD, '>&', STDOUT);
|
2024-03-22 04:54:28 +01:00
|
|
|
open(STDOUT, ">/dev/null");
|
2025-01-14 13:49:31 +01:00
|
|
|
if (open(MOUNTDIR, "|-", "/bin/findmnt", $mountdir)) {;}
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# restore STDOUT
|
2025-01-14 13:49:31 +01:00
|
|
|
open(STDOUT, '>&', $STDOLD);
|
|
|
|
return (!close(MOUNTDIR));
|
|
|
|
} ## end sub checkMount
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub bmount {
|
|
|
|
my ($c, $mntdir, $host, $share, $VFSType) = @_;
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
# verify backup directory not already mounted
|
|
|
|
if (!checkMount($mntdir)) {
|
2024-03-22 04:54:28 +01:00
|
|
|
return if ($VFSType eq 'mnt');
|
|
|
|
return ($c->l('bac_ERR_ALREADY_MOUNTED'));
|
|
|
|
} else {
|
2025-01-14 13:49:31 +01:00
|
|
|
|
2024-03-22 04:54:28 +01:00
|
|
|
if ($VFSType eq 'mnt') {
|
|
|
|
return ($c->l('bac_ERR_NOT_MOUNTED'));
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end else [ if (!checkMount($mntdir...))]
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
# create the directory mount point if it does not exist
|
2025-01-14 13:49:31 +01:00
|
|
|
my $err = createTree($mntdir);
|
2024-03-22 04:54:28 +01:00
|
|
|
return ($c->l('bac_ERR_MOUNTING_SMBSHARE') . "<//$host/$share>\n" . $err) if $err;
|
|
|
|
|
|
|
|
# mount the backup directory
|
2025-01-14 13:49:31 +01:00
|
|
|
$err = dmount($host, $share, $mntdir, '', '', $VFSType);
|
2024-03-22 04:54:28 +01:00
|
|
|
return ($c->l('bac_ERR_MOUNTING_SMBSHARE') . "<//$host/$share>\n" . $err) if $err;
|
|
|
|
|
|
|
|
# verify $mntdir is mounted
|
2025-01-14 13:49:31 +01:00
|
|
|
if (checkMount($mntdir)) {
|
|
|
|
|
|
|
|
# The mount should have suceeded, but sometimes it needs more time,
|
2024-03-22 04:54:28 +01:00
|
|
|
# so sleep and then check again.
|
|
|
|
sleep 5;
|
2025-01-14 13:49:31 +01:00
|
|
|
|
|
|
|
if (checkMount($mntdir)) {
|
2024-03-22 04:54:28 +01:00
|
|
|
return ($c->l('bac_ERR_NOT_MOUNTED'));
|
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end if (checkMount($mntdir...))
|
2024-03-22 04:54:28 +01:00
|
|
|
return;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub bmount
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub bunmount {
|
|
|
|
my ($c, $mount, $type) = @_;
|
2025-01-14 13:49:31 +01:00
|
|
|
return if ($type eq 'mnt'); # Don't unmount for type 'mnt'
|
2024-03-22 04:54:28 +01:00
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (!checkMount($mount)) {
|
2024-03-22 04:54:28 +01:00
|
|
|
system('/bin/umount', '-f', $mount) == 0
|
|
|
|
or return ($c->l('bac_ERR_WHILE_UNMOUNTING'));
|
|
|
|
}
|
|
|
|
return;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub bunmount
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub findmnt {
|
2025-01-14 13:49:31 +01:00
|
|
|
my @mntin = qx( findmnt -n -l -o TARGET );
|
2024-03-22 04:54:28 +01:00
|
|
|
my @mntout;
|
|
|
|
|
|
|
|
foreach my $mount (@mntin) {
|
|
|
|
next if ($mount =~ m/^\/proc|^\/dev|^\/sys|^\/boot/s);
|
|
|
|
chomp $mount;
|
|
|
|
next if ($mount eq '/');
|
|
|
|
push @mntout, $mount;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end foreach my $mount (@mntin)
|
2024-03-22 04:54:28 +01:00
|
|
|
return @mntout;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub findmnt
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub createTree {
|
|
|
|
my $tree = shift;
|
|
|
|
|
2025-01-14 13:49:31 +01:00
|
|
|
if (!-d "$tree") {
|
|
|
|
eval { make_path("$tree") };
|
2024-03-22 04:54:28 +01:00
|
|
|
return ("Error while creating $tree : $@. Maybe insufficient rights directory.\n") if $@;
|
|
|
|
}
|
|
|
|
return;
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub createTree
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
sub vmount {
|
|
|
|
|
|
|
|
#Used to test if the remote share is mountable when you save settings in database
|
|
|
|
# mount dar unit according to dar-workstation configuration in order to test the remote host
|
|
|
|
# return nothing if mount successfull
|
2025-01-14 13:49:31 +01:00
|
|
|
my ($host, $share, $mountdir, $VFSType) = @_;
|
2024-03-22 04:54:28 +01:00
|
|
|
|
|
|
|
if ($VFSType eq 'cifs') {
|
2025-01-14 13:49:31 +01:00
|
|
|
return (qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1));
|
2024-03-22 04:54:28 +01:00
|
|
|
} elsif ($VFSType eq 'nfs') {
|
2025-01-14 13:49:31 +01:00
|
|
|
return (qx(/bin/mount -t nfs -o nolock,timeo=30,retrans=1,retry=0 "$host:/$share" $mountdir 2>&1));
|
2024-03-22 04:54:28 +01:00
|
|
|
}
|
2025-01-14 13:49:31 +01:00
|
|
|
} ## end sub vmount
|
2024-03-22 04:54:28 +01:00
|
|
|
1;
|