Beispiel #1
0
function backup_mysql($ID){
	$sock=new sockets();	
	$unix=new unix();
	$date_start=time();
	$mysqlhotcopy=$unix->find_program("mysqlhotcopy");
	$email_spacer="==========================================";
	
	
	if($mysqlhotcopy==null){
		backup_events($ID,"mysql","ERROR, unable to stat mysqlhotcopy");
		events("ERROR, unable to stat mysqlhotcopy",__FUNCTION__,__LINE__);
		send_email_events("Backup Task $ID:: Unable to backup mysql datas ","ERROR, unable to stat mysqlhotcopy","backup");
		return false;
	}
	
	$array=backup_mysql_databases_list($ID);
	if(!is_array($array)){
		events("ERROR, unable to get databases list",__FUNCTION__,__LINE__);
		send_email_events("Backup Task $ID:: Unable to backup mysql datas ","ERROR, unable to get databases list","backup");
		backup_events($ID,"mysql","ERROR, unable to get databases list");
		return false;		
	}
	
	
	$q=new mysql();
	if($q->mysql_password<>null){$password="******";}
	if($q->mysql_admin<>null){$user="******";}
	$temporarySourceDir=$sock->GET_INFO("ExecBackupTemporaryPath");
	if($temporarySourceDir==null){$temporarySourceDir="/home/mysqlhotcopy";}
	$temporarySourceDir="$temporarySourceDir/mysql";
	events("temporarySourceDir has ExecBackupTemporaryPath token was \"$temporarySourceDir\"",__FUNCTION__,__LINE__);
	events("Creating $temporarySourceDir",__FUNCTION__,__LINE__);
	
	
	@mkdir($temporarySourceDir,0666,true);
	if(!is_dir($temporarySourceDir)){
		events("Creating Unable to backup mysql datas ","ERROR, $temporarySourceDir permission denied or no such file or directory",__FUNCTION__,__LINE__);
		send_email_events("Backup Task $ID:: Unable to backup mysql datas ","ERROR, $temporarySourceDir permission denied or no such file or directory","backup");
		backup_events($ID,"mysql","ERROR, $temporarySourceDir permission denied or no such file or directory");
		return ;
	}
	
	backup_events($ID,"mysql","INFO, using $temporarySourceDir for temp backup");
	
	while (list ($num, $line) = each ($array)){
		if(trim($line)==null){continue;}
		$database_name=trim(basename($line));
		
		if(strtolower($database_name)=="log"){
			events("skipping database \"$database_name\"",__FUNCTION__,__LINE__);
			backup_events($ID,"mysql","INFO, mysqlhotcopy skip log database");
			continue;
		}
		
		if(strtolower($database_name)=="mysql"){
			events("skipping database \"$database_name\"",__FUNCTION__,__LINE__);
			backup_events($ID,"mysql","INFO, mysqlhotcopy skip mysql database");
			continue;
		}
				
		
		
		
		backup_events($ID,"mysql","INFO, mysqlhotcopy database ($database_name) stored in $line -> $temporarySourceDir");
		
		$mysqlhotcopy_command="$mysqlhotcopy --addtodest$user$password $database_name $temporarySourceDir 2>&1";
		events("\"$mysqlhotcopy_command\"",__FUNCTION__,__LINE__);
		exec($mysqlhotcopy_command,$results);
		
		while (list ($num_line, $evenement) = each ($results)){
			if(preg_match("#No space left on device#",$evenement)){
				events("ERROR, backup No space left on device ($temporarySourceDir)",__FUNCTION__,__LINE__);
				backup_events($ID,"mysql","ERROR, backup No space left on device ($temporarySourceDir)\n". implode("\n",$results));
				if(is_dir($temporarySourceDir)){shell_exec("/bin/rm -rf $temporarySourceDir/*");}
				return;
			}
			events("$evenement",__FUNCTION__,__LINE__);
			
			if(preg_match("#failed:#",$evenement)){
				events("ERROR, database: \"$database_name\" ($evenement)",__FUNCTION__,__LINE__);
				backup_events($ID,"mysql","ERROR, database: \"$database_name\" ($evenement)");
				$fulltext=@implode("\n",$results);
				send_email_events("Backup Task $ID:: database: \"$database_name\" failed to backup ","$email_spacer\n$mysqlhotcopy_command$email_spacer\nERROR:$email_spacer\n$evenement\n$email_spacer\n$fulltext","backup");
			}		
		}
		
		backup_events($ID,"mysql","INFO, backup $database_name\n". implode("\n",$results));
		
		if(strtolower($database_name)=="zarafa"){
			events("zarafa database -> backup_mysql_database_mysqldump($ID,zarafa,$temporarySourceDir)",__FUNCTION__,__LINE__);
			backup_mysql_database_mysqldump($ID,"zarafa",$temporarySourceDir);
		}

	}	
	backup_events($ID,"mysql","INFO, Send mysql backup to the \n". implode("\n",$results));
	
	
	events("Creating directory \"{$GLOBALS["MOUNTED_PATH_FINAL"]}/mysql\"",__FUNCTION__,__LINE__);
	backup_mkdir("{$GLOBALS["MOUNTED_PATH_FINAL"]}/mysql");
	backup_copy("$temporarySourceDir/*","mysql",$ID);
	backup_events($ID,"mysql","INFO, backup remove content of $temporarySourceDir/*");
	events("INFO, backup remove content of $temporarySourceDir/*",__FUNCTION__,__LINE__);
	if(is_dir($temporarySourceDir)){
		events("/bin/rm -rf $temporarySourceDir/*",__FUNCTION__,__LINE__);
		shell_exec("/bin/rm -rf $temporarySourceDir/*");
	}
	backup_events($ID,"mysql","INFO, backup END without known error");
	
	$date_end=time();
	$calculate=distanceOfTimeInWords($date_start,$date_end);
	events("INFO, time: $calculate",__FUNCTION__,__LINE__);
	backup_events($ID,"mysql","INFO, time: $calculate");
	
}
Beispiel #2
0
function backup_mysql($ID, $instance_id = 0)
{
    include_once dirname(__FILE__) . '/ressources/class.mysql-multi.inc';
    $sock = new sockets();
    $unix = new unix();
    $date_start = time();
    $TpmPrefix = null;
    $RemotePathSuffix = null;
    $instancename = null;
    $mysqlhotcopy = $unix->find_program("mysqlhotcopy");
    $email_spacer = "==========================================";
    if ($instance_id > 0) {
        $mysql = new mysql_multi($instance_id);
        $instancename = " ({$mysql->MyServer}) ";
    }
    if ($mysqlhotcopy == null) {
        backup_events($ID, "mysql", "ERROR, unable to stat mysqlhotcopy");
        if (is_file($unix->find_program("mysqldump"))) {
            backup_events($ID, "mysql", "INFO,{$instancename} switch to mysqldump processing");
            return backup_mysql_oldway($ID, $instance_id);
        }
        events("ERROR, unable to stat mysqlhotcopy", __FUNCTION__, __LINE__);
        send_email_events("Backup Task {$ID}:: Unable to backup mysql datas ", "ERROR, unable to stat mysqlhotcopy", "backup");
        return false;
    }
    $array = backup_mysql_databases_list($ID, $instance_id);
    if (!is_array($array)) {
        events("ERROR,{$instancename} unable to get databases list", __FUNCTION__, __LINE__);
        send_email_events("Backup Task {$ID}::{$instancename} Unable to backup mysql datas ", "ERROR, unable to get databases list", "backup");
        backup_events($ID, "mysql", "ERROR,{$instancename} unable to get databases list", __LINE__);
        return false;
    }
    $q = new mysql();
    if ($instance_id > 0) {
        $q = new mysql_multi($instance_id);
        $TpmPrefix = $instance_id;
        $Socket = " --socket={$q->SocketPath}";
        $RemotePathSuffix = "-{$q->MyServerCMDLINE}";
    }
    if ($q->mysql_password != null) {
        $password = "******";
    }
    if ($q->mysql_admin != null) {
        $user = "******";
    }
    $temporarySourceDir = $sock->GET_INFO("ExecBackupTemporaryPath");
    if ($temporarySourceDir == null) {
        $temporarySourceDir = "/home/mysqlhotcopy";
    }
    $temporarySourceDir = "{$temporarySourceDir}/mysql{$TpmPrefix}";
    events("temporarySourceDir has ExecBackupTemporaryPath token was \"{$temporarySourceDir}\"", __FUNCTION__, __LINE__);
    events("Creating {$temporarySourceDir}", __FUNCTION__, __LINE__);
    @mkdir($temporarySourceDir, 0755, true);
    if (!is_dir($temporarySourceDir)) {
        events("Creating Unable to backup mysql datas ", "ERROR,{$instancename} {$temporarySourceDir} permission denied or no such file or directory", __FUNCTION__, __LINE__);
        send_email_events("Backup Task {$ID}::{$instancename} Unable to backup mysql datas ", "ERROR, {$temporarySourceDir} permission denied or no such file or directory", "backup");
        backup_events($ID, "mysql", "ERROR,{$instancename} {$temporarySourceDir} permission denied or no such file or directory");
        return;
    }
    $BlacklistDatabases["performance_schema"] = true;
    $BlacklistDatabases["mysql"] = true;
    $BlacklistDatabases["log"] = true;
    backup_events($ID, "mysql", "INFO,{$instancename} using {$temporarySourceDir} for temp backup");
    while (list($num, $line) = each($array)) {
        if (trim($line) == null) {
            continue;
        }
        $database_name = trim(basename($line));
        $database_nameSTR = strtolower($database_name);
        if (isset($BlacklistDatabases[$database_nameSTR])) {
            events("{$instancename}skipping database \"{$database_name}\"", __FUNCTION__, __LINE__);
            backup_events($ID, "mysql", "INFO,{$instancename} mysqlhotcopy skip {$database_nameSTR} database", __LINE__);
            continue;
        }
        backup_events($ID, "mysql", "INFO,{$instancename} mysqlhotcopy database ({$database_name}) stored in {$line} -> {$temporarySourceDir}");
        $mysqlhotcopy_command = "{$mysqlhotcopy} --addtodest{$Socket}{$user}{$password} {$database_name} {$temporarySourceDir} 2>&1";
        events("\"{$mysqlhotcopy_command}\"", __FUNCTION__, __LINE__);
        exec($mysqlhotcopy_command, $results);
        while (list($num_line, $evenement) = each($results)) {
            if (preg_match("#No space left on device#", $evenement)) {
                events("ERROR, backup No space left on device ({$temporarySourceDir})", __FUNCTION__, __LINE__);
                backup_events($ID, "mysql", "ERROR,{$instancename} backup No space left on device ({$temporarySourceDir})\n" . implode("\n", $results));
                if (is_dir($temporarySourceDir)) {
                    shell_exec("/bin/rm -rf {$temporarySourceDir}/*");
                }
                return;
            }
            events("{$evenement}", __FUNCTION__, __LINE__);
            if (preg_match("#failed:#", $evenement)) {
                events("ERROR,{$instancename} database: \"{$database_name}\" ({$evenement})", __FUNCTION__, __LINE__);
                backup_events($ID, "mysql", "ERROR,{$instancename} database: \"{$database_name}\" ({$evenement})");
                $fulltext = @implode("\n", $results);
                send_email_events("Backup Task {$ID}::{$instancename} database: \"{$database_name}\" failed to backup ", "{$email_spacer}\n{$mysqlhotcopy_command}{$email_spacer}\nERROR:{$email_spacer}\n{$evenement}\n{$email_spacer}\n{$fulltext}", "backup");
            }
        }
        backup_events($ID, "mysql", "INFO,{$instancename} backup {$database_name}\n" . implode("\n", $results), __LINE__);
        if (strtolower($database_name) == "zarafa") {
            events("{$instancename}zarafa database -> backup_mysql_database_mysqldump({$ID},zarafa,{$temporarySourceDir})", __FUNCTION__, __LINE__);
            backup_mysql_database_mysqldump($ID, "zarafa", $temporarySourceDir, $instance_id);
        }
    }
    backup_events($ID, "mysql", "INFO,{$instancename} Send mysql backup to the \n" . implode("\n", $results));
    events("Create directory \"{$GLOBALS["MOUNTED_PATH_FINAL"]}/mysql{$RemotePathSuffix}\"", __FUNCTION__, __LINE__);
    backup_mkdir("{$GLOBALS["MOUNTED_PATH_FINAL"]}/mysql{$RemotePathSuffix}");
    backup_copy("{$temporarySourceDir}/*", "mysql{$RemotePathSuffix}", $ID);
    backup_events($ID, "mysql", "INFO,{$instancename} backup remove content of {$temporarySourceDir}/*");
    events("INFO,{$instancename} backup remove content of {$temporarySourceDir}/*", __FUNCTION__, __LINE__);
    if (is_dir($temporarySourceDir)) {
        events("/bin/rm -rf {$temporarySourceDir}/*", __FUNCTION__, __LINE__);
        shell_exec("/bin/rm -rf {$temporarySourceDir}/*");
    }
    backup_events($ID, "mysql", "INFO,{$instancename} backup END without known error");
    $date_end = time();
    $calculate = distanceOfTimeInWords($date_start, $date_end);
    events("INFO,{$instancename} time: {$calculate}", __FUNCTION__, __LINE__);
    backup_events($ID, "mysql", "INFO,{$instancename} time: {$calculate}");
}
Beispiel #3
0
function backup_mysql($ID)
{
    $sock = new sockets();
    $unix = new unix();
    $date_start = time();
    $mysqlhotcopy = $unix->find_program("mysqlhotcopy");
    if ($mysqlhotcopy == null) {
        backup_events($ID, "mysql", "ERROR, unable to stat mysqlhotcopy");
        return false;
    }
    $array = backup_mysql_databases_list($ID);
    if (!is_array($array)) {
        backup_events($ID, "mysql", "ERROR, unable to get databases list");
        return false;
    }
    $q = new mysql();
    if ($q->mysql_password != null) {
        $password = "******";
    }
    if ($q->mysql_admin != null) {
        $user = "******";
    }
    $temporarySourceDir = $sock->GET_INFO("ExecBackupTemporaryPath");
    if ($temporarySourceDir == null) {
        $temporarySourceDir = "/home/mysqlhotcopy";
    }
    $temporarySourceDir = "{$temporarySourceDir}/mysql";
    @mkdir($temporarySourceDir, 0666, true);
    if (!is_dir($temporarySourceDir)) {
        backup_events($ID, "mysql", "ERROR, {$temporarySourceDir} permission denied or no such file or directory");
        return;
    }
    backup_events($ID, "mysql", "INFO, using {$temporarySourceDir} for temp backup");
    while (list($num, $line) = each($array)) {
        if (trim($line) == null) {
            continue;
        }
        backup_events($ID, "mysql", "INFO, mysqlhotcopy ({$line}) -> {$temporarySourceDir}");
        unset($results);
        exec("{$mysqlhotcopy} --addtodest{$user}{$password} {$line} {$temporarySourceDir} 2>&1", $results);
        while (list($num_line, $evenement) = each($results)) {
            if (preg_match("#No space left on device#", $evenement)) {
                backup_events($ID, "mysql", "ERROR, backup No space left on device ({$temporarySourceDir})\n" . implode("\n", $results));
                if (is_dir($temporarySourceDir)) {
                    shell_exec("/bin/rm -rf {$temporarySourceDir}/*");
                }
                return;
            }
        }
        backup_events($ID, "mysql", "INFO, backup {$line}\n" . implode("\n", $results));
        if (strtolower($line) == "zarafa") {
            backup_mysql_database_mysqldump($ID, "zarafa", $temporarySourceDir);
        }
    }
    backup_events($ID, "mysql", "INFO, Send mysql backup to the \n" . implode("\n", $results));
    backup_mkdir("{$GLOBALS["MOUNTED_PATH_FINAL"]}/mysql");
    backup_copy("{$temporarySourceDir}/*", "mysql", $ID);
    backup_events($ID, "mysql", "INFO, backup remove content of {$temporarySourceDir}/*");
    if (is_dir($temporarySourceDir)) {
        shell_exec("/bin/rm -rf {$temporarySourceDir}/*");
    }
    backup_events($ID, "mysql", "INFO, backup END without known error");
    $date_end = time();
    $calculate = distanceOfTimeInWords($date_start, $date_end);
    backup_events($ID, "mysql", "INFO, time: {$calculate}");
}