Esempio n. 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");
	
}
Esempio n. 2
0
function backup_freewebs($ID, $servername)
{
    include_once dirname(__FILE__) . "/ressources/class.freeweb.inc";
    $free = new freeweb($servername);
    backup_events($ID, $servername, "INFO, {$servername} Directory:`{$free->WORKING_DIRECTORY}`", __LINE__);
    $date_start = time();
    if (!is_dir("{$free->WORKING_DIRECTORY}")) {
        backup_events($ID, $servername, "ERROR, {$servername} Directory:`{$free->WORKING_DIRECTORY}` no such directory", __LINE__);
        return;
    }
    $DestinationPath = "{$GLOBALS["MOUNTED_PATH_FINAL"]}/freewebs/{$servername}/www";
    backup_mkdir($DestinationPath);
    if (!backup_isdir($DestinationPath)) {
        backup_events($ID, $servername, "ERROR, {$DestinationPath} permission denied or no such file or directory", __LINE__);
        return false;
    }
    $info = backup_copy($free->WORKING_DIRECTORY, "{$DestinationPath}", $ID);
    backup_events($ID, $servername, "INFO,{$free->WORKING_DIRECTORY}\n{$info}", __LINE__);
    if ($free->mysql_database != null) {
        $q = new mysql();
        if ($free->mysql_instance_id > 0) {
            $q = new mysql_multi($free->mysql_instance_id);
        }
        if (!$q->DATABASE_EXISTS($free->mysql_database)) {
            backup_events($ID, $servername, "ERROR,{$free->mysql_database} no such database", __LINE__);
            $date_end = time();
            $calculate = distanceOfTimeInWords($date_start, $date_end);
            backup_events($ID, $servername, "INFO, time: {$calculate}", __LINE__);
            return;
        }
        backup_mysql_database_mysqldump($ID, $free->mysql_database, "{$GLOBALS["MOUNTED_PATH_FINAL"]}/freewebs/{$servername}/MySQL", $free->mysql_instance_id);
    }
    $date_end = time();
    $calculate = distanceOfTimeInWords($date_start, $date_end);
    backup_events($ID, $servername, "INFO, time: {$calculate}", __LINE__);
}
Esempio n. 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}");
}