snatchdb 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/snatch CHANGED
@@ -11,6 +11,7 @@ require 'snatch'
11
11
  SAMPLE_SCHEMA = <<END
12
12
  ---
13
13
  host: YOUR_HOSTNAME
14
+ port: 22
14
15
  user: YOUR_SSH_USER
15
16
  password: YOUR_SSH_PASSWORD
16
17
  db_user: MYSQL_USER
@@ -44,9 +45,15 @@ begin
44
45
  optparse.parse!
45
46
 
46
47
  unless ARGV.empty?
47
- file = File.expand_path(ARGV.shift)
48
+ filename = ARGV.shift.strip
49
+ if File.extname(filename).empty?
50
+ file = File.join(Snatch.root, "#{filename}.yml")
51
+ else
52
+ file = File.expand_path(filename)
53
+ end
54
+
48
55
  unless File.exists?(file)
49
- puts "File #{file} was not found!"
56
+ puts "File \"#{file}\" was not found!"
50
57
  exit
51
58
  end
52
59
 
@@ -7,6 +7,7 @@ module Snatch
7
7
 
8
8
  def initialize(config)
9
9
  @config = config
10
+ @config[:port] = config[:port] || 22
10
11
  @ssh = nil
11
12
  @filename = "#{@config[:host]}_#{Time.now.strftime("%Y%m%d%H%M%S")}.sql.gz"
12
13
  end
@@ -26,7 +27,7 @@ module Snatch
26
27
  def connect
27
28
  puts "ssh: connecting..."
28
29
  begin
29
- @ssh = Net::SSH.start(@config[:host], @config[:user],:password => @config[:password])
30
+ @ssh = Net::SSH.start(@config[:host], @config[:user], :port => @config[:port], :password => @config[:password])
30
31
  rescue Net::SSH::AuthenticationFailed
31
32
  raise CredentialsError, 'Invalid SSH user or password'
32
33
  end
@@ -58,11 +59,11 @@ module Snatch
58
59
  def dump
59
60
  cmd = []
60
61
  cmd << "--user=#{@config[:db_user]}"
61
- cmd << "--password=#{@config[:db_password]}" unless @config[:db_password].strip.empty?
62
- cmd << "--databases #{@config[:db_list].join(' ')}"
62
+ cmd << "--password=#{@config[:db_password]}" unless @config[:db_password].to_s.strip.empty?
63
63
  cmd << "--add-drop-database"
64
64
  cmd << "--add-drop-table"
65
65
  cmd << "--compact"
66
+ cmd << "--databases #{@config[:db_list].join(' ')}"
66
67
  cmd = "mysqldump #{cmd.join(' ')} | gzip --best > /tmp/#{filename}"
67
68
 
68
69
  puts "mysql: creating a dump..."
@@ -77,7 +78,7 @@ module Snatch
77
78
 
78
79
  # Fetch remote dump to local filesystem
79
80
  def download
80
- Net::SFTP.start(@config[:host], @config[:user], :password => @config[:password]) do |sftp|
81
+ Net::SFTP.start(@config[:host], @config[:user], :port => @config[:port], :password => @config[:password]) do |sftp|
81
82
  t = sftp.download!(
82
83
  "/tmp/#{filename}", # Remote file
83
84
  "#{Dir.pwd}/#{filename}", # Local file
@@ -87,4 +88,4 @@ module Snatch
87
88
  end
88
89
  end
89
90
  end
90
- end
91
+ end
@@ -1,3 +1,3 @@
1
1
  module Snatch
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
data/lib/snatch.rb CHANGED
@@ -7,6 +7,10 @@ require 'snatch/handler'
7
7
  require 'snatch/session'
8
8
 
9
9
  module Snatch
10
+ def self.root
11
+ File.join(ENV['HOME'], '.snatch')
12
+ end
13
+
10
14
  def self.run(config)
11
15
  s = Snatch::Session.new(config)
12
16
  s.run!
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snatchdb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
5
+ version: 1.0.1
11
6
  platform: ruby
12
7
  authors:
13
8
  - Dan Sosedoff
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-02-09 00:00:00 -06:00
13
+ date: 2011-06-14 00:00:00 -05:00
19
14
  default_executable: snatch
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - "="
28
23
  - !ruby/object:Gem::Version
29
- hash: 63
30
- segments:
31
- - 2
32
- - 0
33
- - 24
34
24
  version: 2.0.24
35
25
  type: :runtime
36
26
  version_requirements: *id001
@@ -42,11 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - "="
44
34
  - !ruby/object:Gem::Version
45
- hash: 5
46
- segments:
47
- - 2
48
- - 0
49
- - 5
50
35
  version: 2.0.5
51
36
  type: :runtime
52
37
  version_requirements: *id002
@@ -79,23 +64,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
64
  requirements:
80
65
  - - ">="
81
66
  - !ruby/object:Gem::Version
82
- hash: 3
83
- segments:
84
- - 0
85
67
  version: "0"
86
68
  required_rubygems_version: !ruby/object:Gem::Requirement
87
69
  none: false
88
70
  requirements:
89
71
  - - ">="
90
72
  - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
73
  version: "0"
95
74
  requirements: []
96
75
 
97
76
  rubyforge_project:
98
- rubygems_version: 1.4.1
77
+ rubygems_version: 1.6.2
99
78
  signing_key:
100
79
  specification_version: 3
101
80
  summary: Snatch is a remote database downloader via SSH protocol