steamy 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/bin/steamy +10 -4
- data/lib/boot.rb +8 -0
- data/lib/steamy/app.rb +88 -0
- data/lib/steamy/sequel_pro.rb +10 -9
- data/lib/steamy/version.rb +1 -1
- data/lib/steamy.rb +12 -71
- metadata +32 -51
data/.gitignore
CHANGED
data/bin/steamy
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#/ Usage: steamy HOST DATABASE
|
3
3
|
#/
|
4
|
-
require '
|
4
|
+
require 'boot'
|
5
5
|
require 'optparse'
|
6
6
|
|
7
7
|
def usage
|
@@ -20,6 +20,12 @@ optparse = OptionParser.new do |opts|
|
|
20
20
|
exit 0
|
21
21
|
end
|
22
22
|
|
23
|
+
opts.on('-d', '--databases HOST') do |host|
|
24
|
+
instance = Steamy::App.new(host)
|
25
|
+
instance.available_databases
|
26
|
+
exit 0
|
27
|
+
end
|
28
|
+
|
23
29
|
opts.on('-h', '--help', 'Display help info') do
|
24
30
|
usage
|
25
31
|
exit 0
|
@@ -28,7 +34,7 @@ end
|
|
28
34
|
|
29
35
|
begin
|
30
36
|
optparse.parse!
|
31
|
-
|
37
|
+
|
32
38
|
# The url has no flag and will be in ARGV[0] if it's set
|
33
39
|
options[:host] = ARGV[0] || nil
|
34
40
|
options[:database] = ARGV[1] || nil
|
@@ -42,5 +48,5 @@ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
|
42
48
|
exit 1
|
43
49
|
end
|
44
50
|
|
45
|
-
|
46
|
-
|
51
|
+
instance = Steamy::App.new(options[:host], options[:database])
|
52
|
+
instance.dump
|
data/lib/boot.rb
ADDED
data/lib/steamy/app.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
module Steamy
|
2
|
+
class App
|
3
|
+
|
4
|
+
def initialize(host = nil, database = nil)
|
5
|
+
@host = host
|
6
|
+
@database = database
|
7
|
+
|
8
|
+
@user = ''
|
9
|
+
@password = ''
|
10
|
+
|
11
|
+
@sequel_pro = SequelPro.new()
|
12
|
+
@connections = @sequel_pro.connections
|
13
|
+
end
|
14
|
+
|
15
|
+
def dump
|
16
|
+
setup_connection
|
17
|
+
|
18
|
+
if @database.nil?
|
19
|
+
@database = get_database
|
20
|
+
end
|
21
|
+
|
22
|
+
timestamp = Time.now.strftime("%Y-%m-%d_%H%M%S")
|
23
|
+
name = "#{@host}_#{@database}_#{timestamp}.sql.gz"
|
24
|
+
remote_exec("'mysqldump #{@user} #{@password} #{@database} | gzip -c' > ~/Desktop/#{name}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_database
|
28
|
+
databases = show_databases.split("\n")
|
29
|
+
|
30
|
+
puts "Choose a database to dump:"
|
31
|
+
databases.each_with_index do |db, i|
|
32
|
+
puts i.to_s + ': ' + db
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get index from user
|
36
|
+
index = gets.to_i
|
37
|
+
databases[index]
|
38
|
+
end
|
39
|
+
|
40
|
+
def setup_connection
|
41
|
+
if @host.nil? || @connections[@host].nil?
|
42
|
+
if @host.nil?
|
43
|
+
puts "no host, available hosts:"
|
44
|
+
else
|
45
|
+
puts "no host #{@host}, available hosts:"
|
46
|
+
end
|
47
|
+
@sequel_pro.list
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
|
51
|
+
unless @connections[@host]['user'].empty?
|
52
|
+
@user = "-u #{@connections[@host]['user']}"
|
53
|
+
end
|
54
|
+
|
55
|
+
unless @connections[@host]['password'].empty?
|
56
|
+
@password = "-p\"#{@connections[@host]['password']}\""
|
57
|
+
end
|
58
|
+
|
59
|
+
@database = set_database(@host, @database)
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_database(host, database)
|
63
|
+
if host.nil? || @connections[@host]['database'].nil? || database
|
64
|
+
database = database
|
65
|
+
else
|
66
|
+
puts "This user can only access '#{@connections[@host]['database']}', update credentials to access other databases or specify database to dump."
|
67
|
+
exit 1
|
68
|
+
end
|
69
|
+
|
70
|
+
database
|
71
|
+
end
|
72
|
+
|
73
|
+
def show_databases
|
74
|
+
remote_exec(sprintf('\'mysql -e "show databases" %s %s\'', @user, @password))
|
75
|
+
end
|
76
|
+
|
77
|
+
def remote_exec(command)
|
78
|
+
command = "ssh #{@host} #{command}"
|
79
|
+
`#{command}`
|
80
|
+
end
|
81
|
+
|
82
|
+
def available_databases
|
83
|
+
setup_connection
|
84
|
+
puts show_databases
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
data/lib/steamy/sequel_pro.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'plist'
|
3
|
-
require 'pp'
|
4
2
|
|
5
3
|
module Steamy
|
6
4
|
class SequelPro
|
7
5
|
|
8
6
|
attr_reader :connections
|
9
7
|
|
10
|
-
def initialize
|
11
|
-
@settings = settings
|
8
|
+
def initialize
|
12
9
|
@connections = connections
|
13
10
|
end
|
14
11
|
|
15
12
|
def connections
|
16
13
|
connections = {}
|
17
14
|
|
18
|
-
Dir.chdir(
|
15
|
+
Dir.chdir(Steamy.config[:saved_connections])
|
19
16
|
|
20
17
|
# For each vhost replace the DOCUMENT_ROOT and write back out to sites-enabled
|
21
18
|
Dir.glob("*.spf") do |file|
|
22
19
|
connection = Plist::parse_xml(file)
|
23
|
-
|
20
|
+
unless connection['data']['connection']['ssh_host'].nil?
|
21
|
+
connections[connection['data']['connection']['ssh_host']] = connection['data']['connection']
|
22
|
+
end
|
24
23
|
end
|
25
24
|
|
26
25
|
connections
|
@@ -28,10 +27,12 @@ module Steamy
|
|
28
27
|
|
29
28
|
def available_connections
|
30
29
|
keys = @connections.keys
|
31
|
-
keys.reject! { |name| name.nil? }
|
32
30
|
keys.sort!
|
33
|
-
|
34
|
-
|
31
|
+
end
|
32
|
+
|
33
|
+
def list
|
34
|
+
available_connections.each do |connection|
|
35
|
+
puts connection
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
data/lib/steamy/version.rb
CHANGED
data/lib/steamy.rb
CHANGED
@@ -1,76 +1,17 @@
|
|
1
|
-
require "steamy/version"
|
2
|
-
require "steamy/config"
|
3
|
-
require "steamy/sequel_pro"
|
4
|
-
|
5
1
|
module Steamy
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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'].empty?) ? '' : "-u #{@connections[@host]['user']}"
|
25
|
-
@password = (@connections[@host]['password'].empty?) ? '' : "-p\"#{@connections[@host]['password']}\""
|
26
|
-
@database = set_database(host, database)
|
27
|
-
end
|
28
|
-
|
29
|
-
def set_database(host, database)
|
30
|
-
if host.nil? || @connections[@host]['database'].nil? || database
|
31
|
-
database = database
|
32
|
-
else
|
33
|
-
puts "This user can only access '#{@connections[@host]['database']}', update credentials to access other databases or specify database to dump."
|
34
|
-
exit 1
|
35
|
-
end
|
36
|
-
|
37
|
-
database
|
38
|
-
end
|
39
|
-
|
40
|
-
def remote_exec(command)
|
41
|
-
command = "#{@ssh} #{command}"
|
42
|
-
`#{command}`
|
43
|
-
end
|
44
|
-
|
45
|
-
def show_databases
|
46
|
-
remote_exec(sprintf('\'mysql -e "show databases" %s %s\'', @user, @password))
|
47
|
-
end
|
48
|
-
|
49
|
-
def list
|
50
|
-
@sequel_pro.available_connections
|
51
|
-
end
|
52
|
-
|
53
|
-
def get_database
|
54
|
-
databases = show_databases.split("\n")
|
55
|
-
|
56
|
-
puts "Choose a database to dump:"
|
57
|
-
databases.each_with_index do |db, i|
|
58
|
-
puts i.to_s + ': ' + db
|
59
|
-
end
|
2
|
+
|
3
|
+
def self.config
|
4
|
+
{
|
5
|
+
:saved_connections => File.expand_path(yaml[:saved_connections])
|
6
|
+
}
|
7
|
+
end
|
60
8
|
|
61
|
-
|
62
|
-
|
63
|
-
|
9
|
+
def self.yaml
|
10
|
+
if File.exist?("#{ENV['HOME']}/.steamy")
|
11
|
+
@yaml ||= YAML.load_file("#{ENV['HOME']}/.steamy")
|
12
|
+
else
|
13
|
+
{}
|
64
14
|
end
|
65
|
-
|
66
|
-
def mysqldump
|
67
|
-
if @database.nil?
|
68
|
-
@database = get_database
|
69
|
-
end
|
70
|
-
timestamp = Time.now.strftime("%Y-%m-%d_%H%M%S")
|
71
|
-
name = "#{@host}_#{@database}_#{timestamp}.sql.gz"
|
72
|
-
remote_exec("'mysqldump #{@user} #{@password} #{@database} | gzip -c' > ~/Desktop/#{name}")
|
73
|
-
end
|
74
|
-
|
75
15
|
end
|
16
|
+
|
76
17
|
end
|
metadata
CHANGED
@@ -1,88 +1,69 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: steamy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Ben Ubois
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: plist
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70262401977160 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70262401977160
|
34
25
|
description: steamy exports remote MySQL databases using SequelPro saved connections.
|
35
|
-
email:
|
26
|
+
email:
|
36
27
|
- ben@benubois.com
|
37
|
-
executables:
|
28
|
+
executables:
|
38
29
|
- steamy
|
39
30
|
extensions: []
|
40
|
-
|
41
31
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
32
|
+
files:
|
44
33
|
- .gitignore
|
45
34
|
- Gemfile
|
46
35
|
- README.md
|
47
36
|
- Rakefile
|
48
37
|
- bin/steamy
|
38
|
+
- lib/boot.rb
|
49
39
|
- lib/steamy.rb
|
40
|
+
- lib/steamy/app.rb
|
50
41
|
- lib/steamy/config.rb
|
51
42
|
- lib/steamy/sequel_pro.rb
|
52
43
|
- lib/steamy/version.rb
|
53
44
|
- steamy.gemspec
|
54
|
-
homepage:
|
45
|
+
homepage: ''
|
55
46
|
licenses: []
|
56
|
-
|
57
47
|
post_install_message:
|
58
48
|
rdoc_options: []
|
59
|
-
|
60
|
-
require_paths:
|
49
|
+
require_paths:
|
61
50
|
- lib
|
62
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
52
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
|
68
|
-
|
69
|
-
- 0
|
70
|
-
version: "0"
|
71
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
58
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
version: "0"
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
80
63
|
requirements: []
|
81
|
-
|
82
64
|
rubyforge_project: steamy
|
83
|
-
rubygems_version: 1.8.
|
65
|
+
rubygems_version: 1.8.11
|
84
66
|
signing_key:
|
85
67
|
specification_version: 3
|
86
68
|
summary: Export remote MySQL Databases
|
87
69
|
test_files: []
|
88
|
-
|