steamy 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in steamy.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ steamy
2
+ ======
3
+
4
+ steamy, export remote MySQL Databases
5
+
6
+ Why
7
+ ---
8
+
9
+ steamy has several advantages over mysqldump (and many disadvantages).
10
+
11
+ The main goal of steamy is to make it easy to backup remote MySQL databases. steamy makes database backups fast by relying on SequelPro Saved connections, SSH public keys to the MySQL server your trying to backup from and by running gzip on the sql dump before downloading it to your local machine.
12
+
13
+ This means that steamy has several requirements.
14
+
15
+ 1. You must have a SequelPro saved connection.
16
+ 2. You must have password-less SSH to the remote server using public keys.
17
+ 3. You must have mysqldump and gzip installed on the remote server.
18
+
19
+ Usage
20
+ -----
21
+
22
+ Install by running
23
+
24
+ $ gem install steamy
25
+
26
+ steamy will look for a YAML file located in ~/.steamy which specifies the SequelPro saved connections directory.
27
+
28
+ The format of the file should look like:
29
+
30
+ ---
31
+ :saved_connections: /path/to/db
32
+
33
+ The path supports path expansion so something like `~/Databases` would work too.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/steamy ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ #/ Usage: steamy HOST DATABASE
3
+ #/
4
+ require 'steamy'
5
+ require 'optparse'
6
+
7
+ def usage
8
+ puts File.readlines(__FILE__).
9
+ grep(/^#\/.*/).
10
+ map { |line| line.chomp[3..-1] }.
11
+ join("\n")
12
+ end
13
+
14
+ options = {}
15
+
16
+ optparse = OptionParser.new do |opts|
17
+
18
+ opts.on('-v', '--version') do
19
+ puts Steamy::VERSION
20
+ exit 0
21
+ end
22
+
23
+ opts.on('-h', '--help', 'Display help info') do
24
+ usage
25
+ exit 0
26
+ end
27
+ end
28
+
29
+ begin
30
+ optparse.parse!
31
+
32
+ # The url has no flag and will be in ARGV[0] if it's set
33
+ options[:host] = ARGV[0] || nil
34
+ options[:database] = ARGV[1] || nil
35
+
36
+ # Reset ARGV for gets later
37
+ ARGV.clear
38
+
39
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
40
+ puts $!.to_s
41
+ usage
42
+ exit 1
43
+ end
44
+
45
+ preview = Steamy::Steamy.new(options[:host], options[:database])
46
+ preview.mysqldump
@@ -0,0 +1,20 @@
1
+ require 'yaml'
2
+
3
+ module Steamy
4
+
5
+ class Config
6
+
7
+ FILE = "#{ENV['HOME']}/.steamy"
8
+
9
+ def self.config
10
+ if File.exist?(FILE)
11
+ YAML.load_file(FILE)
12
+ else
13
+ puts "Please create a config file in #{ENV['HOME']}/.steamy"
14
+ exit 1
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'plist'
3
+ require 'pp'
4
+
5
+ module Steamy
6
+ class SequelPro
7
+
8
+ attr_reader :connections
9
+
10
+ def initialize(settings)
11
+ @settings = settings
12
+ @connections = connections
13
+ end
14
+
15
+ def connections
16
+ connections = {}
17
+
18
+ Dir.chdir(@settings[:saved_connections])
19
+
20
+ # For each vhost replace the DOCUMENT_ROOT and write back out to sites-enabled
21
+ Dir.glob("*.spf") do |file|
22
+ connection = Plist::parse_xml(file)
23
+ connections[connection['data']['connection']['ssh_host']] = connection['data']['connection']
24
+ end
25
+
26
+ connections
27
+ end
28
+
29
+ def available_connections
30
+ keys = @connections.keys
31
+ keys.reject! { |name| name.nil? }
32
+ keys.sort!
33
+ keys.each do |name|
34
+ puts name
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Steamy
2
+ VERSION = "0.0.2"
3
+ end
data/lib/steamy.rb ADDED
@@ -0,0 +1,65 @@
1
+ require "steamy/version"
2
+ require "steamy/config"
3
+ require "steamy/sequel_pro"
4
+
5
+ module Steamy
6
+ class Steamy
7
+
8
+ def initialize(host = nil, database = nil)
9
+
10
+ @settings = Config.config
11
+ @settings[:saved_connections] = File.expand_path(@settings[:saved_connections])
12
+ @host = host
13
+
14
+ @sequel_pro = SequelPro.new(@settings)
15
+ @connections = @sequel_pro.connections
16
+
17
+ if @host.nil? || @connections[@host].nil?
18
+ puts "no host #{@host}, available hosts:"
19
+ list
20
+ exit 1
21
+ end
22
+
23
+ @ssh = "ssh #{@host}"
24
+ @user = (@connections[@host]['user'].nil?) ? '' : "-u #{@connections[@host]['user']}"
25
+ @password = (@connections[@host]['password'].nil?) ? '' : "-p\"#{@connections[@host]['password']}\""
26
+ @database = database
27
+ end
28
+
29
+ def remote_exec(command)
30
+ command = "#{@ssh} #{command}"
31
+ `#{command}`
32
+ end
33
+
34
+ def show_databases
35
+ remote_exec(sprintf('\'mysql -e "show databases" %s %s\'', @user, @password))
36
+ end
37
+
38
+ def list
39
+ @sequel_pro.available_connections
40
+ end
41
+
42
+ def get_database
43
+ databases = show_databases.split("\n")
44
+
45
+ puts "Choose a database to dump:"
46
+ databases.each_with_index do |db, i|
47
+ puts i.to_s + ': ' + db
48
+ end
49
+
50
+ # Get index from user
51
+ index = gets.to_i
52
+ databases[index]
53
+ end
54
+
55
+ def mysqldump
56
+ if @database.nil?
57
+ @database = get_database
58
+ end
59
+ timestamp = Time.now.strftime("%Y-%m-%d_%H%M%S")
60
+ name = "#{@host}_#{@database}_#{timestamp}.sql.gz"
61
+ remote_exec("'mysqldump #{@user} #{@password} #{@database} | gzip -c' > ~/Desktop/#{name}")
62
+ end
63
+
64
+ end
65
+ end
data/steamy.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "steamy/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "steamy"
7
+ s.version = Steamy::VERSION
8
+ s.authors = ["Ben Ubois"]
9
+ s.email = ["ben@benubois.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Export remote MySQL Databases}
12
+ s.description = %q{steamy exports remote MySQL databases using SequelPro saved connections.}
13
+
14
+ s.rubyforge_project = "steamy"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "plist"
22
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steamy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Ben Ubois
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-22 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: plist
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: steamy exports remote MySQL databases using SequelPro saved connections.
35
+ email:
36
+ - ben@benubois.com
37
+ executables:
38
+ - steamy
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - README.md
47
+ - Rakefile
48
+ - bin/steamy
49
+ - lib/steamy.rb
50
+ - lib/steamy/config.rb
51
+ - lib/steamy/sequel_pro.rb
52
+ - lib/steamy/version.rb
53
+ - steamy.gemspec
54
+ homepage: ""
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project: steamy
83
+ rubygems_version: 1.8.6
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Export remote MySQL Databases
87
+ test_files: []
88
+