Class: MysqlBackup::Entity::Files::Innodb

Inherits:
MysqlBackup::Entity::Files show all
Defined in:
lib/mysql_backup/entity/files/innodb.rb

Overview

Used to save all of the files for a MySQL Innodb database.

Normal use is:

i = Mysql::InnodbFiles.new
array_of_pathname_objects = i.tar_files

The caller is responsible for removing the files returned from tar_files.

See new for a description of the arguments used to create a Mysql::InnodbFiles object matching your mysql layout.

You can create instances of Mysql::InnodbFiles by hand, but normally you’d use MysqlBackup::Server to create them for you.

MysqlBackup::Server objects will detect where your data files are and fill in the correct options for Mysql::InnodbFiles.new.

What is backed up

  • Innodb data files. Your innodb files must all start with the same string and end with a sequence of digits. ibdata001, ibdata002, etc. is fine, but firstfile, secondfile is not supported.

  • MyISAM files.

  • Log files. You need to specify the directory where the log files are stored; there’s no way to extract this from a running server.

  • mysqladmindump files.

For all of these, we track the log positions (the log file/log position pair).

Instance Attribute Summary collapse

Attributes inherited from MysqlBackup::Entity

#log

Instance Method Summary collapse

Methods inherited from MysqlBackup::Entity::Files

build_files, #confirm_required_paths_are_readable, create_tar_files, do_tar, process_file, #required_path_strings, #set_path_vars

Methods inherited from MysqlBackup::Entity

tar_files

Constructor Details

#initialize(args = {}) ⇒ Innodb

Takes the following arguments:

:datadir => The MySQL data directory.
:innodb_data_home_dir => The directory for innodb files.
:innodb_data_file_path => The root name for the innodb files.
:log_bin_dir => The directory containing the log files.
:log_bin => The prefix of the log files.

The following files will be backed up with the default base_dir and ib_basename:

/var/lib/mysql/ibdata*
/var/lib/mysql/*/*.frm - all files in any directory that contain one or more *.frm files
/var/lib/mysql/*/*.MYD - all files in any directory that contain one or more *.MYD files


49
50
51
# File 'lib/mysql_backup/entity/files/innodb.rb', line 49

def initialize args = {}
  set_path_vars %w(datadir innodb_data_home_dir), args
end

Instance Attribute Details

#datadirObject

Returns the value of attribute datadir.



34
35
36
# File 'lib/mysql_backup/entity/files/innodb.rb', line 34

def datadir
  @datadir
end

#innodb_data_file_pathObject

Returns the value of attribute innodb_data_file_path.



34
35
36
# File 'lib/mysql_backup/entity/files/innodb.rb', line 34

def innodb_data_file_path
  @innodb_data_file_path
end

#innodb_data_home_dirObject

Returns the value of attribute innodb_data_home_dir.



34
35
36
# File 'lib/mysql_backup/entity/files/innodb.rb', line 34

def innodb_data_home_dir
  @innodb_data_home_dir
end

Instance Method Details

#innodb_database_dirsObject

Returns an array of Pathnames for all databases in the base directory.

A database in this case is a directory containing any files matching *.frm.



67
68
69
70
71
# File 'lib/mysql_backup/entity/files/innodb.rb', line 67

def innodb_database_dirs
  result = Pathname.glob(@innodb_data_home_dir_path + '*/*.frm')
  result = result.map {|d| d.dirname}
  result.uniq
end

#innodb_filesObject



73
74
75
76
# File 'lib/mysql_backup/entity/files/innodb.rb', line 73

def innodb_files
  ib = @innodb_data_home_dir_path + @innodb_data_file_path
  Pathname.glob ib.cleanpath.to_s + '*'
end

#required_pathsObject

Returns a list of Pathname objects that need to be backed up for a mysql server using innodb.



55
56
57
58
59
60
# File 'lib/mysql_backup/entity/files/innodb.rb', line 55

def required_paths
  result = []
  result.concat innodb_files
  result.concat innodb_database_dirs
  result.uniq
end