-
Notifications
You must be signed in to change notification settings - Fork 0
/
dumppaa_mysqlkuvaus.php
executable file
·131 lines (103 loc) · 3.39 KB
/
dumppaa_mysqlkuvaus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
// Kutsutaanko CLI:stä
$php_cli = FALSE;
if (php_sapi_name() == 'cli') {
$php_cli = TRUE;
}
if ($php_cli) {
// otetaan includepath aina rootista
ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.dirname(__FILE__).PATH_SEPARATOR."/usr/share/pear");
error_reporting(E_ALL ^E_WARNING ^E_NOTICE);
ini_set("display_errors", 0);
// otetaan tietokanta connect
require "inc/connect.inc";
require "inc/functions.inc";
// Logitetaan ajo
cron_log();
// dummy yhtio (menee ainoastaan filenimeen)
$kukarow["yhtio"] = "crond";
}
else {
require "inc/parametrit.inc";
}
//Hardcoodataan failin nimi /tmp diririkkaan
$tmpfilenimi = $kukarow["yhtio"]."_mysqlkuvays.sql";
if (!$php_cli) echo "<font class='head'>".t("SQL-tietokantarakenne").":</font><hr>";
$ulos = array();
// Jos ollaan annettu poikkeava MySQL portti hostnamessa, pitää se erotella komentorivityökalua varten
if (mb_strpos($dbhost, ":") !== false) {
list($dbhost, $dbport) = explode(":", $dbhost);
}
else {
$dbport = 3306;
}
// /usr/bin/mysqldump --> toimii ainakin fedorassa ja ubuntussa by default
if (file_exists("/usr/bin/mysqldump")) {
$mysql_dump_path = "/usr/bin/mysqldump";
}
elseif (file_exists("/usr/local/bin/mysqldump")) {
$mysql_dump_path = "/usr/local/bin/mysqldump";
}
else {
$mysql_dump_path = "mysqldump";
}
exec("$mysql_dump_path --user=$dbuser --host=$dbhost --port=$dbport --password=$dbpass --no-data $dbkanta", $ulos);
if (!$toot = fopen("/tmp/".$tmpfilenimi, "w")) die("Filen /tmp/$tmpfilenimi luonti epäonnistui!");
foreach ($ulos as $print) {
// poistetaan mysql-sarakkeen kommentti koska se kaataa sqlupdate-ohjelman
$print = preg_replace("/ COMMENT '[^']*',/", ",", $print);
fputs($toot, $print."\n");
}
$curlfile = "/tmp/".$tmpfilenimi;
// Löytyykö alttereita?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://pupeapi.sprintit.fi/sqlupdate.php");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('tee' => "remotefile", 'userfile' => "@$curlfile"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$result = curl_exec($ch);
unlink($curlfile);
if ($result === FALSE) {
echo "<font class='error'>VIRHE:</font><br>\n";
echo curl_errno($ch) . " - " . curl_error($ch) . "</font><br>";
exit(1);
}
curl_close($ch);
$alterit = trim($result);
// Löytyykö custom updateja?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://pupeapi.sprintit.fi/sqlupdate.sql");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
$result = curl_exec($ch);
if ($result === FALSE) {
echo "<font class='error'>VIRHE:</font><br>\n";
echo curl_errno($ch) . " - " . curl_error($ch) . "</font><br>";
exit(1);
}
curl_close($ch);
$updatet = trim($result);
// Yhdistetään
$result = $alterit."\n".$updatet;
// Poistetaan vielä tuplaspacet jos sellasia on
$result = trim(preg_replace("/ {2,}/", " ", $result));
if ($php_cli and $result != "") {
echo $result;
}
elseif (!$php_cli) {
if ($result != "") {
echo t("Tarvittavat muutokset");
echo ":<hr>";
echo "<pre>$result</pre>";
}
else {
echo t("Tietokanta ajantasalla!");
}
require "inc/footer.inc";
}