Commit 66fa9bdd authored by Florian Schaal's avatar Florian Schaal

FS#3897 - backup - delete unused file (interval = none), fixed mail-backup...

FS#3897 - backup - delete unused file (interval = none), fixed mail-backup delete, moved mail-function for failed mounts/umounts
parent 3fb090cb
......@@ -192,11 +192,16 @@ class cronjob_backup extends cronjob {
$web_user = $rec['system_user'];
$web_backup_dir = realpath($backup_dir.'/web'.$web_id);
if(is_dir($web_backup_dir)) {
exec('sudo -u '.escapeshellarg($web_user).' rm -f '.escapeshellarg($web_backup_dir.'/*'));
$sql = "DELETE FROM web_backup WHERE server_id = ? AND parent_domain_id = ?";
$app->db->query($sql, $conf['server_id'], $web_id);
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $web_id);
$dir_handle = opendir($web_backup_dir.'/');
while ($file = readdir($dir_handle)) {
if(!is_dir($file)) {
unlink ("$web_backup_dir/"."$file");
}
}
}
$sql = "DELETE FROM web_backup WHERE server_id = ? AND parent_domain_id = ?";
$app->db->query($sql, $conf['server_id'], $web_id);
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $web_id);
}
}
}
......@@ -353,15 +358,7 @@ class cronjob_backup extends cronjob {
}
//* end run_backups
if( $server_config['backup_dir_is_mount'] == 'y' ) $app->system->umount_backup_dir($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);
}
}
}
}
// delete files from backup download dir (/var/www/example.com/backup)
......
......@@ -66,7 +66,6 @@ class cronjob_backup_mail extends cronjob {
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']));
if(is_array($records) && $run_backups) {
if(!is_dir($backup_dir)) {
mkdir(escapeshellcmd($backup_dir), $backup_dir_permissions, true);
......@@ -76,12 +75,13 @@ class cronjob_backup_mail extends cronjob {
foreach($records as $rec) {
//* Do the mailbox backup
$email = $rec['email'];
$temp = explode("@",$email);
$domain = $temp[1];
unset($temp);
$domain_rec=$app->db->queryOneRecord("SELECT * FROM mail_domain WHERE domain = ?", $domain);
if($rec['backup_interval'] == 'daily' or ($rec['backup_interval'] == 'weekly' && date('w') == 0) or ($rec['backup_interval'] == 'monthly' && date('d') == '01')) {
$email = $rec['email'];
$temp = explode("@",$email);
$domain = $temp[1];
unset($temp);;
$domain_rec=$app->db->queryOneRecord("SELECT * FROM mail_domain WHERE domain = ?", $domain);
$backupusername = 'root';
$backupgroup = 'root';
......@@ -194,23 +194,29 @@ class cronjob_backup_mail extends cronjob {
unset($dir_handle);
}
/* Remove inactive backups */
if($rec['backup_interval'] == 'none') {
/* remove backups from db */
$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'], $rec['mailuser_id']);
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $domain_rec['domain_id'], $rec['mailuser_id']);
if($rec['backup_interval'] == 'none' || $rec['backup_interval'] == '') {
/* remove archives */
$mail_backup_dir = $backup_dir.'/mail'.$rec['domain_id'];
$mail_backup_dir = realpath($backup_dir.'/mail'.$domain_rec['domain_id']);
$mail_backup_file = 'mail'.$rec['mailuser_id'].'_*';
if(is_dir($mail_backup_dir)) {
foreach (glob($mail_backup_dir.'/'.$mail_backup_file) as $filename) {
unlink($filename);
$dir_handle = opendir($mail_backup_dir.'/');
while ($file = readdir($dir_handle)) {
if(!is_dir($file)) {
unlink ("$mail_backup_dir/"."$file");
}
}
}
/* remove backups from db */
$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'], $rec['mailuser_id']);
if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $domain_rec['domain_id'], $rec['mailuser_id']);
}
}
if( $server_config['backup_dir_is_mount'] == 'y' ) $app->system->umount_backup_dir($backup_dir);
} //* end run_backups
//* end run_backups
}
}
parent::onRunJob();
......
......@@ -1802,6 +1802,8 @@ class system{
}
function mount_backup_dir($backup_dir, $mount_cmd = '/usr/local/ispconfig/server/scripts/backup_dir_mount.sh'){
global $app, $conf;
$mounted = true;
if ( is_file($mount_cmd) &&
is_executable($mount_cmd) &&
......@@ -1813,11 +1815,22 @@ class system{
if (!$this->is_mounted($backup_dir)) $mounted = false;
}
} else $mounted = false;
if (!$mounted) {
//* 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".$mount_cmd."\n\nfailed.";
mail($global_config['admin_mail'], $subject, $message);
}
}
return $mounted;
}
function umount_backup_dir($backup_dir, $mount_cmd = '/usr/local/ispconfig/server/scripts/backup_dir_umount.sh'){
global $app, $conf;
if ( is_file($mount_cmd) &&
is_executable($mount_cmd) &&
fileowner($mount_cmd) === 0
......@@ -1828,7 +1841,19 @@ class system{
}
}
return $this->is_mounted($backup_dir) == 0 ? true : false;
$unmounted = $this->is_mounted($backup_dir) == 0 ? true : false;
if(!$unmounted) {
//* send email to admin that backup directory could not be unmounted
$global_config = $app->getconf->get_global_config('mail');
if($global_config['admin_mail'] != ''){
$subject = 'Backup directory '.$backup_dir.' could not be unmounted';
$message = "Backup directory ".$backup_dir." could not be unmounted.\n\nThe command\n\n".$mount_cmd."\n\nfailed.";
mail($global_config['admin_mail'], $subject, $message);
}
}
return $unmounted;
}
function getinitcommand($servicename, $action, $init_script_directory = ''){
......
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