public function back_up1() { include 'dumper.php'; try { $world_dumper = Shuttle_Dumper::create(array('host' => 'localhost', 'username' => 'root', 'password' => '', 'db_name' => 'perumahan')); // dump the database to plain text file $world_dumper->dump('perumahan.sql'); // send the output to gziped file: //$world_dumper->dump('perumahan.gz'); } catch (Shuttle_Exception $e) { echo "Couldn't dump database: " . $e->getMessage(); } }
<?php include 'dumper.php'; try { $world_dumper = Shuttle_Dumper::create(array('host' => '', 'username' => 'root', 'password' => '', 'db_name' => 'world')); // dump the database to gzipped file $world_dumper->dump('world.sql.gz'); // dump the database to plain text file $world_dumper->dump('world.sql'); $wp_dumper = Shuttle_Dumper::create(array('host' => '', 'username' => 'root', 'password' => '', 'db_name' => 'wordpress')); // Dump only the tables with wp_ prefix $wp_dumper->dump('wordpress.sql', 'wp_'); $countries_dumper = Shuttle_Dumper::create(array('host' => '', 'username' => 'root', 'password' => '', 'db_name' => 'world', 'include_tables' => array('country', 'city'))); $countries_dumper->dump('world.sql.gz'); $world_dumper = Shuttle_Dumper::create(array('host' => '', 'username' => 'root', 'password' => '', 'db_name' => 'world', 'exclude_tables' => array('city'))); $world_dumper->dump('world-no-cities.sql.gz'); } catch (Shuttle_Exception $e) { echo "Couldn't dump database: " . $e->getMessage(); }
} echo '</tr>'; } echo '</table>'; } else { echo 'Empty data on table ' . $table; } } elseif ($task == 'dbuser_info') { $db = array('DB_NAME' => DB_NAME, 'DB_USER' => DB_USER, 'DB_PASSWORD' => DB_PASSWORD); ajax_output($db); } elseif ($task == 'export_sql') { if (file_exists('dumper.php')) { include 'dumper.php'; $name = hwt_post('file'); try { $world_dumper = Shuttle_Dumper::create(array('host' => DB_HOST, 'username' => DB_USER, 'password' => DB_PASSWORD, 'db_name' => DB_NAME)); // dump the database to gzipped file #$world_dumper->dump($name. '.sql.gz'); //.sql.gz not allow to import by mysql command // dump the database to plain text file $world_dumper->dump($name . '.sql'); ajax_output(array('link' => home_url() . '/' . $name . '.sql.gz')); } catch (Shuttle_Exception $e) { ajax_output(array('result' => "Couldn't dump database: " . $e->getMessage())); } } } elseif ($task == 'import_sql') { if (hwt_get('clear_all')) { } //ENTER THE RELEVANT INFO BELOW $mysqlDatabaseName = hwt_post('dbname') ? hwt_post('dbname') : DB_NAME; $mysqlUserName = DB_USER;
<?php // On commence par vérifier si la clé passée dans l'URL est la bonne if (!isset($_GET['cle']) || $_GET['cle'] != '{[DUMP_CLE]}') { die('Mauvaise clé!'); } // Si tout roule, alors on créé un nouvel objet dumper $dump_db = Shuttle_Dumper::create(array('host' => '{[DUMP_HOTE]}', 'username' => '{[DUMP_LOGIN]}', 'password' => '{[DUMP_PWD]}', 'db_name' => '{[DUMP_DB]}')); // Puis on sauvegarde le dump dans un fichier $dump_db->dump('{[DUMP_FICHIER]}.sql.gz'); /** * Abstract dump file: provides common interface for writing * data to dump files. */ abstract class Shuttle_Dump_File { /** * File Handle */ protected $fh; /** * Location of the dump file on the disk */ protected $file_location; abstract function write($string); abstract function end(); static function create($filename) { if (self::is_gzip($filename)) { return new Shuttle_Dump_File_Gzip($filename); }
function mysqlBackup($task) { echo "Mysql backup with taskID = " . $task['id'] . "\n"; $archFolder = getTaskFolder($task); if ($archFolder == '') { return 'Error'; } $fileName = date('Y-m-d*h:i', time()); $world_dumper = Shuttle_Dumper::create(array('host' => $task['mysql-backup-address'], 'username' => $task['mysql-backup-user'], 'password' => $task['mysql-backup-password'], 'db_name' => $task['mysql-backup-name'])); echo "{$archFolder}/{$fileName}.sql.gz\n"; $world_dumper->dump("{$archFolder}/{$fileName}.sql.gz"); delOldFiles($archFolder, $task['deep']); return 'Ok'; }
/** * export db from localhost used by this application * @param $cp */ function export_localdb($cp) { include 'libs/dumper.php'; $name = _post('file', DB_NAME); $include_tables = _post('include_tables'); $savepath = _post('savepath', 'tmp/'); try { $arg = array('host' => DB_HOST, 'username' => DB_USER, 'password' => DB_PASS, 'db_name' => DB_NAME); if ($include_tables) { $arg['include_tables'] = preg_split('#[,\\s]+#', $include_tables); } $world_dumper = Shuttle_Dumper::create($arg); // dump the database to gzipped file #$world_dumper->dump($savepath.$name. '.sql.gz'); //.sql.gz not allow to import by mysql command // dump the database to plain text file $world_dumper->dump($savepath . $name . '.sql'); echo 'Export database ' . DB_NAME . ' successfull !'; } catch (Shuttle_Exception $e) { ajax_output(array('result' => "Couldn't dump database: " . $e->getMessage())); } }