Class: Backhoe::Backup

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_key ⇒ Object

Returns the value of attribute access_key

Returns:

  • (Object) —

    the current value of access_key



6
7
8
# File 'lib/backhoe/backup.rb', line 6

def access_key
  @access_key
end

#s3_path ⇒ Object

Returns the value of attribute s3_path

Returns:

  • (Object) —

    the current value of s3_path



6
7
8
# File 'lib/backhoe/backup.rb', line 6

def s3_path
  @s3_path
end

#secret_key ⇒ Object

Returns the value of attribute secret_key

Returns:

  • (Object) —

    the current value of secret_key



6
7
8
# File 'lib/backhoe/backup.rb', line 6

def secret_key
  @secret_key
end

Instance Method Details

#call ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/backhoe/backup.rb', line 7

def call
  @time = Time.now

  Backhoe.dump path

  uri = URI("https://s3-us-west-2.amazonaws.com/#{s3_path}/#{filename}")

  req = Net::HTTP::Put.new(uri, {
    "Content-Length": File.size(path).to_s,
    "Content-Type": content_type,
    "Date": date,
    "Authorization": "AWS #{access_key}:#{signature}",
    "x-amz-storage-class": "STANDARD",
    "x-amz-acl": "private",
  })
  req.body_stream = File.open(path)
  Net::HTTP.start(uri.hostname) { |http| http.request(req) }
end