- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
<?php
ini_set('magic_quotes_runtime', 0);
if (PHP_SAPI != 'cli') exit();
if (in_array('pack', $argv) || !in_array('unpack', $argv)) $packing = true;
else $unpacking = true;
if (isset($packing)) {
$detectors = array(/* a lot of content */);
function parse_configuration($file, $detector) { /* code to find configurations */ }
$configurations = array();
foreach ($detectors as $d => $detector)
if (file_exists($detector['file']))
$configurations[$d] = parse_configuration($detector['file'], $detector);
echo 'Available configurations: ' . PHP_EOL; $i = 0;
foreach ($configurations as $n => $configuration) {
echo (++$i) . '. ' . $n . PHP_EOL;
}
if (count($configurations) == 1) {
echo 'Choosing first configuration' . PHP_EOL;
$configuration = $configurations[$n];
$name = $n;
} else if (count($configurations) > 1) {
while (true) {
echo 'Please, choose configuration to move: ' . PHP_EOL;
$c = trim(fgets(STDIN));
if (isset($configurations[$c])) {
$name = $c;
$configuration = $configurations[$c];
break;
}
}
} else {
echo 'No available configurations' . PHP_EOL;
}
var_dump($configuration);
echo 'Checking mysql connectivity' . PHP_EOL;
$mysql = mysqli_connect($configuration['host'], $configuration['user'], $configuration['password'], $configuration['database']);
if (mysqli_connect_error()) {
die('Error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error());
}
$fp = fopen($configuration['database'] . '.mysqldb', 'wb');
fwrite($fp, pack('n', strlen($name)).$name);
$data = json_encode($configuration);
$length = strlen($data);
fwrite($fp, pack('N', $length));
fwrite($fp, $data);
echo 'Scanning tables structure' . PHP_EOL;
$res = $mysql->query('SHOW TABLES');
$data = array();
while ($row = $res->fetch_row()) {
$data[$row[0]] = array();
$res2 = $mysql->query('EXPLAIN `' . $row[0] . '`');
$i = 0;
while ($field = $res2->fetch_assoc()) {
$data[$row[0]][$i] = array('type' => $field['Type'], 'name' => $field['Field']);
if ($field['Key'] == 'PRI') $data[$row[0]][$i]['primary'] = 'yes';
if ($field['Default'] !== NULL && !empty($field['Default'])) $data[$row[0]][$i]['default'] = $field['Default'];
if ($field['Extra'] == 'auto_increment') $data[$row[0]][$i]['increment'] = 'yes';
if ($field['Null'] !== 'NO') $data[$row[0]][$i]['nullable'] = 'yes';
$i++;
}
}
$data = json_encode($data);
$length = strlen($data);
fwrite($fp, pack('N', $length));
fwrite($fp, $data);
echo 'Scanning tables structure' . PHP_EOL;
$res = $mysql->query('SHOW TABLES');
$data = array();
while ($row = $res->fetch_row()) {
$data[$row[0]] = array();
$res2 = $mysql->query('EXPLAIN `' . $row[0] . '`');
$i = 0;
while ($field = $res2->fetch_assoc()) {
$data[$row[0]][$i] = array('type' => $field['Type'], 'name' => $field['Field']);
if ($field['Key'] == 'PRI') $data[$row[0]][$i]['primary'] = 'yes';
if ($field['Default'] !== NULL && !empty($field['Default'])) $data[$row[0]][$i]['default'] = $field['Default'];
if ($field['Extra'] == 'auto_increment') $data[$row[0]][$i]['increment'] = 'yes';
if ($field['Null'] !== 'NO') $data[$row[0]][$i]['nullable'] = 'yes';
$i++;
}
}
$data = json_encode($data);
$length = strlen($data);
fwrite($fp, pack('N', $length));
fwrite($fp, $data);
echo 'Scanning data' . PHP_EOL;
$res = $mysql->query('SHOW TABLES');
while ($row = $res->fetch_row()) {
$data = array();
$res2 = $mysql->query('SELECT * FROM `' . $row[0] . '`');
while ($record = $res2->fetch_assoc()) {
$data[] = $record;
}
$data = json_encode($data);
$length = strlen($data);
fwrite($fp, pack('N', $length));
fwrite($fp, $data);
}
fclose($fp);
} // and after that code that does unpacking
Utility lets you easily move your project from one server to another
Утилита позволяет переносит базу любого проекта (Wordpress, Joomla, ModX, Textpattern, Concrete5, Contao) с одного сервера на другой, экспортируя её в виде .mysqldb файла.
Если интересно, это чудо называется mysql_mover.
guest 07.01.2017 11:05 # 0
guest 07.01.2017 13:10 # 0
guest 07.01.2017 15:47 # +2
bormand 07.01.2017 17:29 # 0
barop 08.01.2017 03:21 # 0
bormand 08.01.2017 08:01 # 0
barop 08.01.2017 11:15 # 0
bormand 08.01.2017 13:01 # 0