Ejemplo n.º 1
0
function db_optimize()
{
    global $WORKING, $STATIC;
    trigger_error(sprintf(__('%d. try for database optimize...', 'backwpup'), $WORKING['DB_OPTIMIZE']['STEP_TRY']), E_USER_NOTICE);
    if (!isset($WORKING['DB_OPTIMIZE']['DONETABLE']) or !is_array($WORKING['DB_OPTIMIZE']['DONETABLE'])) {
        $WORKING['DB_OPTIMIZE']['DONETABLE'] = array();
    }
    mysql_update();
    //to backup
    $tabelstobackup = array();
    $result = mysql_query("SHOW TABLES FROM `" . $STATIC['WP']['DB_NAME'] . "`");
    //get table status
    if (!$result) {
        trigger_error(sprintf(__('Database error %1$s for query %2$s', 'backwpup'), mysql_error(), "SHOW TABLE STATUS FROM `" . $STATIC['WP']['DB_NAME'] . "`;"), E_USER_ERROR);
    }
    while ($data = mysql_fetch_row($result)) {
        if (!in_array($data[0], $STATIC['JOB']['dbexclude'])) {
            $tabelstobackup[] = $data[0];
        }
    }
    //Set num of todos
    $WORKING['STEPTODO'] = count($tabelstobackup);
    if (count($tabelstobackup) > 0) {
        maintenance_mode(true);
        foreach ($tabelstobackup as $table) {
            if (in_array($table, $WORKING['DB_OPTIMIZE']['DONETABLE'])) {
                continue;
            }
            $result = mysql_query('OPTIMIZE TABLE `' . $table . '`');
            if (!$result) {
                trigger_error(sprintf(__('Database error %1$s for query %2$s', 'backwpup'), mysql_error(), "OPTIMIZE TABLE `" . $table . "`"), E_USER_ERROR);
                continue;
            }
            $optimize = mysql_fetch_assoc($result);
            $WORKING['DB_OPTIMIZE']['DONETABLE'][] = $table;
            $WORKING['STEPDONE'] = count($WORKING['DB_OPTIMIZE']['DONETABLE']);
            if ($optimize['Msg_type'] == 'error') {
                trigger_error(sprintf(__('Result of table optimize for %1$s is: %2$s', 'backwpup'), $table, $optimize['Msg_text']), E_USER_ERROR);
            } elseif ($optimize['Msg_type'] == 'warning') {
                trigger_error(sprintf(__('Result of table optimize for %1$s is: %2$s', 'backwpup'), $table, $optimize['Msg_text']), E_USER_WARNING);
            } else {
                trigger_error(sprintf(__('Result of table optimize for %1$s is: %2$s', 'backwpup'), $table, $optimize['Msg_text']), E_USER_NOTICE);
            }
        }
        trigger_error(__('Database optimize done!', 'backwpup'), E_USER_NOTICE);
        maintenance_mode(false);
    } else {
        trigger_error(__('No tables to optimize', 'backwpup'), E_USER_WARNING);
    }
    $WORKING['STEPSDONE'][] = 'DB_OPTIMIZE';
    //set done
}
Ejemplo n.º 2
0
function db_dump()
{
    global $WORKING, $STATIC;
    trigger_error(sprintf(__('%d. try for database dump...', 'backwpup'), $WORKING['DB_DUMP']['STEP_TRY']), E_USER_NOTICE);
    if (!isset($WORKING['DB_DUMP']['DONETABLE']) or !is_array($WORKING['DB_DUMP']['DONETABLE'])) {
        $WORKING['DB_DUMP']['DONETABLE'] = array();
    }
    mysql_update();
    //to backup
    $tabelstobackup = array();
    $result = mysql_query("SHOW TABLES FROM `" . $STATIC['WP']['DB_NAME'] . "`");
    //get table status
    if (!$result) {
        trigger_error(sprintf(__('Database error %1$s for query %2$s', 'backwpup'), mysql_error(), "SHOW TABLE STATUS FROM `" . $STATIC['WP']['DB_NAME'] . "`;"), E_USER_ERROR);
    }
    while ($data = mysql_fetch_row($result)) {
        if (!in_array($data[0], $STATIC['JOB']['dbexclude'])) {
            $tabelstobackup[] = $data[0];
        }
    }
    $WORKING['STEPTODO'] = count($tabelstobackup);
    //Set maintenance
    maintenance_mode(true);
    if (count($tabelstobackup) > 0) {
        $result = mysql_query("SHOW TABLE STATUS FROM `" . $STATIC['WP']['DB_NAME'] . "`");
        //get table status
        if (!$result) {
            trigger_error(sprintf(__('Database error %1$s for query %2$s', 'backwpup'), mysql_error(), "SHOW TABLE STATUS FROM `" . $STATIC['WP']['DB_NAME'] . "`;"), E_USER_ERROR);
        }
        while ($data = mysql_fetch_assoc($result)) {
            $status[$data['Name']] = $data;
        }
        if ($file = fopen($STATIC['TEMPDIR'] . $STATIC['WP']['DB_NAME'] . '.sql', 'wb')) {
            fwrite($file, "-- ---------------------------------------------------------\n");
            fwrite($file, "-- Dump with BackWPup ver.: " . $STATIC['BACKWPUP']['VERSION'] . "\n");
            fwrite($file, "-- Plugin for WordPress " . $STATIC['WP']['VERSION'] . " by Daniel Huesken\n");
            fwrite($file, "-- http://backwpup.com/\n");
            fwrite($file, "-- Blog Name: " . $STATIC['WP']['BLOGNAME'] . "\n");
            fwrite($file, "-- Blog URL: " . $STATIC['WP']['SITEURL'] . "\n");
            fwrite($file, "-- Blog ABSPATH: " . $STATIC['WP']['ABSPATH'] . "\n");
            fwrite($file, "-- Table Prefix: " . $STATIC['WP']['TABLE_PREFIX'] . "\n");
            fwrite($file, "-- Database Name: " . $STATIC['WP']['DB_NAME'] . "\n");
            fwrite($file, "-- Dump on: " . date('Y-m-d H:i.s', time() + $STATIC['WP']['TIMEDIFF']) . "\n");
            fwrite($file, "-- ---------------------------------------------------------\n\n");
            //for better import with mysql client
            fwrite($file, "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n");
            fwrite($file, "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n");
            fwrite($file, "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n");
            fwrite($file, "/*!40101 SET NAMES '" . mysql_client_encoding() . "' */;\n");
            fwrite($file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
            fwrite($file, "/*!40103 SET TIME_ZONE='" . mysql_result(mysql_query("SELECT @@time_zone"), 0) . "' */;\n");
            fwrite($file, "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n");
            fwrite($file, "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n");
            fwrite($file, "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n");
            fwrite($file, "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n\n");
            //make table dumps
            foreach ($tabelstobackup as $table) {
                if (in_array($table, $WORKING['DB_DUMP']['DONETABLE'])) {
                    continue;
                }
                _db_dump_table($table, $status[$table], $file);
                $WORKING['DB_DUMP']['DONETABLE'][] = $table;
                $WORKING['STEPDONE'] = count($WORKING['DB_DUMP']['DONETABLE']);
            }
            //for better import with mysql client
            fwrite($file, "\n");
            fwrite($file, "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n");
            fwrite($file, "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n");
            fwrite($file, "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n");
            fwrite($file, "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n");
            fwrite($file, "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n");
            fwrite($file, "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n");
            fwrite($file, "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
            fwrite($file, "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
            fclose($file);
            trigger_error(__('Database dump done!', 'backwpup'), E_USER_NOTICE);
        } else {
            trigger_error(__('Can not create database dump!', 'backwpup'), E_USER_ERROR);
        }
    } else {
        trigger_error(__('No tables to dump', 'backwpup'), E_USER_WARNING);
    }
    //add database file to backupfiles
    if (is_readable($STATIC['TEMPDIR'] . $STATIC['WP']['DB_NAME'] . '.sql')) {
        $filestat = stat($STATIC['TEMPDIR'] . $STATIC['WP']['DB_NAME'] . '.sql');
        trigger_error(sprintf(__('Add database dump "%1$s" with %2$s to backup file list', 'backwpup'), $STATIC['WP']['DB_NAME'] . '.sql', formatbytes($filestat['size'])), E_USER_NOTICE);
        $WORKING['ALLFILESIZE'] += $filestat['size'];
        add_file(array(array('FILE' => $STATIC['TEMPDIR'] . $STATIC['WP']['DB_NAME'] . '.sql', 'OUTFILE' => $STATIC['WP']['DB_NAME'] . '.sql', 'SIZE' => $filestat['size'], 'ATIME' => $filestat['atime'], 'MTIME' => $filestat['mtime'], 'CTIME' => $filestat['ctime'], 'UID' => $filestat['uid'], 'GID' => $filestat['gid'], 'MODE' => $filestat['mode'])));
    }
    //Back from maintenance
    maintenance_mode(false);
    $WORKING['STEPSDONE'][] = 'DB_DUMP';
    //set done
}
Ejemplo n.º 3
0
function db_check()
{
    global $WORKING, $STATIC;
    trigger_error(sprintf(__('%d. try for database check...', 'backwpup'), $WORKING['DB_CHECK']['STEP_TRY']), E_USER_NOTICE);
    if (!isset($WORKING['DB_CHECK']['DONETABLE']) or !is_array($WORKING['DB_CHECK']['DONETABLE'])) {
        $WORKING['DB_CHECK']['DONETABLE'] = array();
    }
    mysql_update();
    //to backup
    $tabelstobackup = array();
    $result = mysql_query("SHOW TABLES FROM `" . $STATIC['WP']['DB_NAME'] . "`");
    //get table status
    if (!$result) {
        trigger_error(sprintf(__('Database error %1$s for query %2$s', 'backwpup'), mysql_error(), "SHOW TABLE STATUS FROM `" . $STATIC['WP']['DB_NAME'] . "`;"), E_USER_ERROR);
    }
    while ($data = mysql_fetch_row($result)) {
        if (!in_array($data[0], $STATIC['JOB']['dbexclude'])) {
            $tabelstobackup[] = $data[0];
        }
    }
    //Set num of todos
    $WORKING['STEPTODO'] = sizeof($tabelstobackup);
    //check tables
    if (count($tabelstobackup) > 0) {
        maintenance_mode(true);
        foreach ($tabelstobackup as $table) {
            if (in_array($table, $WORKING['DB_CHECK']['DONETABLE'])) {
                continue;
            }
            $result = mysql_query('CHECK TABLE `' . $table . '` MEDIUM');
            if (!$result) {
                trigger_error(sprintf(__('Database error %1$s for query %2$s', 'backwpup'), mysql_error(), "CHECK TABLE `" . $table . "` MEDIUM"), E_USER_ERROR);
                continue;
            }
            $check = mysql_fetch_assoc($result);
            if ($check['Msg_type'] == 'error') {
                trigger_error(sprintf(__('Result of table check for %1$s is: %2$s', 'backwpup'), $table, $check['Msg_text']), E_USER_ERROR);
            } elseif ($check['Msg_type'] == 'warning') {
                trigger_error(sprintf(__('Result of table check for %1$s is: %2$s', 'backwpup'), $table, $check['Msg_text']), E_USER_WARNING);
            } else {
                trigger_error(sprintf(__('Result of table check for %1$s is: %2$s', 'backwpup'), $table, $check['Msg_text']), E_USER_NOTICE);
            }
            //Try to Repair tabele
            if ($check['Msg_type'] == 'error' or $check['Msg_type'] == 'warning') {
                $result = mysql_query('REPAIR TABLE `' . $table . '`');
                if (!$result) {
                    trigger_error(sprintf(__('Database error %1$s for query %2$s', 'backwpup'), mysql_error(), "REPAIR TABLE `'.{$table}.'`"), E_USER_ERROR);
                    continue;
                }
                $repair = mysql_fetch_assoc($result);
                if ($repair['Msg_type'] == 'error') {
                    trigger_error(sprintf(__('Result of table repair for %1$s is: %2$s', 'backwpup'), $table, $repair['Msg_text']), E_USER_ERROR);
                } elseif ($repair['Msg_type'] == 'warning') {
                    trigger_error(sprintf(__('Result of table repair for %1$s is: %2$s', 'backwpup'), $table, $repair['Msg_text']), E_USER_WARNING);
                } else {
                    trigger_error(sprintf(__('Result of table repair for %1$s is: %2$s', 'backwpup'), $table, $repair['Msg_text']), E_USER_NOTICE);
                }
            }
            $WORKING['DB_CHECK']['DONETABLE'][] = $table;
            $WORKING['STEPDONE'] = sizeof($WORKING['DB_CHECK']['DONETABLE']);
        }
        maintenance_mode(false);
        trigger_error(__('Database check done!', 'backwpup'), E_USER_NOTICE);
    } else {
        trigger_error(__('No tables to check', 'backwpup'), E_USER_WARNING);
    }
    $WORKING['STEPSDONE'][] = 'DB_CHECK';
    //set done
}