Class: SqlDumper
- Inherits:
-
Object
- Object
- SqlDumper
- Defined in:
- app/models/sql_dumper.rb
Constant Summary collapse
- DUMP_DIR =
'/tmp/mysql-backup'
- DUMP_FILE_REGEX =
/#{DUMP_DIR}\/dump_[0-9._]{17}\.sql/
- ARCHIVE_FILE_REGEX =
/#{DUMP_DIR}\/dump_[0-9._]{17}\.tar\.gz/
Instance Attribute Summary collapse
-
#archive_file ⇒ Object
readonly
Returns the value of attribute archive_file.
-
#dump_file ⇒ Object
readonly
Returns the value of attribute dump_file.
Instance Method Summary collapse
- #clean! ⇒ Object
- #dump! ⇒ Object
- #fake_rails_env ⇒ Object
-
#initialize ⇒ SqlDumper
constructor
A new instance of SqlDumper.
- #rails_env ⇒ Object
- #rails_root ⇒ Object
Constructor Details
#initialize ⇒ SqlDumper
Returns a new instance of SqlDumper.
30 31 32 33 |
# File 'app/models/sql_dumper.rb', line 30 def initialize return self if load_db_config and prepare_dump_paths nil end |
Instance Attribute Details
#archive_file ⇒ Object (readonly)
Returns the value of attribute archive_file.
6 7 8 |
# File 'app/models/sql_dumper.rb', line 6 def archive_file @archive_file end |
#dump_file ⇒ Object (readonly)
Returns the value of attribute dump_file.
7 8 9 |
# File 'app/models/sql_dumper.rb', line 7 def dump_file @dump_file end |
Instance Method Details
#clean! ⇒ Object
9 10 11 12 13 14 |
# File 'app/models/sql_dumper.rb', line 9 def clean! FileUtils.rm_rf @temp_dir true rescue false end |
#dump! ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'app/models/sql_dumper.rb', line 16 def dump! FileUtils.mkdir_p @temp_dir system dump_command if File.exists? @dump_file # temporary changes pwd Dir.chdir(@temp_dir) { |path| system tar_command } return File.exists?(@archive_file) ? @archive_file : nil end end |
#fake_rails_env ⇒ Object
26 27 28 |
# File 'app/models/sql_dumper.rb', line 26 def fake_rails_env { database: '', username: '', password: '' } end |
#rails_env ⇒ Object
39 40 41 |
# File 'app/models/sql_dumper.rb', line 39 def rails_env rails_env ||= defined?(Rails) ? Rails.env : fake_rails_env end |
#rails_root ⇒ Object
35 36 37 |
# File 'app/models/sql_dumper.rb', line 35 def rails_root defined?(Rails) ? Rails.root : '/tmp' end |