safety_net_heroku 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61ea92054c7f625dec2e0f52ecf7fd4b97d6be5cbd6c650f3ff70ddc3459bb26
4
- data.tar.gz: c398babb2a018616c9be475ae031716aa23b9fe182fe604181f385c83d5df992
3
+ metadata.gz: 92867d79fcb84288473868ec49974269001515f4db46f3a803a3d17f26fa1726
4
+ data.tar.gz: ce4a289cda6ef8a72afe06047beb653d77c5f168f16cdd7df677a338ecfeb4dd
5
5
  SHA512:
6
- metadata.gz: c0d9217b6f230c22f1a312875421ed72ccfcb9f577938ce29277e65a129d454a8eba12cc13c233c357c336d377d5fce8536bc9c683905fc3904c85960b5cdc68
7
- data.tar.gz: cb33a4bcf2283881a9b36b6f6abb58208d7ab7a6ac1a0c1a12b575152a8e1370b440bfdea4f1ee6bebd73ae2ef9a7a86e6ce0497b483ae4e82e067cb5b41ab92
6
+ metadata.gz: 694f807e2f328893f9f77cb5f0539db878cab61db65e84c66b291e2b87f58db3dacdcafab73ba88d635cf01f057d1920c830ebdf2df36cd1e8069327437f0068
7
+ data.tar.gz: 2037980744291b1f10b6f56ea44dab3cffb7a1c2c107817392467b5494115c3ee5b36b41093db1ffcefef23d093353374cc3593ac2a813fc0b4d263afd48eb77
@@ -0,0 +1,46 @@
1
+ module SafetyNetHeroku
2
+ class BackupDatabaseWorker
3
+ include Sidekiq::Worker
4
+
5
+ sidekiq_options retry: false
6
+
7
+ def perform
8
+
9
+ database_name = SafetyNetHeroku.config[:database_name]
10
+ region = SafetyNetHeroku.config[:aws_region]
11
+ bucket = SafetyNetHeroku.config[:aws_bucket]
12
+ backups_directory = SafetyNetHeroku.config[:aws_backups_directory]
13
+
14
+ if database_name.nil?
15
+ raise Exception.new 'SafetyNetHeroku.config[:database_name] not set'
16
+ end
17
+
18
+ if region.nil?
19
+ raise Exception.new 'SafetyNetHeroku.config[:aws_region] not set'
20
+ end
21
+
22
+ if bucket.nil?
23
+ raise Exception.new 'SafetyNetHeroku.config[:aws_bucket] not set'
24
+ end
25
+
26
+ if backups_directory.nil?
27
+ raise Exception.new 'SafetyNetHeroku.config[:aws_backups_directory] not set'
28
+ end
29
+
30
+ temp_backups_root_directory = "#{Rails.root}/safety_net_heroku"
31
+ temp_backups_directory = "#{temp_backups_root_directory}/database-backups"
32
+ system("mongodump --uri=#{ENV['DB_URI_NO_OPTIONS']} --out=\"#{temp_backups_directory}\"")
33
+
34
+ output_file_name = "#{Time.now.to_formatted_s(:long_ordinal).gsub(" ", "-").gsub(",", "")}.zip"
35
+ output_path = "#{temp_backups_directory}/#{output_file_name}"
36
+ system("zip -rj \"#{output_path}\" \"#{temp_backups_directory}/#{database_name}\"")
37
+
38
+ s3 = Aws::S3::Resource.new(region: region)
39
+ obj = s3.bucket(bucket).object("#{backups_directory}/#{output_file_name}")
40
+ obj.upload_file(output_path)
41
+
42
+ system("rm -r \"#{temp_backups_root_directory}\"")
43
+ end
44
+
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module SafetyNetHeroku
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - daltron
@@ -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