filbert 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in filbert.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tadas Tamosauskas
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.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # Filbert
2
+
3
+ Filbert downloads a backup of a follower database for a given heroku application and stores it in `~/.heroku_backups`
4
+
5
+ ## Installation
6
+
7
+ gem install filbert
8
+
9
+ And reload your path (e.g. `rbenv rehash`). Then run
10
+
11
+
12
+ ## Usage
13
+
14
+ filbert backup --app your-heroku-appname
15
+
16
+ ## Contributing
17
+
18
+ 1. Fork it
19
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
20
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
21
+ 4. Push to the branch (`git push origin my-new-feature`)
22
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/filbert ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/filbert.rb'
3
+
4
+ Filbert::Task.start
data/filbert.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'filbert/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "filbert"
8
+ gem.version = Filbert::VERSION
9
+ gem.authors = ["Tadas Tamosauskas"]
10
+ gem.email = ["tadas@pdfcv.com", "tech@alphasights.com"]
11
+ gem.description = "A utility to download backups from Heroku followers"
12
+ gem.summary = "Heroku followers' backups"
13
+ gem.homepage = "https://github.com/alphasights/filbert"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency('heroku')
20
+ gem.add_dependency('thor')
21
+ end
@@ -0,0 +1,60 @@
1
+ module Filbert
2
+ class Task < Thor
3
+ include Thor::Actions
4
+ class_option :app, type: :string, required: true
5
+
6
+ method_options :real_emails => false
7
+ desc "backup", "capture and pull latest production snapshot and migrate local database"
8
+ def backup
9
+ say "Looking for the follower DB..."
10
+ db_name = run!("heroku pg:info --app #{options[:app]} | grep Followers | awk '/:(.)*/ { print $2 }'").strip
11
+ say "Found the follower: #{db_name}. Capturing..."
12
+ backup_id = run!("heroku pgbackups:capture #{db_name} --expire --app #{options[:app]} | grep backup | awk '/--->/ { print $3}'").strip
13
+ say "Backup id: #{backup_id}"
14
+ say "Fetching backup S3 URL"
15
+ backup_url = run!("heroku pgbackups:url #{backup_id} --app #{options[:app]} ").strip.gsub("\"", "")
16
+ say "Downloading #{backup_url}"
17
+ get backup_url, file_path
18
+ say file_path
19
+ invoke :cleanup
20
+ end
21
+
22
+ desc "cleanup", "remove backup files older than 24 hours"
23
+ def cleanup
24
+ old_files.each do |file|
25
+ say "Deleting old #{File.basename(file.path)}"
26
+ File.delete file.path
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def run!(cmd)
33
+ out = `#{cmd}`
34
+ unless $?.success?
35
+ say "Command exited with status #{$?.to_i}. Exiting.", :red
36
+ exit! $?.exitstatus
37
+ end
38
+ out
39
+ end
40
+
41
+ def old_files
42
+ hurdle = Time.now - 60*60*12
43
+ Dir.new(backups_dir).select{ |x|
44
+ x.end_with? '.dump'
45
+ }.map { |filename|
46
+ file = File.new(File.join(backups_dir, filename))
47
+ }.select{ |file|
48
+ file.mtime < hurdle
49
+ }
50
+ end
51
+
52
+ def file_path
53
+ @filename ||= File.join(backups_dir, "#{options[:app]}_#{Time.now.strftime("%Y-%m-%d_%H-%M-%L")}.dump")
54
+ end
55
+
56
+ def backups_dir
57
+ File.join(Dir.home, '.heroku_backups')
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Filbert
2
+ VERSION = '0.0.1'
3
+ end
data/lib/filbert.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'tmpdir'
2
+ require 'thor'
3
+ require 'filbert/task'
4
+
5
+ module Filbert
6
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filbert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tadas Tamosauskas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: heroku
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: thor
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A utility to download backups from Heroku followers
47
+ email:
48
+ - tadas@pdfcv.com
49
+ - tech@alphasights.com
50
+ executables:
51
+ - filbert
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bin/filbert
61
+ - filbert.gemspec
62
+ - lib/filbert.rb
63
+ - lib/filbert/task.rb
64
+ - lib/filbert/version.rb
65
+ homepage: https://github.com/alphasights/filbert
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.23
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Heroku followers' backups
89
+ test_files: []