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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/heroku_s3_backups/version.rb +1 -1
- data/lib/heroku_s3_backups.rb +46 -45
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 531da22f26527e8f7b45b0a22ed1e54c8d3987ad9a0cead4807f0358d104b7f4
|
4
|
+
data.tar.gz: 591a02426d6204682beef2797e07cd297b6dc92006707ceaff5f8ef733e2bfa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f1f076b913557126fff69538f7f0168fa3d50ca3bb83b5ab79cf05945b3a32b8f267a52635d55805a948c7b8b0947add24c0c6702d82e136d9da63d82544a6b
|
7
|
+
data.tar.gz: 41365674bfbf2008e3d1de7aa82342d4c14c59b2e600e86c06d957e7d74071fadd436726c0a3276cbe8c2e7ad0b53e84ce528779498cd876f2630e4ccf2c130f
|
data/Gemfile.lock
CHANGED
data/lib/heroku_s3_backups.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
16
|
-
|
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
|
-
|
20
|
-
|
22
|
+
# Generate the filename for the backup
|
23
|
+
backup_filename = generate_backup_name
|
21
24
|
|
22
|
-
|
23
|
-
|
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
|
-
|
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
|
-
|
31
|
+
# Remove the backup from the system
|
32
|
+
system("rm #{backup_filename}")
|
33
|
+
end
|
30
34
|
|
31
|
-
|
32
|
-
system("rm #{backup_filename}")
|
33
|
-
end
|
35
|
+
private
|
34
36
|
|
35
|
-
|
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
|
-
|
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
|
-
|
45
|
+
# Need to do this to set content length for some reason
|
46
|
+
backup_obj.content = open(backup_filename)
|
44
47
|
|
45
|
-
|
46
|
-
|
48
|
+
backup_obj.save
|
49
|
+
end
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|