SQL_Dump 1.0.0
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.
- data/lib/sqldump.rb +58 -0
- metadata +65 -0
data/lib/sqldump.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'mysql'
|
5
|
+
def sqldump(user, pass, db)
|
6
|
+
begin
|
7
|
+
my = Mysql.new('localhost', user, pass, db)
|
8
|
+
res = my.query("show tables")
|
9
|
+
tables = []
|
10
|
+
num_tables = res.num_rows
|
11
|
+
num_tables.times do
|
12
|
+
tables.push(res.fetch_row)
|
13
|
+
end
|
14
|
+
tables.each do |tbl|
|
15
|
+
res = my.query("show create table #{tbl}")
|
16
|
+
create = ''
|
17
|
+
res.each_hash do |x|
|
18
|
+
create = "#{x['Create Table']};"
|
19
|
+
end
|
20
|
+
puts create
|
21
|
+
res = my.query("select * from #{tbl}")
|
22
|
+
num_rows = res.num_rows
|
23
|
+
content = []
|
24
|
+
num_rows.times do
|
25
|
+
content.push(res.fetch_row.join("_____"))
|
26
|
+
end
|
27
|
+
res = my.query("select * from #{tbl}")
|
28
|
+
num_rows = res.num_rows
|
29
|
+
content = []
|
30
|
+
num_rows.times do
|
31
|
+
content.push(res.fetch_row.join("_____"))
|
32
|
+
end
|
33
|
+
content.each do |cont|
|
34
|
+
res = my.query("explain #{tbl}")
|
35
|
+
num_cats = res.num_rows
|
36
|
+
y = 1
|
37
|
+
cats = []
|
38
|
+
print "insert into #{tbl}("
|
39
|
+
res.each_hash do |x|
|
40
|
+
print "#{x['Field']}" if y == num_cats
|
41
|
+
print "#{x['Field']}, " if y != num_cats
|
42
|
+
y += 1
|
43
|
+
end
|
44
|
+
print ") values("
|
45
|
+
cont = cont.gsub(/'/, "\\\\'")
|
46
|
+
cont = cont.gsub(/_____/, "', '")
|
47
|
+
puts "'#{cont}');"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
rescue Mysql::Error => e
|
51
|
+
puts "MySQL dump of #{db} failed!"
|
52
|
+
puts "#{e.errno}: #{e.error}"
|
53
|
+
puts "Exiting for safety"
|
54
|
+
exit
|
55
|
+
ensure
|
56
|
+
my.close
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: SQL_Dump
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jason Colyer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2014-05-01 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Calls the MySQL gem and generates a MySQL dump file
|
22
|
+
email: support@reyloc.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/sqldump.rb
|
31
|
+
homepage: http://rubygems.org/gems/sqldump
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.25
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: MySQL Dump
|
64
|
+
test_files: []
|
65
|
+
|