heroku_s3_backups 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7ed67c83f81d5ffa7ed0f9a9e9b9e2035f317c3017bae62222d561eb70abdd8
4
- data.tar.gz: e2432735031695cd647322eac627d9886c8bde38e24c23fcdab594639320a65f
3
+ metadata.gz: 531da22f26527e8f7b45b0a22ed1e54c8d3987ad9a0cead4807f0358d104b7f4
4
+ data.tar.gz: 591a02426d6204682beef2797e07cd297b6dc92006707ceaff5f8ef733e2bfa0
5
5
  SHA512:
6
- metadata.gz: bb9cfedeaa85f7d5c6598c4f9779f7e68cd71e147d964027c3a1c528aa1eb0b80f37a09c03a430bb4f86ccb1dd87f32ebff144d7959f462096f0618bcc8b2cce
7
- data.tar.gz: 74735322784e5a2f824dbf9b5b11c668e94e5f72f40b1d0c91d2294f0e5be6fa0b571eff5f8c1abb67867fac6841862622e3a245dca903e0499c6131a60ea2ca
6
+ metadata.gz: 1f1f076b913557126fff69538f7f0168fa3d50ca3bb83b5ab79cf05945b3a32b8f267a52635d55805a948c7b8b0947add24c0c6702d82e136d9da63d82544a6b
7
+ data.tar.gz: 41365674bfbf2008e3d1de7aa82342d4c14c59b2e600e86c06d957e7d74071fadd436726c0a3276cbe8c2e7ad0b53e84ce528779498cd876f2630e4ccf2c130f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- heroku_s3_backups (0.1.0)
4
+ heroku_s3_backups (0.1.1)
5
5
  s3 (~> 0.3)
6
6
 
7
7
  GEM
@@ -1,3 +1,3 @@
1
1
  module HerokuS3Backups
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,64 +1,65 @@
1
1
  require "s3"
2
2
  require "heroku_s3_backups/version"
3
3
  require "heroku_cli.rb"
4
+ module HerokuS3Backups
5
+ class Heroku
6
+ include HerokuCLI
4
7
 
5
- class HerokuS3Backups
6
- include HerokuCLI
8
+ # @param {string} app_name
9
+ # @param {string} backup_location
10
+ # @return nil
11
+ def initialize(app_name)
12
+ @app_name = app_name
13
+ end
7
14
 
8
- # @param {string} app_name
9
- # @param {string} backup_location
10
- # @return nil
11
- def initialize(app_name)
12
- @app_name = app_name
13
- end
15
+ # @param {hash} options
16
+ # @return nil
17
+ def backup_to_s3(backup_location, options = { capture: true })
14
18
 
15
- # @param {hash} options
16
- # @return nil
17
- def backup(backup_location, options = { capture: true })
19
+ # Capture backups if toggled
20
+ HerokuCLI.cmd("pg:backups:capture", @app_name) if options[:capture]
18
21
 
19
- # Capture backups if toggled
20
- HerokuCLI.cmd("pg:backups:capture", @app_name) if options[:capture]
22
+ # Generate the filename for the backup
23
+ backup_filename = generate_backup_name
21
24
 
22
- # Generate the filename for the backup
23
- backup_filename = generate_backup_name
25
+ # Download the latest backup
26
+ # TODO: Be more explicit about which DB to download
27
+ HerokuCLI.cmd("pg:backups:download --output #{backup_filename}", @app_name)
24
28
 
25
- # Download the latest backup
26
- # TODO: Be more explicit about which DB to download
27
- HerokuCLI.cmd("pg:backups:download --output #{backup_filename}", @app_name)
29
+ store_on_s3(backup_location, backup_filename)
28
30
 
29
- store_on_s3(backup_location, backup_filename)
31
+ # Remove the backup from the system
32
+ system("rm #{backup_filename}")
33
+ end
30
34
 
31
- # Remove the backup from the system
32
- system("rm #{backup_filename}")
33
- end
35
+ private
34
36
 
35
- private
37
+ # Stores the recently backed up file in a specified S3 bucket
38
+ # @param {string} backup_location
39
+ # @param {string} backup_filename
40
+ def store_on_s3(backup_location, backup_filename)
41
+ prod_backup_folder = AWS_S3().buckets.find(ENV["S3_PRODUCTION_BACKUP_BUCKET"]).objects(prefix: backup_location)
36
42
 
37
- # Stores the recently backed up file in a specified S3 bucket
38
- # @param {string} backup_location
39
- # @param {string} backup_filename
40
- def store_on_s3(backup_location, backup_filename)
41
- prod_backup_folder = AWS_S3().buckets.find(ENV["S3_PRODUCTION_BACKUP_BUCKET"]).objects(prefix: backup_location)
43
+ backup_obj = prod_backup_folder.build("#{backup_location}/#{backup_filename}")
42
44
 
43
- backup_obj = prod_backup_folder.build("#{backup_location}/#{backup_filename}")
45
+ # Need to do this to set content length for some reason
46
+ backup_obj.content = open(backup_filename)
44
47
 
45
- # Need to do this to set content length for some reason
46
- backup_obj.content = open(backup_filename)
48
+ backup_obj.save
49
+ end
47
50
 
48
- backup_obj.save
49
- end
50
-
51
- def generate_backup_name
52
- curr_time = Time.now.strftime("%Y-%m-%d_%H%M%S")
53
- "backup_#{curr_time}.dump"
54
- end
51
+ def generate_backup_name
52
+ curr_time = Time.now.strftime("%Y-%m-%d_%H%M%S")
53
+ "backup_#{curr_time}.dump"
54
+ end
55
55
 
56
- # Instantiates a new S3 service using the provided credentials
57
- # @return S3::Service
58
- def AWS_S3
59
- S3::Service.new(
60
- access_key_id: ENV["S3_ACCESS_KEY_ID"],
61
- secret_access_key: ENV["S3_SECRET_ACCESS_KEY"]
62
- )
56
+ # Instantiates a new S3 service using the provided credentials
57
+ # @return S3::Service
58
+ def AWS_S3
59
+ S3::Service.new(
60
+ access_key_id: ENV["S3_ACCESS_KEY_ID"],
61
+ secret_access_key: ENV["S3_SECRET_ACCESS_KEY"]
62
+ )
63
+ end
63
64
  end
64
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_s3_backups
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - joerodrig