Class: Bard::Backup::Restore

Inherits:
Struct
  • Object
show all
Defined in:
lib/bard/backup/restore.rb

Overview

Downloads a database backup from S3 and loads it into the local database. The backup nearest at is selected, decrypted if necessary, and loaded via backhoe.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(at:, drop_and_create: true, destinations: nil) ⇒ Restore

Returns a new instance of Restore.



15
16
17
# File 'lib/bard/backup/restore.rb', line 15

def initialize(at:, drop_and_create: true, destinations: nil)
  super
end

Instance Attribute Details

#atObject

Returns the value of attribute at

Returns:

  • (Object)

    the current value of at



10
11
12
# File 'lib/bard/backup/restore.rb', line 10

def at
  @at
end

#destinationsObject

Returns the value of attribute destinations

Returns:

  • (Object)

    the current value of destinations



10
11
12
# File 'lib/bard/backup/restore.rb', line 10

def destinations
  @destinations
end

#drop_and_createObject

Returns the value of attribute drop_and_create

Returns:

  • (Object)

    the current value of drop_and_create



10
11
12
# File 'lib/bard/backup/restore.rb', line 10

def drop_and_create
  @drop_and_create
end

Class Method Details

.callObject



11
12
13
# File 'lib/bard/backup/restore.rb', line 11

def self.call(...)
  new(...).call
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bard/backup/restore.rb', line 19

def call
  backup = Finder.new(destinations).find(at: at)
  body = backup[:destination].s3_tree.get(backup[:filename])
  path = "/tmp/bard-backup-restore-#{File.basename(backup[:filename])}"
  File.binwrite(path, body)
  Backhoe.load(path, drop_and_create: drop_and_create)

  Bard::Backup.new(
    timestamp: backup[:timestamp],
    size: body.bytesize,
    destinations: [backup[:destination].info],
  )
ensure
  FileUtils.rm_f(path) if path
end