heroku_s3_backups 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/heroku_s3_backups.rb +43 -13
- data/lib/heroku_s3_backups/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 578895ea7218009155fa1a62a6e3ff32831216daeb1e9257f08376e5c1d70806
|
4
|
+
data.tar.gz: e40f81575e440ee42392aa1ee6eb188b846af8f1412b62c17c1969057ba73a54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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").
|
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
|
|
data/lib/heroku_s3_backups.rb
CHANGED
@@ -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
|
-
|
25
|
+
capture if options[:capture]
|
21
26
|
|
22
|
-
#
|
23
|
-
|
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
|
-
#
|
26
|
-
|
27
|
-
|
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
|
-
|
47
|
+
HerokuCLI.cmd("pg:backups:capture", @app_name)
|
30
48
|
|
31
|
-
#
|
32
|
-
|
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
|
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
|
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.
|
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-
|
11
|
+
date: 2018-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|