Class: Backup::Database::SQLite

Inherits:
Base
  • Object
show all
Defined in:
lib/backup/database/sqlite.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Attributes inherited from Base

#database_id, #dump_path, #model

Instance Method Summary collapse

Methods included from Config::Helpers

included

Constructor Details

#initialize(model, database_id = nil, &block) ⇒ SQLite

Creates a new instance of the SQLite adapter object



18
19
20
21
22
23
# File 'lib/backup/database/sqlite.rb', line 18

def initialize(model, database_id = nil, &block)
  super
  instance_eval(&block) if block_given?

  @sqlitedump_utility ||= utility(:sqlitedump)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Backup::Config::Helpers

Instance Attribute Details

#pathObject

Path to the sqlite3 file



10
11
12
# File 'lib/backup/database/sqlite.rb', line 10

def path
  @path
end

#sqlitedump_utilityObject

Path to sqlite utility (optional)



14
15
16
# File 'lib/backup/database/sqlite.rb', line 14

def sqlitedump_utility
  @sqlitedump_utility
end

Instance Method Details

#perform!Object

Performs the sqlitedump command and outputs the data to the specified path based on the ‘trigger’



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/backup/database/sqlite.rb', line 28

def perform!
  super

  dump = "echo '.dump' | #{ sqlitedump_utility } #{ path }"

  pipeline = Pipeline.new
  dump_ext = 'sql'

  pipeline << dump
  if model.compressor
    model.compressor.compress_with do |command, ext|
      pipeline << command
      dump_ext << ext
    end
  end

  pipeline << "cat > '#{ File.join( dump_path , dump_filename) }.#{ dump_ext }'"

  pipeline.run

  if pipeline.success?
    log!(:finished)
  else
    raise Error,
      "#{ database_name } Dump Failed!\n" + pipeline.error_messages
  end
end