heroku_multi_backup 0.0.2 → 0.0.5

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
  SHA1:
3
- metadata.gz: 20f93b62414780ca97722ea26b9159811aa98187
4
- data.tar.gz: 27697bb41fb1b40158fdf6a864e44ddb40074fb8
3
+ metadata.gz: 07bcb1160672fdb4f88b5808c5de21ebcf7eaa90
4
+ data.tar.gz: 5725d256c3b0bff497186983e272f3eedb2a0d17
5
5
  SHA512:
6
- metadata.gz: db1d30fb1ddbad8b0be7c0e18c81c62b7d2fd830e35c7e0fdce961ce69e0aec985cc297f8fe0eadf676b3d45c18dc9f11168124f2dbe2ed90a558337d37d6110
7
- data.tar.gz: 93d9d58063e519dce1622901efcd4e6c3bed89c732955d4e26f5a419398cae263254cbec439598d748b5cde9af9cdeec0cb08e16af8cc28575b3c27db3e3fece
6
+ metadata.gz: 4c60957556be84d2ec711765e9aef4a8a0335644928d04b110cbfced5cf4236564dbba28b6210c7bcff69af1cb3b240c171b9f465639401aa5edd88aca9eb6de
7
+ data.tar.gz: 4a2d60b9982a020a2085a8b8d160ae63498eaa6c148fabfb8423d19dda0cc6005ba32c0dcfb285ea3e6025657774bb0e468e710fc928070d95cd5fe6b20c5fc5
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env rake
2
2
 
3
3
  require "bundler/gem_tasks"
4
- load "tasks/autobackup.rake"
4
+ require 'rake'
5
+ load "lib/tasks/heroku_multi_backup_autobackup.rake"
data/lib/Autobackup.rb ADDED
@@ -0,0 +1,112 @@
1
+ require "heroku/command/pg"
2
+ require "heroku/command/pg_backups"
3
+ require "heroku/api"
4
+ require "tmpdir"
5
+ require 'aws-sdk'
6
+
7
+
8
+
9
+ class Autobackup
10
+ attr_reader :client
11
+ attr_accessor :backup_url, :created_at
12
+ def self.call
13
+ new.call
14
+ end
15
+
16
+
17
+ def initialize(attrs={})
18
+ Heroku::Command.load
19
+ Heroku::Auth.credentials = [ ENV['HEROKU_USERNAME'], ENV['HEROKU_API_KEY'] ]
20
+
21
+
22
+ end
23
+
24
+ def call
25
+ # initialize the heroku client interface
26
+ ENV['APPNAME'].split(",").each do |app|
27
+ execute_backup(app)
28
+ end
29
+ end
30
+
31
+ def execute_backup(appname)
32
+ puts "================================="
33
+ puts "Starting back up for "+appname
34
+
35
+ @client = Heroku::Command::Pg.new([], :app =>appname)
36
+ # database is standard database_url but is configurable in case the app has multiple DBs
37
+ begin
38
+ attachment = client.send(:generate_resolver).resolve(database)
39
+
40
+ # Actual backup interface to heroku
41
+ backup = client.send(:hpg_client, attachment).backups_capture
42
+ client.send(:poll_transfer, "backup", backup[:uuid])
43
+ puts "Backup complete ..."
44
+ # get the public url of the backup file for uploading to S3
45
+ self.backup_url = Heroku::Client::HerokuPostgresqlApp
46
+ .new(appname).transfers_public_url(backup[:num])[:url]
47
+ download_file(appname)
48
+
49
+ puts "Back up for "+ appname + " complete"
50
+ puts "================================="
51
+ rescue
52
+ puts "The application "+ appname + "is not accessible to you"
53
+ end
54
+
55
+ end
56
+
57
+ def download_file(dbname)
58
+ puts "Downloading file in local system"
59
+ # download the file from heroku and save it into a temp file
60
+ File.open(temp_file, "wb") do |output|
61
+ streamer = lambda do |chunk, remaining_bytes, total_bytes|
62
+ output.write chunk
63
+ end
64
+
65
+ # https://github.com/excon/excon/issues/475
66
+ Excon.get backup_url,
67
+ :response_block => streamer,
68
+ :omit_default_port => true
69
+ end
70
+ # initiate upload to S3
71
+ puts "Download complete..."
72
+ upload_file(temp_file,dbname)
73
+ end
74
+
75
+
76
+ def upload_file(filepath,dbname)
77
+ # code for actual s3 upload
78
+ puts "Uploading file in S3..."
79
+ Aws.config.update({
80
+ region: 'ap-southeast-1',
81
+ credentials: Aws::Credentials.new(ENV['S3_ACCESS_ID'],ENV['S3_ACCESS_SECRET'])
82
+
83
+ })
84
+ s3 = Aws::S3::Resource.new(region:ENV['S3_REGION'])
85
+ obj = s3.bucket(ENV['S3_BUCKET']).object(generate_file_name(dbname))
86
+ obj.upload_file(filepath)
87
+ puts "Upload Complete"
88
+ end
89
+
90
+
91
+
92
+ private
93
+ def database
94
+ "DATABASE_URL"
95
+ end
96
+
97
+ def temp_file
98
+ "#{Dir.tmpdir}/pgbackup"
99
+ end
100
+ def current_timestamp
101
+ Time.now.getutc.to_i
102
+ end
103
+ def current_time
104
+ Time.now.getutc.to_s
105
+ end
106
+
107
+ def generate_file_name(dbname)
108
+ 'backup_for_'+dbname+"_"+current_timestamp.to_s+"("+current_time+")"
109
+
110
+ end
111
+
112
+ end
@@ -2,4 +2,5 @@ require "heroku_multi_backup/version"
2
2
 
3
3
  module HerokuMultiBackup
4
4
  require 'Autobackup'
5
+ require 'railtie'
5
6
  end
@@ -1,3 +1,3 @@
1
1
  module HerokuMultiBackup
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/railtie.rb ADDED
@@ -0,0 +1,13 @@
1
+ if defined?(Rails)
2
+ if Rails.version < "3"
3
+ load "tasks/heroku_multi_backup_autobackup.rake"
4
+ else
5
+ module HerokuMultiBackup
6
+ class Railtie < Rails::Railtie
7
+ rake_tasks do
8
+ load "tasks/heroku_multi_backup_autobackup.rake"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ namespace :heroku_multi_backup do
2
+ desc 'Description for rake task'
3
+
4
+ task :autobackup do
5
+ Autobackup.call
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_multi_backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Dark Lord
@@ -14,30 +14,30 @@ dependencies:
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
33
+ version: '0'
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pg
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +45,7 @@ dependencies:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :development
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
@@ -94,14 +94,13 @@ executables: []
94
94
  extensions: []
95
95
  extra_rdoc_files: []
96
96
  files:
97
- - ".gitignore"
98
- - Gemfile
99
- - LICENSE.txt
100
97
  - README.md
101
98
  - Rakefile
102
- - heroku_multi_backup.gemspec
99
+ - lib/Autobackup.rb
103
100
  - lib/heroku_multi_backup.rb
104
101
  - lib/heroku_multi_backup/version.rb
102
+ - lib/railtie.rb
103
+ - lib/tasks/heroku_multi_backup_autobackup.rake
105
104
  homepage: ''
106
105
  licenses:
107
106
  - MIT
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in heroku_multi_backup.gemspec
4
- gemspec
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2015 The Dark Lord
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,28 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'heroku_multi_backup/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "heroku_multi_backup"
8
- spec.version = HerokuMultiBackup::VERSION
9
- spec.authors = ["The Dark Lord"]
10
- spec.email = ["contactme@rushabhhathi.com"]
11
- spec.summary = %q{A Gem to create backups of multiple heroku apps and upload it to the specified Amazon S3 bucket.}
12
- spec.description = %q{A Gem to create backups of multiple heroku apps and upload it to the specified Amazon S3 bucket.}
13
- spec.homepage = ""
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "pg"
24
- spec.add_runtime_dependency "heroku", ">= 3.28.6", "<= 3.32"
25
- spec.add_runtime_dependency "aws-sdk", '~> 2'
26
-
27
-
28
- end