Exemplo n.º 1
0
function MakeBackUp()
{
    global $db_path, $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DB_NAME, $MYSQL_CHARSET, $DOCUMENT_ROOT, $SUB_FOLDER, $TMP_FOLDER;
    // try to exec mysqldump
    $err_code = 127;
    if (strpos($MYSQL_HOST, ":")) {
        list($host, $port) = explode(":", $MYSQL_HOST);
        $host = "--host={$host} --port={$port}";
    } else {
        $host = "--host={$MYSQL_HOST}";
    }
    @exec("mysqldump {$host} -u {$MYSQL_USER} " . ($MYSQL_PASSWORD ? "-p{$MYSQL_PASSWORD} " : "") . ((double) mysql_get_server_info() > 4 ? " --default-character-set={$MYSQL_CHARSET} " : "") . " --add-drop-table --disable-keys --quick" . " --result-file=" . $TMP_FOLDER . "netcat.sql {$MYSQL_DB_NAME} 2>&1", $output, $err_code);
    if (!$err_code) {
        if (!prepend_file($TMP_FOLDER . 'netcat.sql', "SET NAMES '" . $MYSQL_CHARSET . "';\n\n")) {
            $err_code = 1;
        }
    }
    if ($err_code) {
        $mysql_dump = new MYSQL_DUMP($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_CHARSET);
        $result = $mysql_dump->dump_to_file($TMP_FOLDER . 'netcat.sql', $MYSQL_DB_NAME);
        if (!$result) {
            echo $mysql_dump->error();
        }
    }
}