diff options
author | mh <mh@immerda.ch> | 2014-01-12 14:19:26 +0100 |
---|---|---|
committer | mh <mh@immerda.ch> | 2014-01-12 14:19:26 +0100 |
commit | 7bde4efe1e680d21dfa8ecd15e5e9a3c5eb41df2 (patch) | |
tree | 1d7f24473be159d1d9faf3f35fedfdd8e9096942 | |
parent | d459760890e27738c0d577f5c80defb679c4d243 (diff) |
improve optimize script
-rw-r--r-- | files/scripts/optimize_tables.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/files/scripts/optimize_tables.rb b/files/scripts/optimize_tables.rb index 46e223e..e1a71ef 100644 --- a/files/scripts/optimize_tables.rb +++ b/files/scripts/optimize_tables.rb @@ -3,10 +3,12 @@ # set home as we runit as weekly cron, where HOME is / ENV['HOME'] = '/root' tables = %x{mysql -Bse "SELECT TABLE_SCHEMA,TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 0 AND ENGINE IN ('MyISAM','InnoDB','ARCHIVE')"} -tables.each { |table| - tableitems = table.chomp.split(/\t/) - system "mysql #{tableitems[0]} -Bse \"OPTIMIZE TABLE \\`#{tableitems[0]}\\`.\\`#{tableitems[1]}\\`\" | grep -q OK" - if $?.to_i > 0 then - puts "error while optimizing #{tableitems[0]}.#{tableitems[1]}" - end -} +tables.each do |table| + tableitems = table.chomp.split(/\t/) + output = %x{mysql #{tableitems[0]} -Bse "OPTIMIZE TABLE \\`#{tableitems[0]}\\`.\\`#{tableitems[1]}\\`" 2>&1} + unless output =~ /status\t+OK/ + puts "Error while optimizing #{tableitems[0]}.#{tableitems[1]}:" + puts output + puts + end +end |