nxt_heroku_database_backup 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f6f9bc7071511bef9e7526bd263414833ed783263451bf9cb58a266645d6f985
4
+ data.tar.gz: 07f88c0d18c20745775d551da611238298adafa8d1ea1980f26a7f6b0f21e881
5
+ SHA512:
6
+ metadata.gz: 60c9be3d5356e5911605a12d97ac93b9392acb6f4b5e6aa4174f3c0f01ceef8ae8cce44266ea308abe3f3aec1c78353f86cf121914060eab6031338369261a95
7
+ data.tar.gz: 4138a9f8a442239ac427bba1904931b800ae97adfcdc680c03228b058e91ec6137bae65bbd48fccf6e6ca0bea453c0965067076187b06242fa3d0281c7d6ebb8
data/.env.test ADDED
@@ -0,0 +1,4 @@
1
+ DATABASE_BACKUP_AWS_ACCESS_KEY_ID=HEREGOESTHEKEYID
2
+ DATABASE_BACKUP_AWS_SECRET_ACCESS_KEY=hereGOESTHEACTUALKEY
3
+ DATABASE_BACKUP_AWS_REGION=eu-central-1
4
+ HEROKU_APP_NAME=heroku-test-app
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .env.development.local
13
+ .env.test.local
14
+
15
+ !/**/.keep
16
+ /storage/
17
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.1
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nxt_heroku_database_backup.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nxt_heroku_database_backup (0.1.0)
5
+ aws-sdk-s3
6
+ nxt_init
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.0.0)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.1, >= 2.1.8)
17
+ aws-eventstream (1.0.3)
18
+ aws-partitions (1.207.0)
19
+ aws-sdk-core (3.65.1)
20
+ aws-eventstream (~> 1.0, >= 1.0.2)
21
+ aws-partitions (~> 1.0)
22
+ aws-sigv4 (~> 1.1)
23
+ jmespath (~> 1.0)
24
+ aws-sdk-kms (1.24.0)
25
+ aws-sdk-core (~> 3, >= 3.61.1)
26
+ aws-sigv4 (~> 1.1)
27
+ aws-sdk-s3 (1.48.0)
28
+ aws-sdk-core (~> 3, >= 3.61.1)
29
+ aws-sdk-kms (~> 1)
30
+ aws-sigv4 (~> 1.1)
31
+ aws-sigv4 (1.1.0)
32
+ aws-eventstream (~> 1.0, >= 1.0.2)
33
+ coderay (1.1.2)
34
+ concurrent-ruby (1.1.5)
35
+ diff-lcs (1.3)
36
+ dotenv (2.7.5)
37
+ i18n (1.6.0)
38
+ concurrent-ruby (~> 1.0)
39
+ jmespath (1.4.0)
40
+ method_source (0.9.2)
41
+ minitest (5.12.0)
42
+ nxt_init (0.1.5)
43
+ activesupport
44
+ pry (0.12.2)
45
+ coderay (~> 1.1.0)
46
+ method_source (~> 0.9.0)
47
+ rake (10.5.0)
48
+ rspec (3.8.0)
49
+ rspec-core (~> 3.8.0)
50
+ rspec-expectations (~> 3.8.0)
51
+ rspec-mocks (~> 3.8.0)
52
+ rspec-core (3.8.2)
53
+ rspec-support (~> 3.8.0)
54
+ rspec-expectations (3.8.4)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.8.0)
57
+ rspec-mocks (3.8.1)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.8.0)
60
+ rspec-support (3.8.2)
61
+ thread_safe (0.3.6)
62
+ tzinfo (1.2.5)
63
+ thread_safe (~> 0.1)
64
+ zeitwerk (2.1.10)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ bundler (~> 2.0)
71
+ dotenv
72
+ nxt_heroku_database_backup!
73
+ pry
74
+ rake (~> 10.0)
75
+ rspec (~> 3.0)
76
+
77
+ BUNDLED WITH
78
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Andreas Robecke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # NxtHerokuDatabaseBackup
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nxt_heroku_database_backup`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'nxt_heroku_database_backup'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nxt_heroku_database_backup
20
+
21
+ ## Usage
22
+
23
+ In order to use the `NxtHerokuDatabaseBackup::Manager`, you need to add the [heroku-buildpack-cli](https://github.com/heroku/heroku-buildpack-cli)
24
+ to your heroku project. Then you probably want to add a rake task to you project and schedule it with the heroku scheduler to be called once a day or so.
25
+
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nxt_heroku_database_backup.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nxt_heroku_database_backup"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,84 @@
1
+ require 'open-uri'
2
+ require 'aws-sdk-s3'
3
+
4
+ module NxtHerokuDatabaseBackup
5
+ class Manager
6
+ include NxtInit
7
+
8
+ attr_init success_callback: -> { -> { true } },
9
+ environment: -> { default_environment },
10
+ backup_name: -> { default_backup_name },
11
+ backup_tmp_path: -> { default_backup_tmp_path }
12
+
13
+
14
+ def backup_latest_dump
15
+ database_backup = open(database_backup_url)
16
+ IO.copy_stream(database_backup, backup_tmp_path)
17
+ aws_object.upload_file(backup_tmp_path)
18
+ execute_success_callback
19
+ ensure
20
+ File.delete(backup_tmp_path) if File.exist?(backup_tmp_path)
21
+ end
22
+
23
+ private
24
+
25
+ def execute_success_callback
26
+ success_callback.call
27
+ end
28
+
29
+ def aws_object
30
+ @aws_object ||= begin
31
+ ensure_bucket_exists
32
+ Aws::S3::Resource.new(aws_credentials).bucket(bucket_name).object(backup_name)
33
+ end
34
+ end
35
+
36
+ def default_backup_name
37
+ "#{heroku_app_name}-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.dump"
38
+ end
39
+
40
+ def default_backup_tmp_path
41
+ "/tmp/#{backup_name}"
42
+ end
43
+
44
+ def database_backup_url
45
+ @database_backup_url ||= begin
46
+ run_heroku_cli_command "pg:backups:url"
47
+ end
48
+ end
49
+
50
+ def run_heroku_cli_command(command)
51
+ `heroku #{command} -a #{heroku_app_name}`
52
+ end
53
+
54
+ def heroku_app_name
55
+ @heroku_app_name ||= ENV.fetch('HEROKU_APP_NAME')
56
+ end
57
+
58
+ def ensure_bucket_exists
59
+ s3.head_bucket(bucket: bucket_name)
60
+ rescue Aws::S3::Errors::NotFound
61
+ s3.create_bucket(bucket: bucket_name)
62
+ end
63
+
64
+ def bucket_name
65
+ @bucket_name ||= "#{heroku_app_name}-db-backups"
66
+ end
67
+
68
+ def default_environment
69
+ Object.const_defined?('HerokuEnv') && HerokuEnv.env || 'development'
70
+ end
71
+
72
+ def s3
73
+ @s3 ||= Aws::S3::Client.new(**aws_credentials)
74
+ end
75
+
76
+ def aws_credentials
77
+ {
78
+ access_key_id: ENV.fetch('DATABASE_BACKUP_AWS_ACCESS_KEY_ID'),
79
+ secret_access_key: ENV.fetch('DATABASE_BACKUP_AWS_SECRET_ACCESS_KEY'),
80
+ region: ENV.fetch('DATABASE_BACKUP_AWS_REGION')
81
+ }
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module NxtHerokuDatabaseBackup
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'nxt_init'
2
+ require "nxt_heroku_database_backup/version"
3
+ require "nxt_heroku_database_backup/manager"
4
+
5
+ module NxtHerokuDatabaseBackup
6
+ end
@@ -0,0 +1,41 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "nxt_heroku_database_backup/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "nxt_heroku_database_backup"
7
+ spec.version = NxtHerokuDatabaseBackup::VERSION
8
+ spec.authors = ["Andreas Robecke"]
9
+ spec.email = ["a.robecke@getsafe.de"]
10
+
11
+ spec.summary = %q{Backup your heroku databases in the cloud}
12
+ spec.homepage = "https://www.getsafe.de"
13
+ spec.license = "MIT"
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://www.getsafe.de"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "aws-sdk-s3"
30
+ spec.add_dependency "nxt_init"
31
+ # spec.add_dependency "activesupport"
32
+
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
+ spec.add_development_dependency "pry"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ # spec.add_development_dependency "vcr"
38
+ # spec.add_development_dependency "webmock"
39
+ # spec.add_development_dependency "nxt_vcr_harness"
40
+ spec.add_development_dependency "dotenv"
41
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nxt_heroku_database_backup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andreas Robecke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-s3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nxt_init
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: dotenv
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - a.robecke@getsafe.de
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".env.test"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/nxt_heroku_database_backup.rb
130
+ - lib/nxt_heroku_database_backup/manager.rb
131
+ - lib/nxt_heroku_database_backup/version.rb
132
+ - nxt_heroku_database_backup.gemspec
133
+ homepage: https://www.getsafe.de
134
+ licenses:
135
+ - MIT
136
+ metadata:
137
+ allowed_push_host: https://rubygems.org
138
+ homepage_uri: https://www.getsafe.de
139
+ source_code_uri: https://www.getsafe.de
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubygems_version: 3.0.1
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Backup your heroku databases in the cloud
159
+ test_files: []