Class: Backy::PgRestore

Inherits:
Object
  • Object
show all
Includes:
AppConfig, Db
Defined in:
lib/backy/pg_restore.rb

Constant Summary collapse

DUMP_DIR =
"db/dump"

Instance Method Summary collapse

Constructor Details

#initialize(file_name:) ⇒ PgRestore

Returns a new instance of PgRestore.



8
9
10
# File 'lib/backy/pg_restore.rb', line 8

def initialize(file_name:)
  @file_name = file_name
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/backy/pg_restore.rb', line 12

def call
  pigz_installed = system("which pigz > /dev/null 2>&1")
  multicore = Etc.nprocessors > 1
  use_multicore = ENV["BACKY_USE_PARALLEL"] == "true"

  if pigz_installed && multicore && use_multicore
    Logger.log("Using parallel restore with pigz")
    parallel_restore
  else
    Logger.log("Pigz not installed or system is not multicore")
    Logger.log("Using plain text restore")
    plain_text_restore
  end
end