-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsproc.backup.php
More file actions
95 lines (90 loc) · 2.67 KB
/
sproc.backup.php
File metadata and controls
95 lines (90 loc) · 2.67 KB
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
#!/usr/bin/php
<?php
require ('/opt/configs/config.php');
chdir(__DIR__);
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "
select sql_stmt
from (
select p.db, p.name, p.type, 1 as intord, p.character_set_client,
concat('DROP ',p.type, ' IF EXISTS ',p.name,';') as sql_stmt
from mysql.proc p
union all
select p.db, p.name, p.type, 2 as intord, p.character_set_client,
'delimiter $$' as sql_stmt
from mysql.proc p
union all
select p.db, p.name, p.type, 3 as intord, p.character_set_client,
concat('CREATE ',
p.type,
' ',p.name,
'(',convert(p.param_list USING utf8),') ',
case
when length(p.returns) > 1
then concat(' RETURNS ', convert(p.returns USING utf8))
else ''
end, ' \n',
case
when p.is_deterministic = 'YES' then '\tDETERMINISTIC\n'
else ''
end,
case
when p.language = 'SQL' THEN ''
else concat('\tLANGUAGE ',p.language, '\n')
end,
case
when p.sql_data_access = 'CONTAINS_SQL' THEN ''
when p.sql_data_access = 'NO_SQL' THEN '\tNO SQL\n'
when p.sql_data_access = 'READS_SQL_DATA' THEN '\tREADS SQL DATA\n'
when p.sql_data_access = 'MODIFIES_SQL_DATA' THEN '\tMODIFIES SQL DATA\n'
else concat('\t',replace(p.sql_data_access,'_', ' '), '\n')
end,
case when p.security_type <> 'DEFINER'
then concat('\tSQL SECURITY ', p.security_type, '\n')
else ''
end,
case when p.comment <> ''
then concat('\tCOMMENT ''',
replace(replace(p.comment,'''',''''''),'\n','\\n')
,'''')
else ''
end, '\n',
convert(p.body USING utf8),
'$$'
) as sql_stmt
from mysql.proc p
union all
select p.db, p.name, p.type, 4 as intord, p.character_set_client,
'delimiter ;' as sql_stmt
from mysql.proc p
union all
select p.db, p.name, p.type, 0 as intord, p.character_set_client,
p.name as sql_stmt
from mysql.proc p
) sql_stmts
where db = 'eddb'
and type = 'procedure'
order by db, name, type, intord;";
$counter = 0;
if ($result = $mysqli->query($query)) {
while ($data = $result->fetch_assoc()) {
if ($counter == 0) {
$contents = "";
$tfn = __DIR__ . "/" . $data['sql_stmt'] . ".sql";
} else {
$contents .= $data['sql_stmt'] . "\n\n\n";
}
if ($counter == 4) {
$counter = 0;
$fp = fopen($tfn, 'w');
fwrite($fp, $contents);
fclose($fp);
} else {
$counter++;
}
}
}
system("cat *.sql > AllCommands.out");
system("git add .");
system("git commit -m 'Automated Update'");
system("git push");