Top Level Namespace

Defined Under Namespace

Modules: MySQLDBTool

Instance Method Summary collapse

Instance Method Details

#backupDirName(id, dbName = "") ⇒ Object



12
13
14
# File 'lib/mysql_db_tool/db_backup_base.rb', line 12

def backupDirName(id, dbName = "")
  "backup-#{id}#{dbName.empty? ? '' : "/#{dbName}"}"
end

#mysqlDefaultOptions(db_info, database) ⇒ Object



16
17
18
# File 'lib/mysql_db_tool/db_backup_base.rb', line 16

def mysqlDefaultOptions(db_info, database)
  " --ssl-mode=disabled -h #{db_info[:host]} -u #{db_info[:user]} #{db_info[:password].to_s.empty? ? '' : " -p'#{db_info[:password]}'"} #{db_info[:port].to_s.empty? ? '' : " -P'#{db_info[:port]}'"} #{database} "
end

#run(isRun, command) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/mysql_db_tool/db_backup_base.rb', line 3

def run(isRun, command)
  if not isRun
    puts "[dryRun] #{command}"
  else
    puts "Running: [#{command}]"
    puts `#{command}`
  end
end

#verify_tools_existObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mysql_db_tool/db_backup_base.rb', line 20

def verify_tools_exist
  tools = ["mysql", "mysqldump", "gzip", "zcat"]
  missing_tools = []

  tools.each do |tool|
    if not system("which #{tool} > /dev/null 2>&1")
      missing_tools << tool
      puts "'#{tool}' is not available"
    end
  end

  if missing_tools.empty?
    puts "All required tools are available."
  else
    puts "Missing tools: #{missing_tools.join(', ')}"
    puts "Please install the missing tools."
    exit 1
  end
end