mysqlaudit 0.0.5 → 0.0.6
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/README.md +44 -5
- data/bin/mysqlaudit +23 -12
- data/lib/mysqlaudit/config.rb +29 -0
- data/lib/mysqlaudit/version.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -60,9 +60,31 @@ DELETE FROM foo WHERE id = 2;
|
|
60
60
|
|
61
61
|
To apply rollback with specific transaction, this generate SQL output:
|
62
62
|
|
63
|
+
### Get all changes:
|
64
|
+
|
65
|
+
You change data, could reverse with simple statements:
|
66
|
+
|
67
|
+
```Shell
|
68
|
+
$ mysqlaudit rollback --host 127.0.0.1 \
|
69
|
+
--user root \
|
70
|
+
--pass admin \
|
71
|
+
--schema audit \
|
72
|
+
--table foo \
|
73
|
+
```
|
74
|
+
|
75
|
+
Output of last executed command:
|
76
|
+
|
77
|
+
```
|
78
|
+
/* 2013-07-11 07:25:25 */ INSERT INTO foo (id, email, name, birthday) VALUES (2, 'def@def.org', 'Mengano', '1979-03-28 00:00:00');
|
79
|
+
/* 2013-07-11 07:26:26 */ UPDATE users SET name = 'Jaimito' WHERE id = 3;
|
80
|
+
/* 2013-07-11 07:27:27 */ DELETE FROM foo WHERE id = 1;
|
81
|
+
/* 2013-07-11 07:27:27 */ DELETE FROM foo WHERE id = 2;
|
82
|
+
/* 2013-07-11 07:27:27 */ DELETE FROM foo WHERE id = 3;
|
83
|
+
```
|
84
|
+
|
63
85
|
### Get deleted data:
|
64
86
|
|
65
|
-
You delete data, could reverse with simple insert statements
|
87
|
+
You delete data, could reverse with simple insert statements:
|
66
88
|
|
67
89
|
```Shell
|
68
90
|
$ mysqlaudit rollback --host 127.0.0.1 \
|
@@ -82,7 +104,7 @@ Output of last executed command:
|
|
82
104
|
### Get updated data:
|
83
105
|
|
84
106
|
You updated data, could reverse with simple update statements to change new for
|
85
|
-
old value
|
107
|
+
old value:
|
86
108
|
|
87
109
|
```Shell
|
88
110
|
$ mysqlaudit rollback --host 127.0.0.1 \
|
@@ -96,13 +118,12 @@ $ mysqlaudit rollback --host 127.0.0.1 \
|
|
96
118
|
Output of last executed command:
|
97
119
|
|
98
120
|
```
|
99
|
-
/* 2013-07-11 07:26:26 */ UPDATE users SET birthday = '1980-06-15 00:00:00' WHERE id = 3;
|
100
121
|
/* 2013-07-11 07:26:26 */ UPDATE users SET name = 'Jaimito' WHERE id = 3;
|
101
122
|
```
|
102
123
|
|
103
124
|
### Get inserted data:
|
104
125
|
|
105
|
-
You inserted data, could reverse with simple delete statements
|
126
|
+
You inserted data, could reverse with simple delete statements:
|
106
127
|
|
107
128
|
```Shell
|
108
129
|
$ mysqlaudit rollback --host 127.0.0.1 \
|
@@ -123,7 +144,7 @@ Output of last executed command:
|
|
123
144
|
|
124
145
|
### Uninstall test enviroment:
|
125
146
|
|
126
|
-
Uninstall all triggers and drop audit table
|
147
|
+
Uninstall all triggers and drop audit table:
|
127
148
|
|
128
149
|
```Shell
|
129
150
|
$ mysqlaudit uninstall --host 127.0.0.1 \
|
@@ -140,6 +161,24 @@ Drop testing table and database:
|
|
140
161
|
DROP TABLE foo;
|
141
162
|
DROP DATABASE audit;
|
142
163
|
```
|
164
|
+
### Config file example:
|
165
|
+
|
166
|
+
```YAML
|
167
|
+
development:
|
168
|
+
|
169
|
+
test:
|
170
|
+
|
171
|
+
production:
|
172
|
+
host: localhost
|
173
|
+
user: root
|
174
|
+
password: admin
|
175
|
+
database: audit
|
176
|
+
```
|
177
|
+
|
178
|
+
### Execute command with config file and enviroment:
|
179
|
+
```Shell
|
180
|
+
$ ENVIRONMENT=production mysqlaudit install -c config.yml --table foo
|
181
|
+
```
|
143
182
|
|
144
183
|
For more information:
|
145
184
|
|
data/bin/mysqlaudit
CHANGED
@@ -6,7 +6,9 @@ $LOAD_PATH << './lib'
|
|
6
6
|
require 'rubygems'
|
7
7
|
require 'commander'
|
8
8
|
require 'commander/import'
|
9
|
+
require 'yaml'
|
9
10
|
require 'mysqlaudit'
|
11
|
+
require 'mysqlaudit/config'
|
10
12
|
require 'mysqlaudit/actions'
|
11
13
|
require 'mysqlaudit/version'
|
12
14
|
|
@@ -15,15 +17,22 @@ program :version, Mysqlaudit::VERSION
|
|
15
17
|
program :description, 'MySQL tool for audit all tables with triggers.'
|
16
18
|
program :help, 'Author', 'Nicola Strappazzon <nicola51980@gmail.com>'
|
17
19
|
|
20
|
+
global_option('-c', '--config FILE')
|
21
|
+
global_option('-H', '--host STRING')
|
22
|
+
global_option('-u', '--user STRING')
|
23
|
+
global_option('-p', '--pass STRING')
|
24
|
+
global_option('-s', '--schema STRING')
|
25
|
+
|
18
26
|
command :install do |c|
|
19
27
|
c.description = 'Install audit table'
|
20
28
|
c.syntax = 'mysqlaudit install --host 127.0.0.1 --user root [--pass admin] --schema sakila [--table foo]'
|
21
|
-
c.option '--host STRING', String, 'Host'
|
22
|
-
c.option '--user STRING', String, 'User'
|
23
|
-
c.option '--pass STRING', String, 'Password'
|
24
|
-
c.option '--schema STRING', String, 'Schema name'
|
25
29
|
c.option '--table STRING', String, 'Table name'
|
30
|
+
|
26
31
|
c.action do |args, options|
|
32
|
+
configs = Mysqlaudit::Config.new()
|
33
|
+
configs.load(options.config)
|
34
|
+
configs.merge(options)
|
35
|
+
|
27
36
|
if options.host.nil? ||
|
28
37
|
options.user.nil? ||
|
29
38
|
options.schema.nil?
|
@@ -41,13 +50,14 @@ end
|
|
41
50
|
command :uninstall do |c|
|
42
51
|
c.description = 'Uninstall audit table'
|
43
52
|
c.syntax = 'mysqlaudit uninstall --host 127.0.0.1 --user root [--pass admin] --schema sakila [--table foo] [--[no-]drop-audit-table]'
|
44
|
-
c.option '--host STRING', String, 'Host'
|
45
|
-
c.option '--user STRING', String, 'User'
|
46
|
-
c.option '--pass STRING', String, 'Password'
|
47
|
-
c.option '--schema STRING', String, 'Schema name'
|
48
53
|
c.option '--table STRING', String, 'Table name'
|
49
54
|
c.option '--[no-]drop-audit-table', 'Drop audit table'
|
55
|
+
|
50
56
|
c.action do |args, options|
|
57
|
+
configs = Mysqlaudit::Config.new()
|
58
|
+
configs.load(options.config)
|
59
|
+
configs.merge(options)
|
60
|
+
|
51
61
|
if options.host.nil? ||
|
52
62
|
options.user.nil? ||
|
53
63
|
options.schema.nil?
|
@@ -66,13 +76,14 @@ end
|
|
66
76
|
command :rollback do |c|
|
67
77
|
c.description = 'Rollback transaction cath in audit table'
|
68
78
|
c.syntax = 'mysqlaudit rollback --host 127.0.0.1 --user root [--pass admin] --schema sakila --table foo [--statement all|insert|update|delete]'
|
69
|
-
c.option '--host STRING', String, 'Host'
|
70
|
-
c.option '--user STRING', String, 'User'
|
71
|
-
c.option '--pass STRING', String, 'Password'
|
72
|
-
c.option '--schema STRING', String, 'Schema name'
|
73
79
|
c.option '--table STRING', String, 'Table name'
|
74
80
|
c.option '--statement STRING', String, 'Statement operation: all, insert, update, delete'
|
81
|
+
|
75
82
|
c.action do |args, options|
|
83
|
+
configs = Mysqlaudit::Config.new()
|
84
|
+
configs.load(options.config)
|
85
|
+
configs.merge(options)
|
86
|
+
|
76
87
|
options.default statement: :all
|
77
88
|
|
78
89
|
if options.host.nil? ||
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module Mysqlaudit
|
3
|
+
class Config
|
4
|
+
@configs = nil
|
5
|
+
|
6
|
+
def load(file)
|
7
|
+
if !file.nil? && !ENV['ENVIRONMENT'].nil?
|
8
|
+
path = File.expand_path(File.join(Dir.pwd, file))
|
9
|
+
|
10
|
+
if File.exist?(path)
|
11
|
+
@configs = YAML.load_file(path)
|
12
|
+
@configs = @configs[ENV['ENVIRONMENT']]
|
13
|
+
@configs = @configs.inject({}){|config,(k,v)| config[k.to_sym] = v; config}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def merge(options)
|
19
|
+
if !@configs.nil?
|
20
|
+
options.host = options.host || @configs[:host]
|
21
|
+
options.user = options.user || @configs[:user]
|
22
|
+
options.pass = options.password || @configs[:password]
|
23
|
+
options.schema = options.schema || @configs[:database]
|
24
|
+
end
|
25
|
+
|
26
|
+
options
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/mysqlaudit/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysqlaudit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: MySQL tool for audit all tables with triggers.
|
15
15
|
email: nicola51980@gmail.com
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- bin/mysqlaudit
|
22
22
|
- lib/mysqlaudit/actions.rb
|
23
23
|
- lib/mysqlaudit/audit.rb
|
24
|
+
- lib/mysqlaudit/config.rb
|
24
25
|
- lib/mysqlaudit/version.rb
|
25
26
|
- lib/mysqlaudit.rb
|
26
27
|
- LICENSE.txt
|