private function _dumpDatabase($filename, $dbname, $droptable) { $filename .= ".sql"; $filename = $this->folder . DIRECTORY_SEPARATOR . $filename; $dbconfigList = BizSystem::getConfiguration()->getDatabaseInfo(); $dbconfig = $dbconfigList[$dbname]; if (strtolower($dbconfig["Driver"]) != 'pdo_mysql') { return; } include_once dirname(dirname(__FILE__)) . "/lib/MySQLDump.class.php"; $backup = new MySQLDump(); if ($droptable == 1) { $backup->droptableifexists = true; } else { $backup->droptableifexists = false; } if ($dbconfig["Port"]) { $dbHost = $dbconfig["Server"] . ":" . $dbconfig["Port"]; } else { $dbHost = $dbconfig["Port"]; } $dbc = $backup->connect($dbHost, $dbconfig["User"], $dbconfig["Password"], $dbconfig["DBName"], $dbconfig["Charset"]); if (!$dbc) { echo $backup->mysql_error; } $backup->dump(); $data = $backup->output; file_put_contents($filename, $data); @chmod($filename, 0777); return $filename; }
/** * Run the task, and do the business * * @param SS_HTTPRequest $httpRequest */ function run($httpRequest) { global $databaseConfig; // environment type Director::set_environment_type("dev"); // debug ini_set("display_errors", "2"); ERROR_REPORTING(E_ALL); /* $dbhost = $databaseConfig['server']; $dbuser = $databaseConfig['username']; $dbpwd = $databaseConfig['password']; $dbname = $databaseConfig['database']; $backupfolder = $_SERVER['DOCUMENT_ROOT'].'/db_backups'; $dumpfile = $backupfolder."/".$dbname."_".date("Y-m-d_H-i-s").".sql"; if (!is_dir($backupfolder)) mkdir($backupfolder); passthru("/usr/bin/mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpwd $dbname > $dumpfile"); echo "Created: ".$dumpfile; passthru("tail -1 $dumpfile"); */ $drop_table_if_exists = false; //Add MySQL 'DROP TABLE IF EXISTS' Statement To Output $dbhost = $databaseConfig['server']; $dbuser = $databaseConfig['username']; $dbpass = $databaseConfig['password']; $dbname = $databaseConfig['database']; $backupfolder = __DIR__ . '/../../db_backups'; $dumpfile = $backupfolder . "/" . $dbname . "_" . date("Y-m-d_H-i-s") . ".sql"; $backup = new MySQLDump(); $backup->droptableifexists = $drop_table_if_exists; $backup->connect($dbhost, $dbuser, $dbpass, $dbname); //Connect To Database if (!$backup->connected) { die('Error: ' . $backup->mysql_error); } //On Failed Connection, Show Error. $backup->list_tables(); //List Database Tables. $broj = count($backup->tables); //Count Database Tables. $output = ''; echo "found " . $broj . " tables \n\n"; for ($i = 0; $i < $broj; $i++) { $table_name = $backup->tables[$i]; //Get Table Names. $backup->dump_table($table_name); //Dump Data to the Output Buffer. $output .= $backup->output; } if (!is_dir($backupfolder)) { mkdir($backupfolder); } file_put_contents($dumpfile, $output); echo "Dumped into " . $dumpfile; //echo "<pre>".$output."</pre>"; }
//db host $dbuser = $db_USER; //db user name $dbpass = $db_PASS; //db password $dbname = $db_NAME; //db to work with $drop_table_if_exists = true; //should we drop table if exist? $somecontent = "/*\n\n+-------------------------------------------------------------+\n\n+-------------------------------------------------------------+\n\n+---------By:Amila Jayasinghe (amilaplus@gmail.com)-----------+\n\n+-------------------------------------------------------------+\n\n*/\n\n"; // no need for editing further $backup = new MySQLDump(); //create new instance of MySQLDump $backup->droptableifexists = $drop_table_if_exists; //set drop table if exists $backup->connect($dbhost, $dbuser, $dbpass, $dbname); //connect if (!$backup->connected) { die('Error: ' . $backup->mysql_error); } //if not connected, display error $backup->list_tables(); //list all tables $broj = count($backup->tables); //count all tables, $backup->tables will be array of table names //echo "<pre>\n"; //start preformatted output $somecontent .= "-- Dumping tables for database: `{$dbname}`\n"; //write "intro" ;) $somecontent .= "\n\nSET FOREIGN_KEY_CHECKS=0; \n"; //write "intro" ;) //dump all tables:
$permission_level = getPermissionLevel($_SESSION['egps_username']); if ($permission_level > $MINIMUM_AUTHORIZATION_LEVEL || $permission_level == NULL) { $system_message = $system_message . "You do not have permission to view this page (IP: " . $_SERVER['REMOTE_ADDR'] . ")"; IPP_LOG($system_message, $_SESSION['egps_username'], 'ERROR'); require IPP_PATH . 'security_error.php'; exit; } //************** validated past here SESSION ACTIVE WRITE PERMISSION CONFIRMED**************** //include class require_once IPP_PATH . 'include/MySQLDump.class.php'; //create new instance of MySQLDump $backup = new MySQLDump(); //set drop table if exists $backup->droptableifexists = true; //connect to mysql server (host, user, pass, db) $backup->connect($mysql_data_host, $mysql_data_username, $mysql_data_password, 'ipp'); //if not connected, display error if (!$backup->connected) { die('Error: ' . $backup->mysql_error); } //get all tables in db $backup->list_tables(); //reset buffer $buffer = ''; //go through all tables and dump them to buffer foreach ($backup->tables as $table) { $buffer .= $backup->dump_table($table); } if (strstr($HTTP_USER_AGENT, "MSIE 5.5")) { // had to make it MSIE 5.5 because if 6 has no "attachment;" in it it defaults to "inline" $attachment = "";
} // end function validate_key() </SCRIPT> </HTML> <?php exit; } // end else break; case 'dump': // see mysql.inc.php for MySQL parameters require_once './incs/MySQLDump.class.php'; $backup = new MySQLDump(); //create new instance of MySQLDump $the_db = $mysql_prefix . $mysql_db; $backup->connect($mysql_host, $mysql_user, $mysql_passwd, $the_db); // connect if (!$backup->connected) { die('Error: ' . $backup->mysql_error); } // MySQL parameters from mysql.inc.php $backup->list_tables(); // list all tables $broj = count($backup->tables); // count all tables, $backup->tables // will be array of table names ?> <SCRIPT> function copyit() { // 11/30/09 var tempval= document.the_form.the_dump; tempval.focus();