module MySQLServiceScript
Group all MySQL validation and methods into a single module
Public Instance Methods
get_innobackupex_path()
click to toggle source
# File lib/tungsten/script.rb, line 951 def get_innobackupex_path() path = TU.which("innobackupex-1.5.1") if path.nil? path = TU.which("innobackupex") end return path end
get_mysql_command()
click to toggle source
# File lib/tungsten/script.rb, line 943 def get_mysql_command "mysql --defaults-file=#{@options[:my_cnf]} -h#{@options[:mysqlhost]} --port=#{@options[:mysqlport]}" end
get_mysql_option(opt)
click to toggle source
Read the configured value for a mysql variable
# File lib/tungsten/script.rb, line 1016 def get_mysql_option(opt) begin val = TU.cmd_result("my_print_defaults --config-file=#{@options[:my_cnf]} mysqld | grep -e'^--#{opt.gsub(/[\-\_]/, "[-_]")}='") rescue CommandError => ce return nil end return val.split("\n")[0].split("=")[1] end
get_mysql_result(command, timeout = 30)
click to toggle source
# File lib/tungsten/script.rb, line 981 def get_mysql_result(command, timeout = 30) begin Timeout.timeout(timeout.to_i()) { return TU.cmd_result("#{get_mysql_command()} -e \"#{command}\"") } rescue Timeout::Error rescue => e end return nil end
get_mysql_value(command, column = nil)
click to toggle source
# File lib/tungsten/script.rb, line 993 def get_mysql_value(command, column = nil) response = get_mysql_result(command + "\\\\G") if response == nil return nil end response.split("\n").each{ | response_line | parts = response_line.chomp.split(":") if (parts.length != 2) next end parts[0] = parts[0].strip; parts[1] = parts[1].strip; if parts[0] == column || column == nil return parts[1] end } return nil end
get_mysql_variable(var)
click to toggle source
Read the current value for a mysql variable
# File lib/tungsten/script.rb, line 1027 def get_mysql_variable(var) response = TU.cmd_result("#{get_mysql_command()} -e \"SHOW VARIABLES LIKE '#{var}'\\\\G\"") response.split("\n").each{ | response_line | parts = response_line.chomp.split(":") if (parts.length != 2) next end parts[0] = parts[0].strip; parts[1] = parts[1].strip; if parts[0] == "Value" return parts[1] end } return nil end
get_mysqldump_command()
click to toggle source
# File lib/tungsten/script.rb, line 947 def get_mysqldump_command "mysqldump --defaults-file=#{@options[:my_cnf]} --host=#{@options[:mysqlhost]} --port=#{@options[:mysqlport]} --opt --single-transaction --all-databases --add-drop-database --master-data=2" end
get_xtrabackup_command()
click to toggle source
# File lib/tungsten/script.rb, line 959 def get_xtrabackup_command # Use the configured my.cnf file, or the additional config file # if we created one if @options[:extra_mysql_defaults_file] == nil defaults_file = @options[:my_cnf] else defaults_file = @options[:extra_mysql_defaults_file].path() end "#{get_innobackupex_path()} --defaults-file=#{defaults_file} --host=#{@options[:mysqlhost]} --port=#{@options[:mysqlport]}" end
require_local_mysql_service?()
click to toggle source
Allow scripts to turn off MySQL validation of the local server
# File lib/tungsten/script.rb, line 900 def require_local_mysql_service? false end
set_mysql_defaults_value(value)
click to toggle source
Store additional MySQL configuration values in a temporary file
# File lib/tungsten/script.rb, line 1047 def set_mysql_defaults_value(value) if @options[:extra_mysql_defaults_file] == nil @options[:extra_mysql_defaults_file] = Tempfile.new("xtracfg") @options[:extra_mysql_defaults_file].puts("!include #{@options[:my_cnf]}") @options[:extra_mysql_defaults_file].puts("") @options[:extra_mysql_defaults_file].puts("[mysqld]") end @options[:extra_mysql_defaults_file].puts(value) @options[:extra_mysql_defaults_file].flush() end
start_mysql_server()
click to toggle source
# File lib/tungsten/script.rb, line 1059 def start_mysql_server ds = TI.datasource(@options[:service]) ds.start() end
stop_mysql_server()
click to toggle source
Make sure that the mysql server is stopped by stopping it and checking the process has disappeared
# File lib/tungsten/script.rb, line 1066 def stop_mysql_server ds = TI.datasource(@options[:service]) ds.stop() end
validate()
click to toggle source
Calls superclass method
SingleServiceScript#validate
# File lib/tungsten/script.rb, line 904 def validate super() if @options[:service].to_s() == "" return end unless TI.replication_services().include?(@options[:service]) return end if @options[:mysqlhost] == nil @options[:mysqlhost] = TI.setting(TI.setting_key(REPL_SERVICES, @options[:service], "repl_datasource_host")) end if @options[:mysqlport] == nil @options[:mysqlport] = TI.setting(TI.setting_key(REPL_SERVICES, @options[:service], "repl_datasource_port")) end if @options[:my_cnf] == nil @options[:my_cnf] = TI.setting(TI.setting_key(REPL_SERVICES, @options[:service], "repl_datasource_mysql_service_conf")) end if @options[:my_cnf] == nil TU.error "Unable to determine location of MySQL my.cnf file" else unless File.exist?(@options[:my_cnf]) TU.error "The file #{@options[:my_cnf]} does not exist" end end if require_local_mysql_service?() if @options[:mysqluser] == nil @options[:mysqluser] = get_mysql_option("user") end if @options[:mysqluser].to_s() == "" @options[:mysqluser] = "mysql" end end end
xtrabackup_supports_argument(arg)
click to toggle source
# File lib/tungsten/script.rb, line 971 def xtrabackup_supports_argument(arg) arg = arg.tr("-", "\\-") supports_argument = TU.cmd_result("#{get_xtrabackup_command()} --help /tmp | grep -e\"#{arg}\" | wc -l") if supports_argument == "1" return true else return false end end