safety_net_heroku 1.0.3 → 1.0.6

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: 61ea92054c7f625dec2e0f52ecf7fd4b97d6be5cbd6c650f3ff70ddc3459bb26
4
- data.tar.gz: c398babb2a018616c9be475ae031716aa23b9fe182fe604181f385c83d5df992
3
+ metadata.gz: 5530aea2e47137225318c22f28087bf855e1c4bff977a736c9a6a5110b57e24a
4
+ data.tar.gz: 19639afeb0d0bedf60cec2c3c00098325ce585ae25bbb9ccaeaa5e0baf8e9073
5
5
  SHA512:
6
- metadata.gz: c0d9217b6f230c22f1a312875421ed72ccfcb9f577938ce29277e65a129d454a8eba12cc13c233c357c336d377d5fce8536bc9c683905fc3904c85960b5cdc68
7
- data.tar.gz: cb33a4bcf2283881a9b36b6f6abb58208d7ab7a6ac1a0c1a12b575152a8e1370b440bfdea4f1ee6bebd73ae2ef9a7a86e6ce0497b483ae4e82e067cb5b41ab92
6
+ metadata.gz: '01329812b6d1476d89c7c6061d23db42356dd128528a3318146a0b8d53fed6816f508c1aaabe095aee71d9864cbdf278dbc2153e88b6744e40e0ddfb7cdd6d0d'
7
+ data.tar.gz: b6029dcd77e1f7e4419f22309e3ad7d00d8ae789208452f4ef9c0dd672d8a817ac758a527bfed975015bc2aa62a6c7b10e6ac9b66a4f208b5b4b9797e2be3af5
@@ -0,0 +1,49 @@
1
+ require 'sidekiq/web'
2
+ require 'aws-sdk-s3'
3
+
4
+ module SafetyNetHeroku
5
+ class BackupDatabaseWorker
6
+ include Sidekiq::Worker
7
+
8
+ sidekiq_options retry: false
9
+
10
+ def perform
11
+
12
+ database_name = SafetyNetHeroku.config[:database_name]
13
+ region = SafetyNetHeroku.config[:aws_region]
14
+ bucket = SafetyNetHeroku.config[:aws_bucket]
15
+ backups_directory = SafetyNetHeroku.config[:aws_backups_directory]
16
+
17
+ if database_name.nil?
18
+ raise Exception.new 'SafetyNetHeroku.config[:database_name] not set'
19
+ end
20
+
21
+ if region.nil?
22
+ raise Exception.new 'SafetyNetHeroku.config[:aws_region] not set'
23
+ end
24
+
25
+ if bucket.nil?
26
+ raise Exception.new 'SafetyNetHeroku.config[:aws_bucket] not set'
27
+ end
28
+
29
+ if backups_directory.nil?
30
+ raise Exception.new 'SafetyNetHeroku.config[:aws_backups_directory] not set'
31
+ end
32
+
33
+ temp_backups_root_directory = "#{Rails.root}/safety_net_heroku"
34
+ temp_backups_directory = "#{temp_backups_root_directory}/database-backups"
35
+ system("mongodump --uri=#{ENV['DB_URI_NO_OPTIONS']} --out=\"#{temp_backups_directory}\"")
36
+
37
+ output_file_name = "#{Time.now.to_formatted_s(:long_ordinal).gsub(" ", "-").gsub(",", "")}.zip"
38
+ output_path = "#{temp_backups_directory}/#{output_file_name}"
39
+ system("zip -rj \"#{output_path}\" \"#{temp_backups_directory}/#{database_name}\"")
40
+
41
+ s3 = Aws::S3::Resource.new(region: region)
42
+ obj = s3.bucket(bucket).object("#{backups_directory}/#{output_file_name}")
43
+ obj.upload_file(output_path)
44
+
45
+ system("rm -r \"#{temp_backups_root_directory}\"")
46
+ end
47
+
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module SafetyNetHeroku
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safety_net_heroku
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - daltron
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-19 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,16 +73,9 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".gitignore"
77
- - Gemfile
78
- - LICENSE.txt
79
- - README.md
80
- - Rakefile
81
- - bin/console
82
- - bin/setup
83
76
  - lib/safety_net_heroku.rb
77
+ - lib/safety_net_heroku/backup_database_worker.rb
84
78
  - lib/safety_net_heroku/version.rb
85
- - safety_net_heroku.gemspec
86
79
  homepage: https://github.com/daltron/safety_net_heroku
87
80
  licenses:
88
81
  - MIT
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in safety_net_heroku.gemspec
6
- gemspec
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2021 daltron
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 DELETED
@@ -1,50 +0,0 @@
1
- A simple gem for backing up a MongoDB database to AWS when hosted on Heroku using a Sidekiq worker.
2
-
3
- ## Installation
4
-
5
- ```ruby
6
- gem 'safety_net_heroku'
7
- ```
8
-
9
- ## Usage
10
-
11
- Create a new Safety Net Heroku initializer:
12
-
13
- ```ruby
14
- # safety_net_heroku.rb
15
-
16
- require 'safety_net_heroku'
17
-
18
- SafetyNetHeroku.config[:database_name] = 'database_name'
19
- SafetyNetHeroku.config[:aws_region] = 's3_region'
20
- SafetyNetHeroku.config[:aws_bucket] = 's3_bucket'
21
- SafetyNetHeroku.config[:aws_backups_directory] = s3_directory'
22
-
23
- ```
24
-
25
- In your sidekiq initializer, import the Sidekiq worker:
26
-
27
- ```ruby
28
- # sidekiq.rb
29
-
30
- require 'safety_net_heroku'
31
- ```
32
- Add the worker to your sidekiq schedule as a cron job:
33
-
34
- ```ruby
35
- # sidekiq_schedule.yml
36
-
37
- backup_database:
38
- cron: "0 3 * * *"
39
- class: "SafetyNetHeroku::BackupDatabaseWorker"
40
- ```
41
-
42
- #### Your database will now be backed up to the AWS directory specified periodically based on your cron settings! 🎉
43
-
44
- ## Author
45
-
46
- Dalton Hinterscher, daltonhint4@gmail.com
47
-
48
- ## License
49
-
50
- Safety Net Heroku is available under the MIT license. See the LICENSE file for more info.
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "safety_net_heroku"
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 DELETED
@@ -1,8 +0,0 @@
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
@@ -1,39 +0,0 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "safety_net_heroku/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "safety_net_heroku"
8
- spec.version = SafetyNetHeroku::VERSION
9
- spec.authors = ["daltron"]
10
- spec.email = ["daltonhint4@gmail.com"]
11
-
12
- spec.summary = "A simple gem for backing up a MongoDB database to AWS when hosted on Heroku using a Sidekiq worker."
13
- spec.homepage = "https://github.com/daltron/safety_net_heroku"
14
- spec.license = "MIT"
15
-
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = spec.homepage
21
- else
22
- raise "RubyGems 2.0 or newer is required to protect against " \
23
- "public gem pushes."
24
- end
25
-
26
- # Specify which files should be added to the gem when it is released.
27
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
- end
31
- spec.bindir = "exe"
32
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
- spec.require_paths = ["lib"]
34
-
35
- spec.add_development_dependency "bundler", "~> 1.17"
36
- spec.add_development_dependency "rake", "~> 10.0"
37
- spec.add_dependency 'aws-sdk-s3', '~> 1.48.0'
38
- spec.add_dependency 'sidekiq', '~> 6.1.1'
39
- end