Commit 990ca8a4 authored by Florian Schaal's avatar Florian Schaal

moved "mount backup_dir" from various plugins to system.inc.php

parent 0b22b5ef
......@@ -71,22 +71,9 @@ class cronjob_backup extends cronjob {
} else {
chmod(escapeshellcmd($backup_dir), $backup_dir_permissions);
}
//* mount backup directory, if necessary
$run_backups = true;
$backup_dir_mount_cmd = '/usr/local/ispconfig/server/scripts/backup_dir_mount.sh';
if( $server_config['backup_dir_is_mount'] == 'y' &&
is_file($backup_dir_mount_cmd) &&
is_executable($backup_dir_mount_cmd) &&
fileowner($backup_dir_mount_cmd) === 0
){
if(!$app->system->is_mounted($backup_dir)){
exec($backup_dir_mount_cmd);
sleep(1);
if(!$app->system->is_mounted($backup_dir)) $run_backups = false;
}
}
$run_backups = true;
//* mount backup directory, if necessary
if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($backup_dir) ) $run_backups = false;
if($run_backups){
//* backup only active domains
$sql = "SELECT * FROM web_domain WHERE server_id = ? AND (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias') AND active = 'y'";
......
......@@ -59,20 +59,9 @@ class cronjob_backup_mail extends cronjob {
if($backup_mode == '') $backup_mode = 'userzip';
if($backup_dir != '') {
//* mount backup directory, if necessary
$run_backups = true;
$backup_dir_mount_cmd = '/usr/local/ispconfig/server/scripts/backup_dir_mount.sh';
if( $server_config['backup_dir_is_mount'] == 'y' &&
is_file($backup_dir_mount_cmd) &&
is_executable($backup_dir_mount_cmd) &&
fileowner($backup_dir_mount_cmd) === 0
){
if(!$app->system->is_mounted($backup_dir)){
exec($backup_dir_mount_cmd);
sleep(1);
if(!$app->system->is_mounted($backup_dir)) $run_backups = false;
}
}
//* mount backup directory, if necessary
if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($backup_dir) ) $run_backups = false;
$records = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE server_id = ? AND maildir <> ''", intval($conf['server_id']));
......
......@@ -1801,6 +1801,22 @@ class system{
return $return_var == 0 ? true : false;
}
function mount_backup_dir($backup_dir, $mount_cmd = '/usr/local/ispconfig/server/scripts/backup_dir_mount.sh'){
$mounted = true;
if ( is_file($mount_cmd) &&
is_executable($mount_cmd) &&
fileowner($mount_cmd) === 0
) {
if (!$this->is_mounted($backup_dir)){
exec($backup_dir_mount_cmd);
sleep(1);
if (!$this->is_mounted($backup_dir)) $mounted = false;
}
} else $mounted = false;
return $mounted;
}
function getinitcommand($servicename, $action, $init_script_directory = ''){
global $conf;
// systemd
......
......@@ -2046,25 +2046,19 @@ class apache2_plugin {
if($data['old']['type'] == 'vhost') {
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'];
//* mount backup directory, if necessary
$mount_backup = true;
$server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
if($server_config['backup_dir'] != '' && $server_config['backup_delete'] == 'y') {
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)) $mount_backup = false;
}
}
//* mount backup directory, if necessary
if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($backup_dir) ) $mount_backup = false;
if($mount_backup){
$web_backup_dir = $backup_dir.'/web'.$data_old['domain_id'];
//** do not use rm -rf $web_backup_dir because database(s) may exits
exec(escapeshellcmd('rm -f '.$web_backup_dir.'/web'.$data_old['domain_id'].'_').'*');
//* cleanup database
$sql = "DELETE FROM web_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = ".$data_old['domain_id']." AND filename LIKE 'web".$data_old['domain_id']."_%'";
$app->db->query($sql);
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql);
$sql = "DELETE FROM web_backup WHERE server_id = ? AND parent_domain_id = ? AND filename LIKE ?";
$app->db->query($sql, $conf['server_id'], $data_old['domain_id'], "web".$data_old['domain_id']."_%");
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $data_old['domain_id'], "web".$data_old['domain_id']."_%");
$app->log('Deleted the web backup files', LOGLEVEL_DEBUG);
}
......
......@@ -72,30 +72,9 @@ class backup_plugin {
$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($server_config['backup_dir'])){
exec(escapeshellcmd($server_config['backup_dir_mount_cmd']));
sleep(1);
if(!$app->system->is_mounted($server_config['backup_dir'])) $backup_dir_is_ready = false;
}
}*/
$backup_dir_is_ready = true;
$backup_dir_mount_cmd = '/usr/local/ispconfig/server/scripts/backup_dir_mount.sh';
if( $server_config['backup_dir_is_mount'] == 'y' &&
is_file($backup_dir_mount_cmd) &&
is_executable($backup_dir_mount_cmd) &&
fileowner($backup_dir_mount_cmd) === 0
){
if(!$app->system->is_mounted($backup_dir)){
exec($backup_dir_mount_cmd);
sleep(1);
if(!$app->system->is_mounted($server_config['backup_dir'])) $backup_dir_is_ready = false;
}
}
//* mount backup directory, if necessary
if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($backup_dir) ) $backup_dir_is_ready = false;
if($backup_dir_is_ready){
//* Make backup available for download
......@@ -186,17 +165,10 @@ class backup_plugin {
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'];
//* 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;
}
}
//* mount backup directory, if necessary
if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($backup_dir) ) $backup_dir_is_ready = false;
if($backup_dir_is_ready){
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
$domain_rec = $app->db->queryOneRecord("SELECT * FROM mail_domain WHERE domain_id = ".intval($mail_backup['parent_domain_id']));
......
......@@ -398,17 +398,10 @@ class mail_plugin {
//* Delete the mail-backups
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'];
//* mount backup directory, if necessary
$mount_backup = true;
$server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
if($server_config['backup_dir'] != '' && $maildir_path_deleted && $server_config['backup_delete'] == 'y') {
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)) $mount_backup = false;
}
}
//* mount backup directory, if necessary
if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($backup_dir) ) $mount_backup = false;
if($mount_backup){
$sql = "SELECT * FROM mail_domain WHERE domain = '".explode("@",$data['old']['email'])[1]."'";
$domain_rec = $app->db->queryOneRecord($sql);
......@@ -416,13 +409,11 @@ class mail_plugin {
$mail_backup_files = 'mail'.$data['old']['mailuser_id'];
exec(escapeshellcmd('rm -f '.$mail_backup_dir.'/'.$mail_backup_files).'*');
//* cleanup database
$sql = "DELETE FROM mail_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = ".$domain_rec['domain_id']." AND mailuser_id = ".$data['old']['mailuser_id'];
$app->db->query($sql);
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql);
$sql = "DELETE FROM mail_backup WHERE server_id = ? AND parent_domain_id = ? AND mailuser_id = ?";
$app->db->query($sql, $conf['server_id'], $domain_rec['domain_id'], $data['old']['mailuser_id']);
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $domain_rec['domain_id'], $data['old']['mailuser_id']);
$app->log('Deleted the mail backups for: '.$data['old']['email'], LOGLEVEL_DEBUG);
}
}
}
......@@ -457,24 +448,17 @@ class mail_plugin {
//* Delete the mail-backups
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'];
//* mount backup directory, if necessary
$mount_backup = true;
$server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
if($server_config['backup_dir'] != '' && $maildomain_path_deleted && $server_config['backup_delete'] == 'y'){
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)) $mount_backup = false;
}
}
//* mount backup directory, if necessary
if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($backup_dir) ) $mount_backup = false;
if($mount_backup){
$mail_backup_dir = $backup_dir.'/mail'.$data['old']['domain_id'];
exec(escapeshellcmd('rm -rf '.$mail_backup_dir));
//* cleanup database
$sql = "DELETE FROM mail_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = ".$data['old']['domain_id'];
$app->db->query($sql);
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql);
$sql = "DELETE FROM mail_backup WHERE server_id = ? AND parent_domain_id = ? AND mailuser_id = ?";
$app->db->query($sql, $conf['server_id'], $domain_rec['domain_id'], $data['old']['mailuser_id']);
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $domain_rec['domain_id'], $data['old']['mailuser_id']);
$app->log('Deleted the mail backup directory: '.$mail_backup_dir, LOGLEVEL_DEBUG);
}
......
......@@ -2046,6 +2046,28 @@ class nginx_plugin {
$this->awstats_delete($data, $web_config);
}
//* Delete the web-backups
if($data['old']['type'] == 'vhost') {
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'];
$mount_backup = true;
if($server_config['backup_dir'] != '' && $server_config['backup_delete'] == 'y') {
//* mount backup directory, if necessary
if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($backup_dir) ) $mount_backup = false;
if($mount_backup){
$web_backup_dir = $backup_dir.'/web'.$data_old['domain_id'];
//** do not use rm -rf $web_backup_dir because database(s) may exits
exec(escapeshellcmd('rm -f '.$web_backup_dir.'/web'.$data_old['domain_id'].'_').'*');
//* cleanup database
$sql = "DELETE FROM web_backup WHERE server_id = ? AND parent_domain_id = ? AND filename LIKE ?";
$app->db->query($sql, $conf['server_id'], $data_old['domain_id'], "web".$data_old['domain_id']."_%");
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $data_old['domain_id'], "web".$data_old['domain_id']."_%");
$app->log('Deleted the web backup files', LOGLEVEL_DEBUG);
}
}
}
$app->services->restartServiceDelayed('httpd', 'reload');
}
......
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