Sha256: 1aa7e15186815b69085855af722ae78cad958c7abf3b6249aacbd9804c533592

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 KB

Contents

require 'toolshed/commands/base'
require 'toolshed/databases/mysql/backup'

module Toolshed
  module Commands
    module Mysql
      # Responsible for handing backup of mysql database
      class Backup < Toolshed::Commands::Base
        def self.cli_options # rubocop:disable MethodLength
          {
            banner: 'Usage: mysql backup [options]',
            options: {
              host: {
                short_on: '-l'
              },
              path: {
                short_on: '-p'
              },
              username: {
                short_on: '-u'
              },
              password: {
                short_on: '-d'
              },
              name: {
                short_on: '-n'
              },
              wait_time: {
                short_on: '-w'
              }
            }
          }
        end

        def execute(_args, options = nil)
          options = options_with_defaults(options)
          Toolshed.logger.info ''
          Toolshed::Databases::Mysql::Backup.new(options).execute
          Toolshed.logger.info ''
          Toolshed.die
        end

        private

        def options_with_defaults(options = nil)
          options ||= {}
          options[:host] ||= 'localhost'
          options[:path] ||= read_user_input("Storage Path (/tmp/test/#{Time.now.utc.getlocal.strftime('%Y%m%d')}.sql) ?", required: true)
          options[:username] ||= read_user_input('Username?', required: true)
          options[:name] ||= read_user_input('Database Name?', required: true)
          options
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
toolshed-1.0.12 lib/toolshed/commands/mysql/backup.rb
toolshed-1.0.11 lib/toolshed/commands/mysql/backup.rb
toolshed-1.0.10 lib/toolshed/commands/mysql/backup.rb
toolshed-1.0.9 lib/toolshed/commands/mysql/backup.rb
toolshed-1.0.8 lib/toolshed/commands/mysql/backup.rb
toolshed-1.0.7 lib/toolshed/commands/mysql/backup.rb