Class: Bard::Backup::UploadDestination

Inherits:
Destination
  • Object
show all
Defined in:
lib/bard/backup/destination/upload_destination.rb

Instance Attribute Summary

Attributes inherited from Destination

#config

Instance Method Summary collapse

Methods inherited from Destination

build

Instance Method Details

#callObject

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bard/backup/destination/upload_destination.rb', line 10

def call
  timestamp = now
  filename = "#{timestamp.iso8601}.sql.gz"
  temp_path = "/tmp/#{filename}"
  errors = []

  begin
    Backhoe.dump(temp_path)
    size = File.size(temp_path)

    threads = urls.map do |url|
      Thread.new do
        upload_to_url(url, temp_path)
      rescue => e
        errors << e
      end
    end

    threads.each(&:join)
  ensure
    FileUtils.rm_f(temp_path)
  end

  raise Error, "Upload failed: #{errors.map(&:message).join(", ")}" unless errors.empty?

  Bard::Backup.new(timestamp:, size:, destinations: [])
end

#infoObject



38
39
40
# File 'lib/bard/backup/destination/upload_destination.rb', line 38

def info
  { type: :upload, name: config[:name] }.compact
end