Module: Backups::Stats::Mysql
Instance Method Summary
collapse
#connect, #exec_query, #get_result, #get_results
Instance Method Details
#get_database_names ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/backups/stats/mysql.rb', line 54
def get_database_names
query = <<-EOS
SELECT
SCHEMA_NAME `database`
FROM
INFORMATION_SCHEMA.SCHEMATA
WHERE
SCHEMA_NAME NOT IN ('#{get_excluded_schemas.join("', '")}')
EOS
get_results(query)
end
|
#get_database_stats(database) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/backups/stats/mysql.rb', line 37
def get_database_stats(database)
tables = get_database_tables(database)
stats = {}
tables.each do |item|
table = item['table']
stats[table] = get_table_stats(database, table)
$LOGGER.debug "Writing stats for table #{database}.#{table}: #{stats[table]}"
end
return stats
end
|
#get_database_tables(database) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/backups/stats/mysql.rb', line 24
def get_database_tables(database)
query = <<-EOS
SELECT
TABLE_NAME `table`
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = '#{database}'
EOS
get_results(query)
end
|
#get_excluded_schemas ⇒ Object
50
51
52
|
# File 'lib/backups/stats/mysql.rb', line 50
def get_excluded_schemas
["information_schema", "performance_schema", "mysql"]
end
|
#get_server_tables(databases = nil) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/backups/stats/mysql.rb', line 7
def get_server_tables(databases = nil)
query = <<-EOS
SELECT
TABLE_SCHEMA `database`,
TABLE_NAME `table`
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA NOT IN ('#{get_excluded_schemas.join("', '")}')
EOS
query += "AND TABLE_SCHEMA IN ('#{databases.join("', '")}')" if databases
query += "ORDER BY TABLE_SCHEMA ASC"
get_results(query)
end
|
#get_table_stats(database, table) ⇒ Object
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/backups/stats/mysql.rb', line 67
def get_table_stats(database, table)
query = <<-EOS
SELECT
COUNT(*) `rows`
FROM
`#{database}`.`#{table}`
EOS
get_result(query)
end
|