summaryrefslogtreecommitdiff
path: root/files/scripts/optimize_tables.rb
diff options
context:
space:
mode:
Diffstat (limited to 'files/scripts/optimize_tables.rb')
-rw-r--r--files/scripts/optimize_tables.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/files/scripts/optimize_tables.rb b/files/scripts/optimize_tables.rb
new file mode 100644
index 0000000..52e726e
--- /dev/null
+++ b/files/scripts/optimize_tables.rb
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+
+# 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[1]}\" | grep -q OK"
+ if $?.to_i > 0 then
+ puts "error while optimizing #{tableitems[0]}. #{tableitems[1]}"
+ end
+}