Class: Captive::Commands::DbDump

Inherits:
Object
  • Object
show all
Defined in:
lib/captive/commands/db_dump.rb

Instance Method Summary collapse

Constructor Details

#initialize(kubectl:, trail:) ⇒ DbDump

Returns a new instance of DbDump.



8
9
10
11
# File 'lib/captive/commands/db_dump.rb', line 8

def initialize(kubectl:, trail:)
  @kubectl = kubectl
  @trail   = trail
end

Instance Method Details

#default_filename(app) ⇒ Object



27
28
29
30
# File 'lib/captive/commands/db_dump.rb', line 27

def default_filename(app)
  base = ENV.fetch("CAPTIVE_ORIG_DIR", Dir.pwd)
  File.join(base, "#{app}_#{Time.now.strftime("%Y%m%d_%H%M%S")}.pgsql")
end

#run(app, output_file) {|:dumping| ... } ⇒ Object

Yields:

  • (:dumping)

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/captive/commands/db_dump.rb', line 13

def run(app, output_file)
  @trail.db_dumped(app)
  output_file ||= default_filename(app)
  pg_pod        = @kubectl.postgres_pod_name(app, app)
  password      = @kubectl.postgres_secret_password(app, app)
  cmd           = "PGPASSWORD='#{password}' pg_dump -h localhost -U app -d app -Fc"

  yield :dumping if block_given?
  ok = @kubectl.dump_from_pod(app, pg_pod, output_file, cmd)
  raise DumpError, "Le dump a échoué" if ok == false

  output_file
end