Commit 05646536 authored by Falko Timme's avatar Falko Timme

- Added options to use a mounted backup directory. This allows for remote...

- Added options to use a mounted backup directory. This allows for remote backups, e.g. vis sshfs to a backup server. The backup script checks if the backup directory is mounted, and if not, tries to mount it.
parent 855e605f
......@@ -15,6 +15,8 @@ firewall=bastille
loglevel=2
admin_notify_events=1
backup_dir=/var/backup
backup_dir_is_mount=n
backup_dir_mount_cmd=
backup_mode=rootgz
monit_url=
monit_user=
......
......@@ -171,6 +171,20 @@ $form["tabs"]['server'] = array(
'width' => '40',
'maxlength' => '255'
),
'backup_dir_is_mount' => array(
'datatype' => 'VARCHAR',
'formtype' => 'CHECKBOX',
'default' => 'n',
'value' => array(0 => 'n', 1 => 'y')
),
'backup_dir_mount_cmd' => array(
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'width' => '40',
'maxlength' => '255'
),
'backup_mode' => array(
'datatype' => 'VARCHAR',
'formtype' => 'SELECT',
......
......@@ -188,4 +188,6 @@ $wb['munin_user_txt'] = 'Munin-Benutzer';
$wb['munin_password_txt'] = 'Munin-Passwort';
$wb['munin_url_error_regex'] = 'Ungültige Munin-URL';
$wb['munin_url_note_txt'] = 'Platzhalter:';
$wb['backup_dir_is_mount_txt'] = 'Backupverzeichnis ist ein eigener Mount?';
$wb['backup_dir_mount_cmd_txt'] = 'Mount-Befehl, falls Backupverzeichnis nicht gemountet';
?>
\ No newline at end of file
......@@ -188,4 +188,6 @@ $wb['munin_user_txt'] = 'Munin User';
$wb['munin_password_txt'] = 'Munin Password';
$wb['munin_url_error_regex'] = 'Invalid Munin URL';
$wb['munin_url_note_txt'] = 'Placeholder:';
$wb['backup_dir_is_mount_txt'] = 'Backup directory is a mount?';
$wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounted';
?>
......@@ -58,6 +58,16 @@
<div class="ctrlHolder">
<label for="backup_dir">{tmpl_var name='backup_dir_txt'}</label>
<input name="backup_dir" id="backup_dir" value="{tmpl_var name='backup_dir'}" size="40" maxlength="255" type="text" class="textInput" />
</div>
<div class="ctrlHolder">
<p class="label">{tmpl_var name='backup_dir_is_mount_txt'}</p>
<div class="multiField">
{tmpl_var name='backup_dir_is_mount'}
</div>
</div>
<div class="ctrlHolder">
<label for="backup_dir_mount_cmd">{tmpl_var name='backup_dir_mount_cmd_txt'}</label>
<input name="backup_dir_mount_cmd" id="backup_dir_mount_cmd" value="{tmpl_var name='backup_dir_mount_cmd'}" size="40" maxlength="255" type="text" class="textInput" />
</div>
<div class="ctrlHolder">
<label for="backup_mode">{tmpl_var name='backup_mode_txt'}</label>
......
......@@ -562,7 +562,6 @@ if(is_file($logfile) && filesize($logfile) > 10000000) {
$sql = "SELECT domain_id, domain, document_root, system_user FROM web_domain WHERE server_id = ".$conf['server_id'];
$records = $app->db->queryAllRecords($sql);
$app->uses('system');
if(is_array($records)) {
foreach($records as $rec){
$tmp_path = realpath(escapeshellcmd($rec['document_root'].'/tmp'));
......@@ -1105,6 +1104,18 @@ if($backup_dir != '') {
chmod(escapeshellcmd($backup_dir), $backup_dir_permissions);
}
//* mount backup directory, if necessary
$run_backups = true;
$server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
if($server_config['backup_dir_is_mount'] == 'y' && $server_config['backup_dir_mount_cmd'] != ''){
if(!$app->system->is_mounted($backup_dir)){
exec(escapeshellcmd($server_config['backup_dir_mount_cmd']));
sleep(1);
if(!$app->system->is_mounted($backup_dir)) $run_backups = false;
}
}
if($run_backups){
$sql = "SELECT * FROM web_domain WHERE server_id = ".$conf['server_id']." AND (type = 'vhost' OR type = 'vhostsubdomain')";
$records = $app->db->queryAllRecords($sql);
if(is_array($records)) {
......@@ -1197,7 +1208,6 @@ if($backup_dir != '') {
unset($dir_handle);
//* Remove backupdir symlink and create as directory instead
$app->uses('system');
$app->system->web_folder_protection($web_path, false);
if(is_link($web_path.'/backup')) {
......@@ -1325,6 +1335,15 @@ if($backup_dir != '') {
}
}
}
} else {
//* send email to admin that backup directory could not be mounted
$global_config = $app->getconf->get_global_config('mail');
if($global_config['admin_mail'] != ''){
$subject = 'Backup directory '.$backup_dir.' could not be mounted';
$message = "Backup directory ".$backup_dir." could not be mounted.\n\nThe command\n\n".$server_config['backup_dir_mount_cmd']."\n\nfailed.";
mail($global_config['admin_mail'], $subject, $message);
}
}
}
......
......@@ -65,12 +65,24 @@ class backup_plugin {
if(is_array($backup)) {
$app->uses('ini_parser,file,getconf');
$app->uses('ini_parser,file,getconf,system');
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$backup['parent_domain_id']);
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'].'/web'.$web['domain_id'];
//* mount backup directory, if necessary
$backup_dir_is_ready = true;
$server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
if($server_config['backup_dir_is_mount'] == 'y' && $server_config['backup_dir_mount_cmd'] != ''){
if(!$app->system->is_mounted($backup_dir)){
exec(escapeshellcmd($server_config['backup_dir_mount_cmd']));
sleep(1);
if(!$app->system->is_mounted($backup_dir)) $backup_dir_is_ready = false;
}
}
if($backup_dir_is_ready){
//* Make backup available for download
if($action_name == 'backup_download') {
//* Copy the backup file to the backup folder of the website
......@@ -123,6 +135,9 @@ class backup_plugin {
}
}
}
} else {
$app->log('Backup directory not ready.', LOGLEVEL_DEBUG);
}
} else {
$app->log('No backup with ID '.$backup_id.' found.', LOGLEVEL_DEBUG);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment