safety_net_heroku 1.0.1 → 1.0.5

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: 3d980c0aecf55ecccff0fe9699cadb2df3fa403923c68509fea4b0b4294ff847
4
- data.tar.gz: 17bed72bc17641f432ec2f70e87f4b614674ba734000a51c46b4705472673183
3
+ metadata.gz: 1312b6b0a31d1046385a10c9a6ba536638472b6ad37725cf1e560e89ebcc113d
4
+ data.tar.gz: c5a49805d9da1aeb680952f92a33fbf6ba8e03b5633152e76d43477cfb5ff751
5
5
  SHA512:
6
- metadata.gz: aee358e251a00bfb6372333ca5a71f3687ecb803ca431100b4da5c7636711c04bf214247b9a8a887485b981a6610963fb993e253a5c43c01967f81d3844b5ab1
7
- data.tar.gz: 47a8567c08419e1f8779c76cae1bd1267052659c42d8511fc1676add7bc0a13843c2e2af06a6aec9c22e1f5f7dfdd11965c67fa50f72c1d4f9174eb69a84b467
6
+ metadata.gz: 06b6525b1b815d03495ddf135040d4df329f2def92010ccc711c10e0b3d61a65b47726c4b5683fce9587ddfc3fffa50a022a4cd0cc5b3d0986cdf3ff347c0006
7
+ data.tar.gz: 118c9bf3b9a2f7aa2910a02d59dd220ded450333ab673f104962f07c7ab5a6d439030f909d2315cb8a53f9b5ebe6027b40d9cdb59bfa295508ec5000d7742726
@@ -1,5 +1,5 @@
1
1
  require "safety_net_heroku/version"
2
- #require "safety_net_heroku/backup_database_worker"
2
+ require "safety_net_heroku/backup_database_worker"
3
3
 
4
4
  module SafetyNetHeroku
5
5
  def self.config
@@ -0,0 +1,48 @@
1
+ require 'sidekiq/web'
2
+
3
+ module SafetyNetHeroku
4
+ class BackupDatabaseWorker
5
+ include Sidekiq::Worker
6
+
7
+ sidekiq_options retry: false
8
+
9
+ def perform
10
+
11
+ database_name = SafetyNetHeroku.config[:database_name]
12
+ region = SafetyNetHeroku.config[:aws_region]
13
+ bucket = SafetyNetHeroku.config[:aws_bucket]
14
+ backups_directory = SafetyNetHeroku.config[:aws_backups_directory]
15
+
16
+ if database_name.nil?
17
+ raise Exception.new 'SafetyNetHeroku.config[:database_name] not set'
18
+ end
19
+
20
+ if region.nil?
21
+ raise Exception.new 'SafetyNetHeroku.config[:aws_region] not set'
22
+ end
23
+
24
+ if bucket.nil?
25
+ raise Exception.new 'SafetyNetHeroku.config[:aws_bucket] not set'
26
+ end
27
+
28
+ if backups_directory.nil?
29
+ raise Exception.new 'SafetyNetHeroku.config[:aws_backups_directory] not set'
30
+ end
31
+
32
+ temp_backups_root_directory = "#{Rails.root}/safety_net_heroku"
33
+ temp_backups_directory = "#{temp_backups_root_directory}/database-backups"
34
+ system("mongodump --uri=#{ENV['DB_URI_NO_OPTIONS']} --out=\"#{temp_backups_directory}\"")
35
+
36
+ output_file_name = "#{Time.now.to_formatted_s(:long_ordinal).gsub(" ", "-").gsub(",", "")}.zip"
37
+ output_path = "#{temp_backups_directory}/#{output_file_name}"
38
+ system("zip -rj \"#{output_path}\" \"#{temp_backups_directory}/#{database_name}\"")
39
+
40
+ s3 = Aws::S3::Resource.new(region: region)
41
+ obj = s3.bucket(bucket).object("#{backups_directory}/#{output_file_name}")
42
+ obj.upload_file(output_path)
43
+
44
+ system("rm -r \"#{temp_backups_root_directory}\"")
45
+ end
46
+
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module SafetyNetHeroku
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.5"
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.1
4
+ version: 1.0.5
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: 2021-08-16 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,39 +0,0 @@
1
- # SafetyNetHeroku
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/safety_net_heroku`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'safety_net_heroku'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install safety_net_heroku
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. 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]/safety_net_heroku.
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 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