Class: Backup::Tasks::MySQL
- Inherits:
-
Object
- Object
- Backup::Tasks::MySQL
- Defined in:
- lib/backup-agent/tasks/mysql.rb
Defined Under Namespace
Classes: Credentials
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #databases ⇒ Object
- #dump_options ⇒ Object
- #host_options ⇒ Object
-
#initialize(host:, credentials:, databases: :all, **options) ⇒ MySQL
constructor
A new instance of MySQL.
- #perform(storage) ⇒ Object
Constructor Details
#initialize(host:, credentials:, databases: :all, **options) ⇒ MySQL
Returns a new instance of MySQL.
8 9 10 11 12 13 |
# File 'lib/backup-agent/tasks/mysql.rb', line 8 def initialize(host:, credentials:, databases: :all, **) @host = host @credentials = credentials @databases = databases = end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
6 7 8 |
# File 'lib/backup-agent/tasks/mysql.rb', line 6 def credentials @credentials end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/backup-agent/tasks/mysql.rb', line 6 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/backup-agent/tasks/mysql.rb', line 6 def end |
Instance Method Details
#databases ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/backup-agent/tasks/mysql.rb', line 30 def databases if @databases == :all command("mysql", *credentials., *, "-e", "SHOW DATABASES;") .split("\n") .reject { |el| el =~ /database|information_schema|mysql|performance_schema|test|phpmyadmin|pma|sys/i } else [@databases].flatten.compact end end |
#dump_options ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/backup-agent/tasks/mysql.rb', line 40 def .fetch(:dump_options) do %W( --add-drop-table --add-locks --allow-keywords --comments --complete-insert --create-options --disable-keys --extended-insert --lock-tables --quick --quote-names --routines --set-charset --dump-date --tz-utc --verbose ) end end |
#host_options ⇒ Object
61 62 63 |
# File 'lib/backup-agent/tasks/mysql.rb', line 61 def ["--host=#{@host}"] end |
#perform(storage) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/backup-agent/tasks/mysql.rb', line 15 def perform(storage) databases.map do |db| Tempfile.open do |tempfile| command("mysqldump", *credentials., *, *, "--databases", db).tap do |dump_sql| stdin dump_sql do command("xz", "--compress", "-9", "--format=xz", "--keep", "--threads=0", "--verbose", "--check=sha256").tap do |dump_xz| tempfile.write(dump_xz) storage.store(construct_filename(db, ".sql.xz"), tempfile.path) end end end end end end |