Ejemplo n.º 1
0
function check_rsync_error($ID, $results)
{
    if (!is_array($results)) {
        return true;
    }
    while (list($num, $line) = each($results)) {
        if (preg_match("#rsync error#", $line)) {
            if (preg_match("#some files\\/attrs were not transferred#", $line)) {
                continue;
            }
            if (preg_match("#some files vanished before they could be transferred#", $line)) {
                continue;
            }
            writelogs(date('m-d H:i:s') . " " . "[TASK {$ID}]: {$line} ", __FUNCTION__, __FILE__, __LINE__);
            if ($ID > 0) {
                backup_events($ID, "Copy", "ERROR,{$line}", __LINE__);
                return false;
            }
        }
        if (preg_match("#rsync: mkstemp.*?failed:#", $line)) {
            if ($ID > 0) {
                backup_events($ID, "Copy", "ERROR,{$line}", __LINE__);
                return false;
            }
        }
    }
    return true;
}
Ejemplo n.º 2
0
function backupsite_mysql_database_mysqldump($database, $temporarySourceDir, $instance_id, $servername)
{
    include_once dirname(__FILE__) . '/ressources/class.mysql-multi.inc';
    $date_start = time();
    $q = new mysql();
    $TpmPrefix = null;
    $Socket = null;
    $RemotePathSuffix = null;
    $instancename = null;
    if ($instance_id > 0) {
        $q = new mysql_multi($instance_id);
        $instancename = " ({$mysql->MyServer}) ";
        $TpmPrefix = $instance_id;
        $Socket = " --socket={$q->SocketPath}";
        $RemotePathSuffix = "-{$q->MyServerCMDLINE}";
    }
    $sock = new sockets();
    $NoBzipForBackupDatabasesDump = $sock->GET_INFO("NoBzipForBackupDatabasesDump");
    if ($NoBzipForBackupDatabasesDump == null) {
        $NoBzipForBackupDatabasesDump = 1;
    }
    if ($temporarySourceDir == null) {
        $temporarySourceDir = "/home/mysqlhotcopy";
    }
    if ($q->mysql_password != null) {
        $password = "******";
    }
    if ($q->mysql_admin != null) {
        $user = "******";
    }
    if (!is_dir($temporarySourceDir)) {
        @mkdir($temporarySourceDir, 0755, true);
    }
    $unix = new unix();
    $mysqldump = $unix->find_program("mysqldump");
    $bzip2 = $unix->find_program("bzip2");
    if ($mysqldump == null) {
        writelogs("ERROR,[{$servername}] {$instancename} Unable to find mysqldump", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $target_file = "{$temporarySourceDir}/{$servername}.sql.tar.bz2";
    if (!is_dir(dirname($target_file))) {
        @mkdir(dirname($target_file), 0755, true);
    }
    $bzip2_cmd = "| {$bzip2} ";
    if ($NoBzipForBackupDatabasesDump == 1) {
        $bzip2_cmd = null;
        $target_file = "{$temporarySourceDir}/{$servername}.sql";
    }
    $cmd = "{$mysqldump}{$Socket}{$user}{$password} --single-transaction --skip-add-locks --skip-lock-tables {$database} {$bzip2_cmd}> {$target_file} 2>&1";
    if ($GLOBALS["VERBOSE"]) {
        writelogs(str_replace($password, "****", $cmd), __FUNCTION__, __FILE__, __LINE__);
    }
    writelogs("INFO,{$instancename} Dumping {$database} mysql database", __FUNCTION__, __FILE__, __LINE__);
    exec($cmd, $results);
    $date_end = time();
    $calculate = distanceOfTimeInWords($date_start, $date_end);
    writelogs("INFO,{$instancename} {$database} {$calculate}", __FUNCTION__, __FILE__, __LINE__);
    while (list($num_line, $evenement) = each($results)) {
        if ($GLOBALS["VERBOSE"]) {
            writelogs("{$instancename}{$evenement}", __FUNCTION__, __FILE__, __LINE__);
        }
        if (preg_match("#Error\\s+([0-9]+)#", $evenement)) {
            backup_events($ID, "mysql", "ERROR,{$instancename} {$evenement}", __LINE__);
            writelogs("ERROR,{$instancename} {$evenement}", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
    }
    if (!is_file("{$target_file}")) {
        writelogs("ERROR,{$instancename} Dumping {$database} mysql database failed, {$target_file} no such file or directory", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $size = $unix->file_size_human("{$target_file}");
    writelogs("INFO,{$instancename} END dumping {$database} mysql database ({$size})", __FUNCTION__, __FILE__, __LINE__);
}