Class: MysqlBackup::Librarian::Backup

Inherits:
Object
  • Object
show all
Includes:
Comparable, FactoryCreateMethod, NamedArguments
Defined in:
lib/mysql_backup/librarian/backup.rb

Overview

A backup is a complete set of identifiers for each run of backup type (full or log). Each backup has multiple identifiers because a single backup can have multiple files. The mysql binary logs are tarred up and then split into smaller parts to fit on S3. The same for mysqldump files; they can be greater than the size you can store in one S3 bucket.

Direct Known Subclasses

Full, Log

Defined Under Namespace

Classes: Full, Log

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FactoryCreateMethod

included

Constructor Details

#initialize(args = {}) ⇒ Backup

Returns a new instance of Backup.



25
26
27
28
29
# File 'lib/mysql_backup/librarian/backup.rb', line 25

def initialize args = {}
  super
  args[:identifier] or raise RuntimeError, "Must provide :identifier"
  identifiers << args[:identifier]
end

Instance Attribute Details

#identifiersObject

Returns an array of MysqlBackup::Entity::Identifier objects that are the members of this group



20
21
22
# File 'lib/mysql_backup/librarian/backup.rb', line 20

def identifiers
  @identifiers
end

Class Method Details

.new_if_class_match(klass) ⇒ Object



85
86
87
# File 'lib/mysql_backup/librarian/backup.rb', line 85

def self.new_if_class_match klass
  new_if_class klass, :identifier
end

Instance Method Details

#<=>(rhs) ⇒ Object



69
70
71
# File 'lib/mysql_backup/librarian/backup.rb', line 69

def <=> rhs
  identifiers.first.log_file_number <=> rhs.log_file_number || identifiers.first.log_position <=> rhs.log_position
end

#add_identifier_to_group_if_the_identifier_should_be_in_this_group(identifier) ⇒ Object

Returns true if the identifier was added to this group



46
47
48
49
50
# File 'lib/mysql_backup/librarian/backup.rb', line 46

def add_identifier_to_group_if_the_identifier_should_be_in_this_group identifier
  is_part = is_part_of_this_group? identifier
  identifiers << identifier if is_part
  is_part
end

#each_identifierObject



65
66
67
# File 'lib/mysql_backup/librarian/backup.rb', line 65

def each_identifier 
  identifiers.each {|i| yield i}  
end

#is_part_of_this_group?(identifier) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/mysql_backup/librarian/backup.rb', line 52

def is_part_of_this_group? identifier
  return false unless identifier_class?.first === identifier
  log_file == identifier.log_file && log_position == identifier.log_position
end

#log_fileObject



57
58
59
# File 'lib/mysql_backup/librarian/backup.rb', line 57

def log_file
  identifiers.first.log_file
end

#log_positionObject



61
62
63
# File 'lib/mysql_backup/librarian/backup.rb', line 61

def log_position
  identifiers.first.log_position
end

#most_recent?Boolean

True if this backup is the most recent of its type

Returns:

  • (Boolean)


32
33
# File 'lib/mysql_backup/librarian/backup.rb', line 32

def most_recent?
end

#name_match(rhs) ⇒ Object



81
82
83
# File 'lib/mysql_backup/librarian/backup.rb', line 81

def name_match rhs
  to_s == rhs
end

#to_sObject

The id string for a backup doesn’t include the number of parts and the part itself.

(Split on :, ignore the last two elements)



77
78
79
# File 'lib/mysql_backup/librarian/backup.rb', line 77

def to_s
  identifiers.first.to_s.split(':').slice(0..-3).join(':')
end

#write_files(directory) ⇒ Object

Write the files for this backup, untarring and unzipping as required.



38
39
# File 'lib/mysql_backup/librarian/backup.rb', line 38

def write_files directory
end

#write_raw_files(directory) ⇒ Object

Write the files for this backup without untarring and unzipping.



42
43
# File 'lib/mysql_backup/librarian/backup.rb', line 42

def write_raw_files directory
end