Class: S3Archive::DbDump
- Inherits:
-
Object
- Object
- S3Archive::DbDump
- Includes:
- Logging
- Defined in:
- lib/s3archive/db_dump.rb
Instance Attribute Summary collapse
-
#db_config ⇒ Object
readonly
Returns the value of attribute db_config.
-
#dump_path ⇒ Object
readonly
Returns the value of attribute dump_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(db_config, name = 'dbdump') ⇒ DbDump
constructor
A new instance of DbDump.
- #run ⇒ Object
Methods included from Logging
Constructor Details
#initialize(db_config, name = 'dbdump') ⇒ DbDump
Returns a new instance of DbDump.
12 13 14 15 |
# File 'lib/s3archive/db_dump.rb', line 12 def initialize(db_config, name = 'dbdump') @db_config = db_config @name = name.gsub(/\s+/, '_') end |
Instance Attribute Details
#db_config ⇒ Object (readonly)
Returns the value of attribute db_config.
10 11 12 |
# File 'lib/s3archive/db_dump.rb', line 10 def db_config @db_config end |
#dump_path ⇒ Object (readonly)
Returns the value of attribute dump_path.
10 11 12 |
# File 'lib/s3archive/db_dump.rb', line 10 def dump_path @dump_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/s3archive/db_dump.rb', line 10 def name @name end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/s3archive/db_dump.rb', line 17 def run backup_filename = "#{name}-#{Time.now.utc.strftime("%Y%m%dT%H%M%S")}.sql.gz" backup_path = "/tmp/#{backup_filename}" logger.info "* Dumping and compressing data to #{backup_path}." case db_config['adapter'] when /^mysql/ db_host = db_config['host'] db_name = db_config['database'] password = "-p#{db_config['password']}" if db_config['password'] = "--opt --skip-lock-tables --single-transaction --skip-extended-insert" = "-u #{db_config['username']} #{password} #{} -h #{db_host} #{db_name}" logger.info "** Backing up mysql db #{db_name}@#{db_host}" system "mysqldump #{} | gzip -c > #{backup_path}" else db_config.delete 'password' msg = "Don't know how to dump #{db_config['adapter']} database: #{db_config.inspect}'" logger.fatal msg raise msg end @dump_path = backup_path end |