diff options
author | Jerome Charaoui <jcharaoui@cmaisonneuve.qc.ca> | 2009-12-10 14:52:50 -0500 |
---|---|---|
committer | Jerome Charaoui <jcharaoui@cmaisonneuve.qc.ca> | 2009-12-10 14:52:50 -0500 |
commit | 9ec0ef766c210ac6ca26a725701a89031a56fbab (patch) | |
tree | b4164616ac1558a790f33ff6e3bdbe89915da7c0 /files/scripts | |
parent | 4a24fffe14abc4ac89322c2707ec6b16d46c0917 (diff) |
make backup and optimize cron jobs optional; introduce $mysql_backup_cron, $mysql_backup_dir and$mysql_optimize_cron; use a module_dir for scripts
Diffstat (limited to 'files/scripts')
-rw-r--r-- | files/scripts/CentOS/setmysqlpass.sh | 15 | ||||
-rw-r--r-- | files/scripts/Debian/setmysqlpass.sh | 17 | ||||
-rw-r--r-- | files/scripts/optimize_tables.rb | 12 |
3 files changed, 44 insertions, 0 deletions
diff --git a/files/scripts/CentOS/setmysqlpass.sh b/files/scripts/CentOS/setmysqlpass.sh new file mode 100644 index 0000000..d762a20 --- /dev/null +++ b/files/scripts/CentOS/setmysqlpass.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +test $# -gt 0 || exit 1 + +/sbin/service mysqld stop + +/usr/libexec/mysqld --skip-grant-tables --user=root --datadir=/var/lib/mysql/data --log-bin=/var/lib/mysql/mysql-bin & +sleep 5 +echo "USE mysql; UPDATE user SET Password=PASSWORD('$1') WHERE User='root' AND Host='localhost';" | mysql -u root +killall mysqld +# chown to be on the safe side +chown mysql.mysql /var/lib/mysql/mysql-bin.* + +/sbin/service mysqld start + diff --git a/files/scripts/Debian/setmysqlpass.sh b/files/scripts/Debian/setmysqlpass.sh new file mode 100644 index 0000000..5bd63e2 --- /dev/null +++ b/files/scripts/Debian/setmysqlpass.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +test $# -gt 0 || exit 1 + +/etc/init.d/mysql stop + +/usr/sbin/mysqld --skip-grant-tables --user=root --datadir=/var/lib/mysql --log-bin=/var/lib/mysql/mysql-bin & +sleep 5 +echo "USE mysql; UPDATE user SET Password=PASSWORD('$1') WHERE User='root' AND Host='localhost';" | mysql -u root +killall mysqld +sleep 5 +# chown to be on the safe side +ls -al /var/lib/mysql/mysql-bin.* &> /dev/null +[ $? == 0 ] && chown mysql.mysql /var/lib/mysql/mysql-bin.* + +/etc/init.d/mysql start + 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 +} |