my_general 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c4ce678b6da475675e5f6804cae58a7f642367b78568cae33ff63d126b295018
4
+ data.tar.gz: 8a2d5d7129071b08376a85c749478b647cf215e13f06bef425e2fd43ec550a99
5
+ SHA512:
6
+ metadata.gz: a9c1a30e12a3f6502b28aa7a72325d003e7520f454d2dc93a4f8bd2e2a9e0abd16a1e22face9cae6c08eaf36ce72ebf94c486ad58cb0506e0ca3cf5a699f1775
7
+ data.tar.gz: 10287b2ca71453fc887fa1118bf4feb7fc1df6e66b93e14a0a34d2289ddc739b7a19b246f11c2435ce00110279ee03f0703427aefc90b8b39f9504462e79b39c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Delton Ding
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/bin/my_general ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'my_general'
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = 'Usage: my_general [options]'
10
+ opts.on('-l LOG_FILE", "--log", "General Purpose Log File') do |v|
11
+ options[:log] = v
12
+ end
13
+ opts.on('-d DATABASE_YAML", "--database", "Database Connection YAML') do |v|
14
+ options[:database] = v
15
+ end
16
+ end.parse!
17
+
18
+ instance = MyGeneral::Instance.new(options[:log], options[:database])
19
+ instance.run
data/lib/my_general.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'ruby-progressbar'
2
+ require 'sequel'
3
+ require 'yaml'
4
+
5
+ require_relative 'my_general/version'
6
+
7
+ require_relative 'my_general/instance'
@@ -0,0 +1,54 @@
1
+ class MyGeneral::Instance
2
+ def initialize(log_file, database_file)
3
+ @complexity = nil
4
+ @db = nil
5
+
6
+ @log_file = log_file
7
+ @database_file = database_file
8
+ end
9
+
10
+ def complexity
11
+ @complexity.nil? ? (@complexity = `wc -l #{@log_file}`.to_i) : @complexity
12
+ end
13
+
14
+ def run
15
+ puts "Log File: #{@log_file}"
16
+ puts "Database YAML: #{@database_file}"
17
+ puts '[1/4] ⌚ Counting Complexity...'
18
+ complexity
19
+ puts "[1/4] ⌚ Counting Complexity... OK [Complexity: #{@complexity}]"
20
+ puts '[2/4] 🔌 Dailing Database...'
21
+ @db = Sequel.connect(YAML.load_file(@database_file))
22
+ puts "[2/4] 🔌 Dailing Database... OK [Connected]"
23
+ puts '[3/4] ⏳ Importing Data...'
24
+ run_data
25
+ puts "[3/4] ⏳ Importing Data... OK [#{complexity}/#{complexity}]"
26
+ puts '[4/4] 🚩 Finished!'
27
+ end
28
+
29
+ def run_data
30
+ progressbar = ProgressBar.create
31
+ progressbar.total = complexity
32
+ File.open(@log_file, 'r') do |file|
33
+ until file.eof?
34
+ line = file.readline
35
+ run_query(line, progressbar)
36
+ progressbar.increment
37
+ end
38
+ end
39
+ end
40
+
41
+ def run_query(line, progressbar)
42
+ data = line.split("\t")
43
+ return if data.length < 3 # A connecting message
44
+ return if data[-1].upcase.start_with?('CREATE DATABASE') # Ignore database scale query
45
+ return unless data[-2].end_with?('Query') # Ignore not query
46
+ return if data[-1].upcase.start_with?('SELECT')# Ignore select query
47
+ return if data[-1].upcase.start_with?('SHOW') # Ignore show query
48
+ @db.run(data[-1])
49
+ rescue => e
50
+ progressbar.log("When executing #{line}")
51
+ progressbar.log('We met a problem:')
52
+ progressbar.log(e.inspect)
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ # MyGenral Module
2
+ module MyGeneral
3
+ # Current Version Code
4
+ VERSION = '0.0.1'.freeze
5
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: my_general
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - HeckPsi Lab
8
+ autorequire:
9
+ bindir:
10
+ - bin
11
+ cert_chain: []
12
+ date: 2018-01-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ruby-progressbar
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.9'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.9'
28
+ - !ruby/object:Gem::Dependency
29
+ name: sequel
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '5.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '5.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: mysql2
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.4'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.4'
56
+ - !ruby/object:Gem::Dependency
57
+ name: sqlite3
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.3'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ description: Recover MySQL data from General Purpose Query Log.
71
+ email:
72
+ - business@heckpsi.com
73
+ executables:
74
+ - my_general
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - LICENSE
79
+ - bin/my_general
80
+ - lib/my_general.rb
81
+ - lib/my_general/instance.rb
82
+ - lib/my_general/version.rb
83
+ homepage: https://github.com/dsh0416/my_general
84
+ licenses:
85
+ - MIT
86
+ metadata:
87
+ issue_tracker: https://github.com/dsh0416/my_general/issues
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.2.6
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.7.3
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Recover MySQL data from General Purpose Query Log
108
+ test_files: []