heroku_s3_backups 0.1.3 → 0.1.4

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: 30af0c9bc6a1781af32673bd76b0c09b13f557e8036bd2e1adde45b4a740bc6d
4
- data.tar.gz: 5a7044c7662fa60119f4ec3cbc0093041ed107ba7752723fc781746b2c756dcb
3
+ metadata.gz: 578895ea7218009155fa1a62a6e3ff32831216daeb1e9257f08376e5c1d70806
4
+ data.tar.gz: e40f81575e440ee42392aa1ee6eb188b846af8f1412b62c17c1969057ba73a54
5
5
  SHA512:
6
- metadata.gz: 4647e5deba4cabe9c4cb29415e2411fbf0502282ba6d910ffda663ed226d1f6c508b68a45a949405221d962cbaabd6a8af142c18a2cd220fefe9e40a52c7c532
7
- data.tar.gz: 6940c24f0149ec6f799228df2f1c89ea02d19a8daaf54f5cfd7316ebb273a3f72503565f0b829abd303eb1f7094901e9d73da325b8265d0294d508030fdd8a9d
6
+ metadata.gz: cd5a6302f00153dbc489363f1215b042ee636b61e6ffde429ee5b40928bc7869eb9485f4c494c99ecb665f8a668f7e75fd3b8133107cf8fecc252516715b3067
7
+ data.tar.gz: 3e78db9b20ca4dfad706d72b8f7dfaa1df60bb9de6a36e95990e4fdee96cb9674af4d7b8d1a0259754832b476c1306fbffbfc70ac721cc32f54c410b1578f513
data/README.md CHANGED
@@ -46,7 +46,7 @@ HEROKU_API_KEY="1234-abcd"
46
46
  ```
47
47
 
48
48
  To run:
49
- `HerokuS3Backups::Heroku.new("name-of-application").backup("path/to/backup/folder")`
49
+ `HerokuS3Backups::Heroku.new("name-of-application").backup_to_s3("path/to/backup/folder")`
50
50
 
51
51
  If you're running this in a Heroku application, ensure that you have the [Heroku Buildpack CLI](https://github.com/heroku/heroku-buildpack-cli) installed.
52
52
 
@@ -10,47 +10,77 @@ module HerokuS3Backups
10
10
  # @return nil
11
11
  def initialize(app_name)
12
12
  @app_name = app_name
13
+ @backup_filename = nil
13
14
  end
14
15
 
16
+ # Backup Heroku DB to S3
17
+ # Valid options:
18
+ # => {boolean} capture - If true, capture a new backup at the current point in
19
+ # time. Otherwise, we'll just download the latest backup
15
20
  # @param {hash} options
16
21
  # @return nil
17
22
  def backup_to_s3(backup_location, options = { capture: true })
18
23
 
19
24
  # Capture backups if toggled
20
- HerokuCLI.cmd("pg:backups:capture", @app_name) if options[:capture]
25
+ capture if options[:capture]
21
26
 
22
- # Generate the filename for the backup
23
- backup_filename = generate_backup_name
27
+ # Download the latest backup from Heroku and store it on S3
28
+ generate_backup_filename
29
+ download(@backup_filename)
30
+ store_on_s3(backup_location)
24
31
 
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)
32
+ # Remove the backup from the local system
33
+ remove_backup(@backup_filename)
34
+ end
35
+
36
+ # Creates a new Heroku backup for a particular moment in time
37
+ # Valid options:
38
+ # => {boolean} maintenance_mode - If true, set the application to go into
39
+ # maintenance mode to prevent further interaction until the capture is
40
+ # complete
41
+ # @param {hash} options
42
+ # @return nil
43
+ def capture(options = { maintenance_mode: false })
44
+ # Enable maintenance mode if set
45
+ HerokuCLI.cmd("maintenance:on", @app_name) if options[:maintenance_mode]
28
46
 
29
- store_on_s3(backup_location, backup_filename)
47
+ HerokuCLI.cmd("pg:backups:capture", @app_name)
30
48
 
31
- # Remove the backup from the system
32
- system("rm #{backup_filename}")
49
+ # Turn off maintenance mode once capture is complete
50
+ HerokuCLI.cmd("maintenance:off", @app_name) if options[:maintenance_mode]
51
+ end
52
+
53
+ # Download the latest backup
54
+ # TODO: Be more explicit about which DB to download
55
+ # @param {string} output_filename
56
+ def download(output_filename)
57
+ raise "Please specify a filename" if output_filename.length.eql?(0)
58
+ HerokuCLI.cmd("pg:backups:download --output #{output_filename}", @app_name)
33
59
  end
34
60
 
35
61
  private
36
62
 
63
+ def remove_backup
64
+ system("rm #{@backup_filename}")
65
+ @backup_filename = nil
66
+ end
67
+
37
68
  # Stores the recently backed up file in a specified S3 bucket
38
69
  # @param {string} backup_location
39
- # @param {string} backup_filename
40
70
  def store_on_s3(backup_location, backup_filename)
41
71
  prod_backup_folder = AWS_S3().buckets.find(ENV["S3_PRODUCTION_BACKUP_BUCKET"]).objects(prefix: backup_location)
42
72
 
43
73
  backup_obj = prod_backup_folder.build("#{backup_location}/#{backup_filename}")
44
74
 
45
75
  # Need to do this to set content length for some reason
46
- backup_obj.content = open(backup_filename)
76
+ backup_obj.content = open(@backup_filename)
47
77
 
48
78
  backup_obj.save
49
79
  end
50
80
 
51
- def generate_backup_name
81
+ def generate_backup_filename
52
82
  curr_time = Time.now.strftime("%Y-%m-%d_%H%M%S")
53
- "backup_#{curr_time}.dump"
83
+ @backup_filename = "backup_#{curr_time}.dump"
54
84
  end
55
85
 
56
86
  # Instantiates a new S3 service using the provided credentials
@@ -1,3 +1,3 @@
1
1
  module HerokuS3Backups
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_s3_backups
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - joerodrig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-09 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler