Class: Toolshed::Databases::Mysql::Backup
- Inherits:
-
Object
- Object
- Toolshed::Databases::Mysql::Backup
- Includes:
- Password
- Defined in:
- lib/toolshed/databases/mysql/backup.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
-
#wait_time ⇒ Object
readonly
Returns the value of attribute wait_time.
Instance Method Summary collapse
- #create_path ⇒ Object
- #execute ⇒ Object
- #hidden_password_param ⇒ Object
-
#initialize(options = nil) ⇒ Backup
constructor
A new instance of Backup.
- #password_param ⇒ Object
Methods included from Password
Constructor Details
#initialize(options = nil) ⇒ Backup
Returns a new instance of Backup.
14 15 16 17 18 19 20 21 22 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 14 def initialize( = nil) ||= {} @host = [:host] @name = [:name] @path = [:path] @password = [:password] @username = [:username] @wait_time = [:wait_time] || 120 end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
12 13 14 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 12 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 12 def name @name end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
12 13 14 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 12 def password @password end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 12 def path @path end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
12 13 14 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 12 def username @username end |
#wait_time ⇒ Object (readonly)
Returns the value of attribute wait_time.
12 13 14 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 12 def wait_time @wait_time end |
Instance Method Details
#create_path ⇒ Object
24 25 26 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 24 def create_path FileUtils.mkdir_p(File.dirname(path)) end |
#execute ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 28 def execute raise TypeError, "Wait time passed in is not a number #{wait_time}" unless wait_time.is_a?(Fixnum) Toolshed.logger.info "Starting execution of mysqldump -h #{host} -u #{username} #{hidden_password_param} #{name} > #{path}." create_path results = Toolshed::Base.wait_for_command("mysqldump -h #{host} -u #{username} #{password_param} #{name} > #{path}", wait_time) unless results[:stderr].is_a?(NilClass) = results[:stderr].join(' ') Toolshed.logger.fatal raise Toolshed::PermissionsException, end Toolshed.logger.info results[:stdout].join(' ') unless results[:stdout].is_a?(NilClass) Toolshed.logger.info 'mysqldump has completed.' end |
#hidden_password_param ⇒ Object
46 47 48 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 46 def hidden_password_param password_param.empty? ? '' : '-p *******' end |
#password_param ⇒ Object
42 43 44 |
# File 'lib/toolshed/databases/mysql/backup.rb', line 42 def password_param password.nil? || password.empty? ? '' : "-p#{password_from_config(password)}" end |