Class: MysqlBackup::Entity::Files
- Inherits:
-
MysqlBackup::Entity
- Object
- MysqlBackup::Entity
- MysqlBackup::Entity::Files
- Defined in:
- lib/mysql_backup/entity/files.rb
Overview
See MysqlBackup::Entity::Files::Innodb and MysqlBackup::Entity::Files::Myisam for implementations of this abstract base class.
Defined Under Namespace
Instance Attribute Summary
Attributes inherited from MysqlBackup::Entity
Class Method Summary collapse
-
.build_files(args) ⇒ Object
Create the actual files in a
with_lock
block. -
.create_tar_files(args = {}, &block) ⇒ Object
Create the tar files to back up a mysql instance.
-
.do_tar(args) ⇒ Object
:nodoc:.
-
.process_file(args, &block) ⇒ Object
Process each file with the specified block.
Instance Method Summary collapse
- #confirm_required_paths_are_readable ⇒ Object
-
#initialize(args = {}) ⇒ Files
constructor
A new instance of Files.
-
#required_path_strings ⇒ Object
Returns a list of path strings that need to be backed up.
-
#set_path_vars(var_names, args = {}) ⇒ Object
Given a set of variable names, create a set of matching Pathname objects with
_path
appended to the name.
Methods inherited from MysqlBackup::Entity
Constructor Details
#initialize(args = {}) ⇒ Files
Returns a new instance of Files.
10 11 12 |
# File 'lib/mysql_backup/entity/files.rb', line 10 def initialize args = {} super() end |
Class Method Details
.build_files(args) ⇒ Object
Create the actual files in a with_lock
block.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mysql_backup/entity/files.rb', line 38 def self.build_files args #:nodoc: log_data = nil args[:mysql_server].with_lock do |l| log_data = l mysql_file_objs = args[:mysql_files] mysql_file_objs.each do |o| o.confirm_required_paths_are_readable end path_strings = (mysql_file_objs.map {|o| o.required_path_strings}).flatten.uniq log_data[:files] = tar_files path_strings log_data[:n_parts] = log_data[:files].length end log_data end |
.create_tar_files(args = {}, &block) ⇒ Object
Create the tar files to back up a mysql instance.
Takes the following:
:mysql_server => a MysqlBackup::Server object
:mysql_files => an array of MysqlBackup::Entity::Files objects
Yields a hash:
:identifier => a MysqlBackup::Entity::Identifier object
:file => a Pathname object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mysql_backup/entity/files.rb', line 25 def self.create_tar_files args = {}, &block begin log_data = build_files args log_data[:files].each do |p| process_file(log_data.merge(:file => p), &block) end ensure # files.each {|f| f.unlink if f.exist?} end end |
.do_tar(args) ⇒ Object
:nodoc:
72 73 74 75 76 |
# File 'lib/mysql_backup/entity/files.rb', line 72 def self.do_tar args #:nodoc: log = args[:log] log && log.info("running #{cmd}") system args[:cmd] or raise RuntimeError, "The command failed with status #{$?}" end |
.process_file(args, &block) ⇒ Object
Process each file with the specified block
54 55 56 57 58 |
# File 'lib/mysql_backup/entity/files.rb', line 54 def self.process_file args, &block #:nodoc: part_number = args[:file].to_s[/.*(\d+)$/, 1].to_i identifier = MysqlBackup::Entity::Identifier.create_object args.merge(:category => :full, :type => :binary, :part_number => part_number) block.call(:identifier => identifier, :file => args[:file]) end |
Instance Method Details
#confirm_required_paths_are_readable ⇒ Object
60 61 62 63 64 |
# File 'lib/mysql_backup/entity/files.rb', line 60 def confirm_required_paths_are_readable required_paths.each do |p| raise RuntimeError, "Not readable: #{p}" unless p.readable? end end |
#required_path_strings ⇒ Object
Returns a list of path strings that need to be backed up.
68 69 70 |
# File 'lib/mysql_backup/entity/files.rb', line 68 def required_path_strings files = required_paths.map {|p| p.cleanpath.to_s} end |
#set_path_vars(var_names, args = {}) ⇒ Object
Given a set of variable names, create a set of matching Pathname objects with _path
appended to the name.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mysql_backup/entity/files.rb', line 81 def set_path_vars var_names, args = {} #:nodoc: args.each_pair do |k,v| send "#{k}=", v end var_names.each do |p| instance_var_name = "@#{p}" instance_var_value = instance_variable_get(instance_var_name) path_instance_var_name = "@#{p}_path" raise RuntimeError, "Must pass :#{p}" unless instance_var_value new_path = Pathname.new(instance_var_value) instance_variable_set path_instance_var_name, new_path raise RuntimeError, "Must provide a readable file for #{instance_var_name}" unless new_path.readable? end end |