Exemple #1
0
 function fallback()
 {
     $host = $this->db->hostname;
     $username = $this->db->username;
     $password = $this->db->password;
     $db = $this->db->database;
     //print_array($password);
     backup_database($username, $password, $host, $db);
 }
<?php

include_once "constantes.php";
include_once "DBConnector.php";
$dbhost = 'localhost';
$dbuser = '******';
$dbpass = '******';
$dbname = 'bdActivos';
$dir = 'C:\\xampp\\htdocs\\proyectoActivosRespaldo\\Proyecto-Activos\\DB_backup';
// directory files
$name = 'backup';
// name sql backup
print_r(backup_database($dir, $name, 'localhost', 'ActivosMaster', '1234', 'bdActivos'));
// execute
function mysqli_import_sql($args, $dbhost, $dbuser, $dbpass, $dbname)
{
    // check mysqli extension installed
    if (!function_exists('mysqli_connect')) {
        die(' This scripts need mysql extension to be running properly ! please resolve!!');
    }
    $mysqli = @new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    if ($mysqli->connect_error) {
        print_r($mysqli->connect_error);
        return false;
    }
    $querycount = 11;
    $queryerrors = '';
    $lines = (array) $args;
    if (is_string($args)) {
        $lines = array($args);
    }
Exemple #3
0
                    header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
                    header('Connection: Keep-Alive');
                    header("Content-Transfer-Encoding: binary");
                    header('Expires: 0');
                    header('Pragma: no-cache');
                    echo $gzipoutput;
                }
            } else {
                $result = '<p>Error when executing database query to export.</p>' . $mysqli->error;
            }
        }
    } else {
        $result = '<p>Wrong mysqli input</p>';
    }
    if ($mysqli && !$mysqli->error) {
        @$mysqli->close();
    }
    return $result;
}
$dbname = 'gs';
$toDay = date('d-m-Y-g-i-s');
$dir = dirname(__FILE__);
// directory files
$name = 'backup';
// name sql backup
$nameBackup = backup_database($dir, $name . $toDay, DB_HOST, DB_USER, DB_PASS, DB_NAME);
// execute
// // import
// $file = dirname(__FILE__).'/data.sql'; // sql data file
// $args = file_get_contents($file); // get contents
// print_r( mysqli_import_sql( $args, 'localhost',  'user', 'password', 'databasename') ); // execute
 public function backup_db()
 {
     // \Cache::forget("last_db_backup");
     if (!\Cache::has('last_db_backup')) {
         \Cache::put('last_db_backup', time(), 5000);
         // 3.5 days
         // $dir  = "D:/xampp/htdocs/ahmed-badawy.com/backups/db"; // directory files
         $dir = base_path("backups/db");
         // directory files
         $db_name = "courtaks_maindb";
         $output_name = time() . "-" . $db_name;
         // output name sql backup
         $db_user_name = "root";
         $db_user_pass = "";
         $db_host = "localhost";
         backup_database($dir, $output_name, $db_host, $db_user_name, $db_user_pass, $db_name);
         // execute
     }
 }
<?php

require 'db_control_helper.php';
$dir = __DIR__ . "/backups";
// directory files
$db_name = "blog";
$output_name = time() . "-" . $db_name;
// output name sql backup
$db_host = "localhost";
$db_user_name = "root";
$db_user_pass = "";
backup_database($dir, $output_name, $db_host, $db_user_name, $db_user_pass, $db_name);
// execute
Exemple #6
0
if ($argv[1] == "--install-progress") {
    $GLOBALS["OUTPUT"] = true;
    $GLOBALS["PROGRESS"] = true;
    install();
    die;
}
if ($argv[1] == "--restart-progress") {
    $GLOBALS["OUTPUT"] = true;
    $GLOBALS["PROGRESS"] = true;
    restart_progress();
    die;
}
if ($argv[1] == "--backup") {
    $GLOBALS["OUTPUT"] = true;
    $GLOBALS["PROGRESS"] = true;
    backup_database();
    die;
}
if ($argv[1] == "--time") {
    timeZoneUTC();
    exit;
}
if ($argv[1] == "--config") {
    Config();
    exit;
}
if ($argv[1] == "--restore") {
    restore_influx();
    exit;
}
if ($argv[1] == "--tests") {
Exemple #7
0
        }
        // When no update was applied, stop trying. We are probably up to date
        // or stuck with an unupgradable version.
        break;
    }
}
$updates = array();
$updates[] = new Update(null, 1.1, array("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "cast` (\n    `movie_id` int(7) NOT NULL,\n    `name_id` int(7) NOT NULL,\n    `order` int(3) NOT NULL,\n    PRIMARY KEY  (`movie_id`,`name_id`),\n    KEY `name_id` (`name_id`)\n  ) ENGINE=MyISAM DEFAULT CHARSET=utf8", "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "crew` (\n    `movie_id` int(7) NOT NULL,\n    `name_id` int(7) NOT NULL,\n    `order` int(3) NOT NULL,\n    PRIMARY KEY  (`movie_id`,`name_id`),\n    KEY `name_id` (`name_id`)\n  ) ENGINE=MyISAM DEFAULT CHARSET=utf8", "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "imdbtop250` (\n    `id` int(7) NOT NULL,\n    `order` int(3) NOT NULL,\n    PRIMARY KEY  (`id`),\n    UNIQUE KEY `id` (`id`),\n    UNIQUE KEY `order` (`order`)\n  ) ENGINE=MyISAM DEFAULT CHARSET=utf8", "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "movies` (\n    `id` int(7) NOT NULL,\n    `title` varchar(255) NOT NULL,\n    `title_english` varchar(255) NOT NULL,\n    `language` varchar(2) NOT NULL,\n    `genre` set('Action','Adventure','Animation','Biography','Comedy','Crime',\n\t\t\t'Documentary','Drama','Family','History','Horror','Music','Musical',\n\t\t\t'Mystery','Sci-Fi','Short','Sport','Talk Show','Thriller','War',\n\t\t\t'Western') NOT NULL,\n    `year` int(4) NOT NULL,\n    `runtime` int(3) NOT NULL,\n    `rating` tinyint(2) NOT NULL,\n    `date_added` datetime NOT NULL,\n    PRIMARY KEY  (`id`)\n  ) ENGINE=MyISAM DEFAULT CHARSET=utf8", "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "names` (\n    `id` int(7) NOT NULL,\n    `name` varchar(255) NOT NULL,\n    PRIMARY KEY  (`id`)\n  ) ENGINE=MyISAM DEFAULT CHARSET=utf8", "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "options` (\n    `name` varchar(255) NOT NULL,\n    `value` varchar(255) NOT NULL,\n    PRIMARY KEY  (`name`)\n  ) ENGINE=MyISAM DEFAULT CHARSET=utf8"));
$updates[] = new Update(1.1, 1.2, array("ALTER TABLE `" . DB_PREFIX . "movies` CHANGE `genre` `genre`\n    SET('Action','Adventure','Animation','Biography','Comedy','Crime',\n    'Documentary','Drama','Family','Fantasy','Film-Noir','Game-Show','History',\n    'Horror','Music','Musical','Mystery','News','Reality-TV','Romance','Sci-Fi',\n    'Sport','Talk-Show','Thriller','War','Western') NOT NULL DEFAULT ''"));
$ignored_prefix_sql_updates = array("DROP TRIGGER IF EXISTS `" . DB_PREFIX . "_sort_title`", "CREATE TRIGGER `" . DB_PREFIX . "_sort_title` BEFORE INSERT ON `" . DB_PREFIX . "movies`\n\t\tFOR EACH ROW\n\t\tBEGIN\n\t\t\tCASE\n\t\t\t" . generate_prefix_remove_sql("\n\t\t\t\tWHEN LEFT(NEW.title, %d) = '%s' THEN\n\t\t\t\t\tSET NEW.sort_title = SUBSTRING(NEW.title FROM %d);\n\t\t\t", $ignoredPrefixes) . "\n\t\t\t\tELSE\n\t\t\t\t\tSET NEW.sort_title = NEW.title;\n\t\t\tEND CASE;\n\t\tEND", "UPDATE `" . DB_PREFIX . "movies`\n\t\tSET sort_title = CASE\n\t\t\t" . generate_prefix_remove_sql("\n\t\t\tWHEN LEFT(title, %d) = '%s' THEN\n\t\t\t\tSUBSTRING(title FROM %d)\n\t\t\t", $ignoredPrefixes) . "\n\t\t\tELSE\n\t\t\t\ttitle\n\t\tEND");
$updates[] = new Update(1.2, 1.3, array_merge(array("ALTER TABLE `" . DB_PREFIX . "movies`\n\t\tADD `sort_title` VARCHAR(255) NULL DEFAULT NULL AFTER `title`,\n\t\tADD INDEX `sort_index` (`sort_title`)"), $ignored_prefix_sql_updates));
function generate_prefix_remove_sql($format, $prefixes)
{
    $sql = '';
    foreach ($prefixes as $prefix) {
        // WHEN LEFT(NEW.title, 4) = 'The ' THEN
        //   SET NEW.sort_title = SUBSTRING(NEW.title FROM 5);
        $sql .= sprintf($format, strlen($prefix) + 1, $prefix . ' ', strlen($prefix) + 2);
    }
    return $sql;
}
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect: ' . mysql_error());
mysql_select_db(DB_NAME, $conn) or die('Could not select database');
$db = new MDB($conn);
if (!isset($_GET['skip-backups'])) {
    backup_database($db, $conn);
}
update_database($db, $conn, $updates);
if (!error_get_last()) {
    header('Location: ./?message=update-success');
}