Module: MySQLDBTool

Defined in:
lib/mysql_db_tool.rb,
lib/mysql_db_tool/backup.rb,
lib/mysql_db_tool/restore.rb,
lib/mysql_db_tool/version.rb,
lib/mysql_db_tool/config/config_loader.rb

Overview

lib/mysql_db_tool/version.rb

Defined Under Namespace

Modules: Config Classes: Backup, Error, Restore

Constant Summary collapse

ENV_VAR_DESCRIPTION =

Environment variable description

<<~DESC
  Environment Variables:
    DUMP_OPTIONS - Additional options to pass to the MySQL dump command during the backup process.
                   This can include any options supported by mysqldump, such as --skip-lock-tables.
DESC
VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.backup(options = {}) ⇒ Object

You might want to add methods to easily access your main functionalities



42
43
44
45
# File 'lib/mysql_db_tool.rb', line 42

def self.backup(options = {})
  commands = Backup.new(options).perform
  commands.each { |command| run(options[:run], command) }
end

.database_opt(options, opts) ⇒ Object



35
36
37
38
39
# File 'lib/mysql_db_tool.rb', line 35

def self.database_opt(options, opts)
  opts.on("-d", "--database DATABASE", "Override option for dbInfo.database configuration") do |database|
    options[:database] = database.split(',')
  end
end

.env_opt(options, opts) ⇒ Object



17
18
19
20
21
# File 'lib/mysql_db_tool.rb', line 17

def self.env_opt(options, opts)
  opts.on("-e", "--env ENVIRONMENT", "Environment (default: local) - key to find the configuration file. e.g.) config-local.json") do |env|
    options[:env] = env
  end
end

.find_resource(relative_path) ⇒ Object



52
53
54
# File 'lib/mysql_db_tool.rb', line 52

def self.find_resource(relative_path)
  File.join(File.dirname(__FILE__), 'mysql_db_tool', relative_path)
end

.id_opt(options, opts) ⇒ Object



23
24
25
26
27
# File 'lib/mysql_db_tool.rb', line 23

def self.id_opt(options, opts)
  opts.on("-i", "--backup-id BACKUP_ID", "BACKUP_ID (default: 0)") do |id|
    options[:id] = id
  end
end

.restore(options = {}) ⇒ Object



47
48
49
50
# File 'lib/mysql_db_tool.rb', line 47

def self.restore(options = {})
  commands = Restore.new(options).perform
  commands.each { |command| run(options[:run], command) }
end

.run_opt(options, opts) ⇒ Object



29
30
31
32
33
# File 'lib/mysql_db_tool.rb', line 29

def self.run_opt(options, opts)
  opts.on("-r", "--run", "Run the backup (default: false) or Just show the commands") do
    options[:run] = true
  end
end