示例#1
0
 // delete old backup files
 PMBP_get_backup_files();
 // save PMBP_SYS_VARS
 if ($mode == "web") {
     PMBP_save_export_settings();
 }
 // in shell mode the dbs must be seperated with commas
 if ($mode == "shell") {
     $db_list = explode(",", $_POST['db']);
 } elseif (!isset($_POST['db'][0])) {
     $db_list = FALSE;
 } else {
     $db_list = $_POST['db'];
 }
 // get all available databases
 $available_dbs = PMBP_get_db_list();
 // always backup all dbs in scheduled mode, if the system variable is set
 if ($mode == "incl" && $PMBP_SYS_VAR["schedule_all_dbs"]) {
     $db_list = $available_dbs;
 }
 // is a database selected?
 if ($db_list) {
     foreach ($db_list as $export_db) {
         // check if $export_db is available
         if (in_array($export_db, $available_dbs)) {
             // generate db dump
             $backupfile = PMBP_dump($export_db, $_POST['tables'] == "on", $_POST['data'] == "on", $_POST['drop'] == "on", $_POST['zip'], $_POST['comments']);
             // is there no db connection or a db missing?
             if ($backupfile && $backupfile !== "DB_ERROR") {
                 // change mode to 0777
                 @chmod("./" . $backupfile, 0777);
示例#2
0
        if (function_exists("microtime")) {
            $microtime = explode(" ", microtime());
            $endtime = $microtime[0] + $microtime[1];
        } else {
            $endtime = time();
        }
        echo "<div class=\"bold_left\">" . F_DURATION . ": " . number_format($endtime - $starttime, 3) . " " . F_SECONDS . "</div><br><br>\n";
    }
}
// print html form and show last selected database and last queries
echo "<form action=\"sql_query.php\" method=\"post\" name=\"sql\" enctype=\"multipart/form-data\">\n<div>\n";
echo "<div class=\"bold_left\">" . SQ_WARNING . "</div>\n";
// print database select
echo SQ_SELECT_DB . ":<br><select name=\"db\">";
if (count(PMBP_get_db_list()) > 0) {
    foreach (PMBP_get_db_list() as $db) {
        $selected = "";
        if (isset($_POST['db'])) {
            if ($_POST['db'] == $db) {
                $selected = " selected";
            }
        }
        echo "<option value='" . $db . "'" . $selected . ">" . $db . "</option>\n";
    }
} else {
    echo "<option></option>\n";
}
echo "</select>\n<br>";
// print sql textarea and submit button
echo "<br>" . SQ_INSERT . ":<br>\n<textarea name=\"sql_query\" rows=\"10\" cols=\"80\">" . $sql_print . "</textarea>";
echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"3000000\">";
示例#3
0
function PMBP_dump($db, $tables, $data, $drop, $zip, $comment)
{
    global $CONF;
    global $PMBP_SYS_VAR;
    $error = FALSE;
    // set max string size before writing to file
    if (@ini_get("memory_limit")) {
        $max_size = 900000 * ini_get("memory_limit");
    } else {
        $max_size = $PMBP_SYS_VAR['memory_limit'];
    }
    // set backupfile name
    $time = time();
    if ($zip == "gzip") {
        $backupfile = $db . "." . $time . ".sql.gz";
    } else {
        $backupfile = $db . "." . $time . ".sql";
    }
    $backupfile = PMBP_EXPORT_DIR . $backupfile;
    if ($con = @mysql_connect($CONF['sql_host'], $CONF['sql_user'], $CONF['sql_passwd'])) {
        //create comment
        $out = "# MySQL dump of database '" . $db . "' on host '" . $CONF['sql_host'] . "'\n";
        $out .= "# backup date and time: " . strftime($CONF['date'], $time) . "\n";
        $out .= "# built by phpMyBackupPro " . PMBP_VERSION . "\n";
        $out .= "# " . PMBP_WEBSITE . "\n\n";
        // write users comment
        if ($comment) {
            $out .= "# comment:\n";
            $comment = preg_replace("'\n'", "\n# ", "# " . $comment);
            foreach (explode("\n", $comment) as $line) {
                $out .= $line . "\n";
            }
            $out .= "\n";
        }
        // print "use database" if more than one databas is available
        if (count(PMBP_get_db_list()) > 1) {
            $out .= "CREATE DATABASE IF NOT EXISTS `" . $db . "`;\n\n";
            $out .= "USE `" . $db . "`;\n";
        }
        // select db
        @mysql_select_db($db);
        // get auto_increment values and names of all tables
        $res = mysql_query("show table status");
        $all_tables = array();
        while ($row = mysql_fetch_array($res)) {
            $all_tables[] = $row;
        }
        // get table structures
        foreach ($all_tables as $table) {
            $res1 = mysql_query("SHOW CREATE TABLE `" . $table['Name'] . "`");
            $tmp = mysql_fetch_array($res1);
            $table_sql[$table['Name']] = $tmp["Create Table"];
        }
        // find foreign keys
        $fks = array();
        if (isset($table_sql)) {
            foreach ($table_sql as $tablenme => $table) {
                $tmp_table = $table;
                // save all tables, needed for creating this table in $fks
                while (($ref_pos = strpos($tmp_table, " REFERENCES ")) > 0) {
                    $tmp_table = substr($tmp_table, $ref_pos + 12);
                    $ref_pos = strpos($tmp_table, "(");
                    $fks[$tablenme][] = substr($tmp_table, 0, $ref_pos);
                }
            }
        }
        // order $all_tables and check for ring constraints
        $all_tables_copy = $all_tables;
        $all_tables = PMBP_order_sql_tables($all_tables, $fks);
        $ring_contraints = false;
        // ring constraints found
        if ($all_tables === false) {
            $ring_contraints = true;
            $all_tables = $all_tables_copy;
            $out .= "\n# ring constraints workaround\n";
            $out .= "SET FOREIGN_KEY_CHECKS=0;\n";
            $out .= "SET AUTOCOMMIT=0;\n";
            $out .= "START TRANSACTION;\n";
        }
        unset($all_tables_copy);
        // as long as no error occurred
        if (!$error) {
            foreach ($all_tables as $row) {
                $tablename = $row['Name'];
                $auto_incr[$tablename] = $row['Auto_increment'];
                // don't backup tables in $PMBP_SYS_VAR['except_tables']
                if (in_array($tablename, explode(",", $PMBP_SYS_VAR['except_tables']))) {
                    continue;
                }
                $out .= "\n\n";
                // export tables
                if ($tables) {
                    $out .= "### structure of table `" . $tablename . "` ###\n\n";
                    if ($drop) {
                        $out .= "DROP TABLE IF EXISTS `" . $tablename . "`;\n\n";
                    }
                    $out .= $table_sql[$tablename];
                    // add auto_increment value
                    if ($auto_incr[$tablename]) {
                        $out .= " AUTO_INCREMENT=" . $auto_incr[$tablename];
                    }
                    $out .= ";";
                }
                $out .= "\n\n\n";
                // export data
                if ($data && !$error) {
                    $out .= "### data of table `" . $tablename . "` ###\n\n";
                    // check if field types are NULL or NOT NULL
                    $res3 = mysql_query("show columns from `" . $tablename . "`");
                    $res2 = mysql_query("select * from `" . $tablename . "`");
                    for ($j = 0; $j < mysql_num_rows($res2); $j++) {
                        $out .= "insert into `" . $tablename . "` values (";
                        $row2 = mysql_fetch_row($res2);
                        // run through each field
                        for ($k = 0; $k < ($nf = mysql_num_fields($res2)); $k++) {
                            // identify null values and save them as null instead of ''
                            if (is_null($row2[$k])) {
                                $out .= "null";
                            } else {
                                $out .= "'" . mysql_escape_string($row2[$k]) . "'";
                            }
                            if ($k < $nf - 1) {
                                $out .= ", ";
                            }
                        }
                        $out .= ");\n";
                        // if saving is successful, then empty $out, else set error flag
                        if (strlen($out) > $max_size) {
                            if ($out = PMBP_save_to_file($backupfile, $zip, $out, "a")) {
                                $out = "";
                            } else {
                                $error = TRUE;
                            }
                        }
                    }
                    // an error occurred! Try to delete file and return error status
                } elseif ($error) {
                    @unlink("./" . PMBP_EXPORT_DIR . $backupfile);
                    return FALSE;
                }
                // if saving is successful, then empty $out, else set error flag
                if (strlen($out) > $max_size) {
                    if ($out = PMBP_save_to_file($backupfile, $zip, $out, "a")) {
                        $out = "";
                    } else {
                        $error = TRUE;
                    }
                }
            }
            // an error occurred! Try to delete file and return error status
        } else {
            @unlink("./" . $backupfile);
            return FALSE;
        }
        // if db contained ring constraints
        if ($ring_contraints) {
            $out .= "\n\n# ring constraints workaround\n";
            $out .= "SET FOREIGN_KEY_CHECKS=1;\n";
            $out .= "COMMIT;\n";
        }
        // save to file
        if ($backupfile = PMBP_save_to_file($backupfile, $zip, $out, "a")) {
            if ($zip != "zip") {
                return basename($backupfile);
            }
        } else {
            @unlink("./" . $backupfile);
            return FALSE;
        }
        // create zip file in file system
        include_once "pclzip.lib.php";
        $pclzip = new PclZip($backupfile . ".zip");
        $pclzip->create($backupfile, PCLZIP_OPT_REMOVE_PATH, PMBP_EXPORT_DIR);
        // remove temporary plain text backup file used for zip compression
        @unlink(substr($backupfile, 0, strlen($backupfile)));
        if ($pclzip->error_code == 0) {
            return basename($backupfile) . ".zip";
        } else {
            // print pclzip error message
            echo "<div class=\"red\">pclzip: " . $pclzip->error_string . "</div>";
            // remove temporary plain text backup file
            @unlink(substr($backupfile, 0, strlen($backupfile) - 4));
            @unlink("./" . $backupfile);
            return FALSE;
        }
    } else {
        return "DB_ERROR";
    }
}
示例#4
0
文件: PMBP.inc.php 项目: nemiah/fheME
function PMBP_dump($CONF, $PMBP_SYS_VAR, $db, $tables, $data, $drop, $zip, $comment)
{
    set_time_limit(0);
    $error = false;
    $time = date("Ymd");
    if ($zip == "gzip") {
        $backupfile = $db . "." . $time . "_utf8.sql.gz";
    } else {
        $backupfile = $db . "." . $time . "_utf8.sql";
    }
    $backupfile = PMBP_EXPORT_DIR . $backupfile;
    $con = @mysqli_connect($CONF['sql_host'], $CONF['sql_user'], $CONF['sql_passwd']);
    if (!$con) {
        return "DB_ERROR";
    }
    mysqli_set_charset($con, "utf8");
    mysqli_query($con, "SET SESSION sql_mode='';");
    //create comment
    $hout = "# MySQL dump of database '" . $db . "' on host '" . $CONF['sql_host'] . "'\n";
    $hout .= "# backup date and time: " . date("d.m.Y H:i:s") . "\n";
    $hout .= "# " . PMBP_WEBSITE . "\n\n";
    // write users comment
    if ($comment) {
        $hout .= "# comment:\n";
        $comment = preg_replace("'\n'", "\n# ", "# " . $comment);
        foreach (explode("\n", $comment) as $line) {
            $hout .= $line . "\n";
        }
        $hout .= "\n";
    }
    // print "use database" if more than one databas is available
    if (count(PMBP_get_db_list($CONF)) > 1) {
        $hout .= "CREATE DATABASE IF NOT EXISTS `" . $db . "`;\n\n";
        $hout .= "USE `" . $db . "`;\n";
    }
    PMBP_save_to_file($backupfile, $zip, $hout, "a");
    $hout = "";
    // select db
    mysqli_select_db($con, $db);
    // get auto_increment values and names of all tables
    $res = mysqli_query($con, "show table status");
    $all_tables = array();
    while ($row = mysqli_fetch_array($res)) {
        if ($row["Comment"] == "VIEW") {
            continue;
        }
        $all_tables[] = $row;
    }
    // get table structures
    foreach ($all_tables as $table) {
        $res1 = mysqli_query($con, "SHOW CREATE TABLE `" . $table['Name'] . "`");
        $tmp = mysqli_fetch_array($res1);
        $table_sql[$table['Name']] = $tmp["Create Table"];
    }
    // find foreign keys
    $fks = array();
    if (isset($table_sql)) {
        foreach ($table_sql as $tablenme => $table) {
            $tmp_table = $table;
            // save all tables, needed for creating this table in $fks
            while (($ref_pos = strpos($tmp_table, " REFERENCES ")) > 0) {
                $tmp_table = substr($tmp_table, $ref_pos + 12);
                $ref_pos = strpos($tmp_table, "(");
                $fks[$tablenme][] = substr($tmp_table, 0, $ref_pos);
            }
        }
    }
    foreach ($all_tables as $row) {
        $tablename = $row['Name'];
        $auto_incr[$tablename] = $row['Auto_increment'];
        $kout = "\n\n";
        if ($tables) {
            if ($drop) {
                $kout .= "DROP TABLE IF EXISTS `" . $tablename . "`;\n\n";
            }
            $kout .= $table_sql[$tablename];
            // add auto_increment value
            if ($auto_incr[$tablename] and strpos($kout, "AUTO_INCREMENT") === false) {
                $kout .= " AUTO_INCREMENT=" . $auto_incr[$tablename];
            }
            $kout .= ";";
        }
        $kout .= "\n\n\n";
        PMBP_save_to_file($backupfile, $zip, $kout, "a");
        $kout = "";
        if ($error) {
            @unlink("./" . PMBP_EXPORT_DIR . $backupfile);
            return false;
        }
        // export data
        if ($data && !$error) {
            // check if field types are NULL or NOT NULL
            #$res3 = mysqli_query($con, "show columns from `" . $tablename . "`");
            $res2 = mysqli_query($con, "SELECT * FROM `" . $tablename . "`", MYSQLI_USE_RESULT);
            while ($row2 = mysqli_fetch_row($res2)) {
                $sout = "INSERT INTO `" . $tablename . "` VALUES (";
                // run through each field
                foreach ($row2 as $k => $v) {
                    if (is_null($v)) {
                        $sout .= "null";
                    } else {
                        $sout .= "'" . mysqli_real_escape_string($con, $v) . "'";
                    }
                    if ($k < count($row2) - 1) {
                        $sout .= ", ";
                    }
                }
                $sout .= ");\n";
                PMBP_save_to_file($backupfile, $zip, $sout, "a");
                $sout = "";
            }
            mysqli_free_result($res2);
        }
    }
    $backupfile = PMBP_save_to_file($backupfile, $zip, "", "a");
    if ($backupfile) {
        if ($zip != "zip") {
            return basename($backupfile);
        }
    } else {
        @unlink("./" . $backupfile);
        return false;
    }
    // create zip file in file system
    include_once "pclzip.lib.php";
    $pclzip = new PclZip($backupfile . ".zip");
    $pclzip->create($backupfile, PCLZIP_OPT_REMOVE_PATH, PMBP_EXPORT_DIR);
    // remove temporary plain text backup file used for zip compression
    @unlink(substr($backupfile, 0, strlen($backupfile)));
    if ($pclzip->error_code == 0) {
        return basename($backupfile) . ".zip";
    } else {
        // print pclzip error message
        echo "<div class=\"red\">pclzip: " . $pclzip->error_string . "</div>";
        // remove temporary plain text backup file
        @unlink(substr($backupfile, 0, strlen($backupfile) - 4));
        @unlink("./" . $backupfile);
        return FALSE;
    }
}
示例#5
0
        $endtime = $microtime[0] + $microtime[1];
    } else {
        $endtime = time();
    }
    echo "<tr>\n<td colspan=\"4\">\n<br><div class=\"bold_left\">" . F_DURATION . ": " . number_format($endtime - $starttime, 3) . " " . F_SECONDS . "</div>\n</td>\n</tr>\n";
    echo "</table>\n</body>\n</html>";
    exit;
}
PMBP_print_header(ereg_replace(".*/", "", $_SERVER['SCRIPT_NAME']));
// if first use or no db-connection possible
if (!$con) {
    echo "<div class=\"red\">" . I_SQL_ERROR . "</div>";
}
echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"0\" width=\"100%\">\n";
// list all databases
$all_dbs = PMBP_get_db_list();
if (count($all_dbs)) {
    natsort($all_dbs);
    echo "<tr>\n<th class=\"active\">" . DB_NAME . "</th>\n<th class=\"active\">" . DB_NUM_TABLES . "</th>\n<th class=\"active\">" . DB_NUM_ROWS . "</th>\n<th class=\"active\">" . DB_SIZE . "</th>\n</tr>\n";
    // print html table
    foreach ($all_dbs as $db_name) {
        // select the db
        mysql_select_db($db_name, $con);
        $num_tables = $num_rows = $data_size = 0;
        // get number of rows and size of tables
        $stati = mysql_query("show table status", $con);
        while ($status = @mysql_fetch_array($stati)) {
            $data_size += $status['Data_length'] + $status['Index_length'];
            $num_rows += $status['Rows'];
        }
        $size = PMBP_size_type($data_size);
示例#6
0
$all_files = PMBP_get_backup_files();
// delete ALL backup files if the link was clicked
if ($_GET['del_ALL']) {
    $result = false;
    if (is_array($all_files)) {
        $result = PMBP_delete_backup_files($all_files);
    }
    if (!$result) {
        echo PMBP_addOutput(B_DELETED_ALL, "green");
    } else {
        echo PMBP_addOutput($result, "red");
    }
}
// empty ALL db if the link was clicked
if ($_GET['empty_ALL']) {
    foreach (PMBP_get_db_list() as $dbname) {
        empty_single_db($_GET['empty_all']);
    }
}
// empty db if the link was clicked
if ($_GET['empty_all']) {
    empty_single_db($_GET['empty_all']);
}
// delete all backup files of selected db if the link was clicked
if ($_GET['del_all']) {
    if (is_array($all_files)) {
        foreach ($all_files as $filename) {
            if ($_GET['del_all'] == PMBP_file_info("db", PMBP_EXPORT_DIR . $filename)) {
                $del_files[] = $filename;
            }
        }
示例#7
0
function PMBP_dump($db, $tables, $data, $drop, $zip, $comment)
{
    global $CONF;
    global $PMBP_SYS_VAR;
    $error = FALSE;
    // set max string size before writing to file
    if (@ini_get("memory_limit")) {
        $max_size = 500000 * ini_get("memory_limit");
    } else {
        ini_set("memory_limit", $PMBP_SYS_VAR['memory_limit'] / 1024000);
        $max_size = 500000 * ($PMBP_SYS_VAR['memory_limit'] / 1024000);
    }
    // set backupfile name
    $time = time();
    if ($zip == "gzip") {
        $backupfile = $db . "." . $time . ".sql.gz";
    } else {
        $backupfile = $db . "." . $time . ".sql";
    }
    $backupfile = PMBP_EXPORT_DIR . $backupfile;
    if ($con = PMBP_mysql_connect()) {
        // don't backup tables in $PMBP_SYS_VAR['except_tables']
        $except_tables = explode(",", $PMBP_SYS_VAR['except_tables']);
        //create comment
        $out = "# MySQL dump of database '" . $db . "' on host '" . $CONF['sql_host'] . "'\n";
        $out .= "# backup date and time: " . strftime($CONF['date'], $time) . "\n";
        $out .= "# LugrawibeBackup " . PMBP_VERSION . "\n";
        $out .= "# " . PMBP_WEBSITE . "\n\n";
        // write users comment
        if ($comment) {
            $out .= "# comment:\n";
            $comment = preg_replace("'\n'", "\n# ", "# " . $comment);
            foreach (explode("\n", $comment) as $line) {
                $out .= $line . "\n";
            }
            $out .= "\n";
        }
        // set and log character set
        $characterSet = PMBP_set_character_set();
        $out .= "### used character set: " . $characterSet . " ###\n";
        $out .= "set names " . $characterSet . ";\n\n";
        // print "use database" if more than one database is available
        if (count(PMBP_get_db_list()) > 1) {
            $out .= "CREATE DATABASE IF NOT EXISTS `" . $db . "`;\n\n";
            $out .= "USE `" . $db . "`;\n";
        }
        // select db
        @mysql_select_db($db);
        // get tables and views
        $tables_and_views = PMBP_list_tables_and_view();
        $all_tables = $tables_and_views['tables'];
        $all_views = $tables_and_views['views'];
        // get table structures
        $all_tables_new = array();
        foreach ($all_tables as $key => $table) {
            if (!in_array($table['Name'], $except_tables)) {
                $res1 = mysql_query("SHOW CREATE TABLE `" . $table['Name'] . "`");
                $tmp = mysql_fetch_array($res1);
                $table_sql[$table['Name']] = $tmp["Create Table"];
                $all_tables_new[$key] = $table;
            }
        }
        $all_tables = $all_tables_new;
        unset($all_tables_new);
        // find foreign keys
        $fks = array();
        if (isset($table_sql)) {
            foreach ($table_sql as $tablenme => $table) {
                $tmp_table = $table;
                // save all tables, needed for creating this table in $fks
                while (($ref_pos = strpos($tmp_table, " REFERENCES ")) > 0) {
                    $tmp_table = substr($tmp_table, $ref_pos + 12);
                    $ref_pos = strpos($tmp_table, "(");
                    // cut of '`' at the begining and end of fk-name
                    $fks[$tablenme][] = trim(str_replace('`', '', substr($tmp_table, 0, $ref_pos)));
                }
            }
        }
        // order $all_tables and check for ring constraints
        $all_tables_copy = $all_tables;
        $all_tables = PMBP_order_sql_tables($all_tables, $fks);
        $ring_constraints = false;
        // ring constraints found
        if ($all_tables === false) {
            $ring_constraints = true;
            $all_tables = $all_tables_copy;
            $out .= "\n# ring constraints workaround\n";
            $out .= "SET FOREIGN_KEY_CHECKS=0;\n";
            $out .= "SET AUTOCOMMIT=0;\n";
            $out .= "START TRANSACTION;\n";
        }
        unset($all_tables_copy);
        // as long as no error occurred
        if (!$error) {
            if ($drop) {
                $out .= "\n### drop all tables first ###\n";
                foreach (array_reverse($all_tables) as $row) {
                    $out .= "\nDROP TABLE IF EXISTS `" . $row['Name'] . "`;";
                }
                $out .= "\n";
            }
            foreach ($all_tables as $row) {
                $tablename = $row['Name'];
                $auto_incr[$tablename] = $row['Auto_increment'];
                $out .= "\n\n";
                // export tables
                if ($tables) {
                    $out .= "### structure of table `" . $tablename . "` ###\n\n";
                    $out .= $table_sql[$tablename];
                    // add auto_increment value
                    if ($auto_incr[$tablename]) {
                        $out .= " AUTO_INCREMENT=" . $auto_incr[$tablename];
                    }
                    $out .= ";";
                }
                $out .= "\n\n\n";
                // export data
                if ($data && !$error) {
                    $out .= "### data of table `" . $tablename . "` ###\n\n";
                    // check if field types are NULL or NOT NULL
                    $res3 = mysql_query("show columns from `" . $tablename . "`");
                    $res2 = mysql_query("select * from `" . $tablename . "`");
                    if ($res2) {
                        $number_of_rows = mysql_num_rows($res2);
                        if ($number_of_rows > 0) {
                            for ($j = 0; $j < $number_of_rows; $j++) {
                                $out .= "insert into `" . $tablename . "` values (";
                                $row2 = mysql_fetch_row($res2);
                                // run through each field
                                for ($k = 0; $k < ($nf = mysql_num_fields($res2)); $k++) {
                                    // identify null values and save them as null instead of ''
                                    if (is_null($row2[$k])) {
                                        $out .= "null";
                                    } else {
                                        $out .= "'" . mysql_real_escape_string($row2[$k]) . "'";
                                    }
                                    if ($k < $nf - 1) {
                                        $out .= ", ";
                                    }
                                }
                                $out .= ");\n";
                                // if saving is successful, then empty $out, else set error flag
                                if (strlen($out) > $max_size) {
                                    if ($out = PMBP_save_to_file($backupfile, $zip, $out, "a")) {
                                        $out = "";
                                    } else {
                                        $error = TRUE;
                                    }
                                }
                            }
                        } else {
                            $out .= "-- table is empty\n";
                            // no data
                        }
                    } else {
                        echo "MySQL error: " . mysql_error();
                        @unlink(PMBP_EXPORT_DIR . $backupfile);
                        return FALSE;
                    }
                    // an error occurred! Try to delete file and return error status
                } elseif ($error) {
                    @unlink(PMBP_EXPORT_DIR . $backupfile);
                    return FALSE;
                }
                // if saving is successful, then empty $out, else set error flag
                if (strlen($out) > $max_size) {
                    if ($out = PMBP_save_to_file($backupfile, $zip, $out, "a")) {
                        $out = "";
                    } else {
                        $error = TRUE;
                    }
                }
            }
            // views
            // get all view definitions
            $all_views_definitions = array();
            foreach ($all_views as $row) {
                $viewname = $row['Name'];
                if (!in_array($viewname, $except_tables)) {
                    $res4 = mysql_query("show create view `" . $viewname . "`");
                    if ($res4) {
                        $row4 = mysql_fetch_array($res4);
                        $all_views_definitions[$viewname] = $row4['Create View'];
                    } else {
                        echo "MySQL error: " . mysql_error();
                        @unlink(PMBP_EXPORT_DIR . $backupfile);
                        return FALSE;
                    }
                }
            }
            if (sizeof($all_views_definitions) > 0) {
                $out .= "\n\n### views ###\n\n";
            }
            // order $all_views and check for ring constraints
            $all_views_definitions_copy = $all_views_definitions;
            $all_views_definitions = PMBP_order_sql_views($all_views_definitions);
            $ring_constraints = false;
            // ring constraints found
            if ($all_views_definitions === false) {
                $all_views_definitions = $all_views_definitions_copy;
                // if not already written because of tabel ring constraints
                if (!$ring_constraints) {
                    $out .= "\n# ring constraints workaround\n";
                    $out .= "SET FOREIGN_KEY_CHECKS=0;\n";
                    $out .= "SET AUTOCOMMIT=0;\n";
                    $out .= "START TRANSACTION;\n";
                }
                $ring_constraints = true;
            }
            unset($all_views_definitions_copy);
            // view drop statements (in reverse order)
            if ($drop && count($all_views_definitions) > 0) {
                $out .= "### drop all views first ###\n\n";
                foreach (array_reverse($all_views_definitions) as $view_name => $view_definition) {
                    $out .= "DROP VIEW IF EXISTS `" . $view_name . "`;\n";
                }
                $out .= "\n\n";
            }
            // view definitions
            foreach ($all_views_definitions as $view_name => $view_definition) {
                $out .= "### create statement of view `" . $view_name . "` ###\n\n";
                $out .= $view_definition;
                $out .= ";\n\n";
            }
            // if saving is successful, then empty $out, else set error flag
            if (strlen($out) > $max_size) {
                if ($out = PMBP_save_to_file($backupfile, $zip, $out, "a")) {
                    $out = "";
                } else {
                    $error = TRUE;
                }
            }
            // an error occurred! Try to delete file and return error status
        } else {
            @unlink($backupfile);
            return FALSE;
        }
        // if db contained ring constraints
        if ($ring_constraints) {
            $out .= "\n\n# ring constraints workaround\n";
            $out .= "SET FOREIGN_KEY_CHECKS=1;\n";
            $out .= "COMMIT;\n";
        }
        // save to file
        if ($backupfile = PMBP_save_to_file($backupfile, $zip, $out, "a")) {
            if ($zip != "zip") {
                return basename($backupfile);
            }
        } else {
            @unlink($backupfile);
            return FALSE;
        }
        // create zip file in file system
        include_once "pclzip.lib.php";
        $pclzip = new PclZip($backupfile . ".zip");
        $pclzip->create($backupfile, PCLZIP_OPT_REMOVE_PATH, PMBP_EXPORT_DIR);
        // remove temporary plain text backup file used for zip compression
        @unlink(substr($backupfile, 0, strlen($backupfile)));
        if ($pclzip->error_code == 0) {
            return basename($backupfile) . ".zip";
        } else {
            // print pclzip error message
            echo PMBP_addOutput("pclzip: " . $pclzip->error_string, "red");
            // remove temporary plain text backup file
            @unlink(substr($backupfile, 0, strlen($backupfile) - 4));
            @unlink($backupfile);
            return FALSE;
        }
    } else {
        return "DB_ERROR";
    }
}