cowtech-rails 2.6.0.1 → 2.6.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cowtech/tasks/log.rake +6 -6
- data/lib/cowtech/tasks/mongodb.rake +8 -8
- data/lib/cowtech/tasks/sql.rake +9 -9
- data/lib/cowtech/version.rb +1 -1
- metadata +4 -4
data/lib/cowtech/tasks/log.rake
CHANGED
@@ -19,14 +19,14 @@ module Cowtech
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.rotate(rake_args)
|
22
|
-
Cowtech::RubyOnRails::
|
22
|
+
Cowtech::RubyOnRails::Scheduler.log "Rotating log files..."
|
23
23
|
|
24
24
|
# Get timestamp
|
25
25
|
tstamp = Time.now.strftime("%Y%m%d")
|
26
26
|
|
27
27
|
# For each log file
|
28
28
|
Dir.glob(Rails.root + "log/*.log") do |log_file|
|
29
|
-
Cowtech::RubyOnRails::
|
29
|
+
Cowtech::RubyOnRails::Scheduler.log "\tRotating #{log_file} ..."
|
30
30
|
new_name = "#{File.basename(log_file)}-#{tstamp}" # CREIAMO IL NOME
|
31
31
|
|
32
32
|
# Resolv duplicates
|
@@ -43,7 +43,7 @@ module Cowtech
|
|
43
43
|
|
44
44
|
# Send file via mail
|
45
45
|
if (Rails.env == "production" || rake_args["force"].to_boolean) && rake_args["email_class"].present? then
|
46
|
-
Cowtech::RubyOnRails::
|
46
|
+
Cowtech::RubyOnRails::Scheduler.log "\tForwarding log file to requested email address..."
|
47
47
|
rake_args["email_class"].constantize.log_report(log_file).deliver
|
48
48
|
end
|
49
49
|
|
@@ -55,18 +55,18 @@ module Cowtech
|
|
55
55
|
end
|
56
56
|
|
57
57
|
# Truncate files
|
58
|
-
Cowtech::RubyOnRails::
|
58
|
+
Cowtech::RubyOnRails::Scheduler.log "Truncating current log files ..."
|
59
59
|
Dir.glob(Rails.root + "log/*.log") do |log_file|
|
60
60
|
File.open(log_file, "w").close
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.clean
|
65
|
-
Cowtech::RubyOnRails::
|
65
|
+
Cowtech::RubyOnRails::Scheduler.log "Cleaning log files..."
|
66
66
|
|
67
67
|
["backups/logs/*.log", "backups/logs/*.#{@@log_compressed_extension}"].each do |path|
|
68
68
|
Dir.glob(Rails.root + path) do |log_file|
|
69
|
-
Cowtech::RubyOnRails::
|
69
|
+
Cowtech::RubyOnRails::Scheduler.log "\tDeleting #{log_file.gsub(Rails.root.to_s + "/", "")} ..."
|
70
70
|
File.delete(log_file)
|
71
71
|
end
|
72
72
|
end
|
@@ -12,7 +12,7 @@ module Cowtech
|
|
12
12
|
def self.run_command(cmd); system(cmd) end
|
13
13
|
|
14
14
|
def self.backup(rake_args)
|
15
|
-
Cowtech::RubyOnRails::
|
15
|
+
Cowtech::RubyOnRails::Scheduler.log "--- Backupping MongoDB ..."
|
16
16
|
|
17
17
|
# Get configuration
|
18
18
|
mongo_config = YAML.load_file(Rails.root + "config/mongoid.yml")
|
@@ -28,36 +28,36 @@ module Cowtech
|
|
28
28
|
FileUtils.mkdir_p(dir) if !File.directory?(dir)
|
29
29
|
|
30
30
|
databases.each do |db|
|
31
|
-
Cowtech::RubyOnRails::
|
31
|
+
Cowtech::RubyOnRails::Scheduler.log "\t\tBackupping DB #{db} ..."
|
32
32
|
|
33
33
|
dump_cmd = "mongodump"
|
34
34
|
dump_args = {"" => "-o \"#{dest_file}\"", "database" => "-d #{db}"}
|
35
35
|
|
36
36
|
# Execute command
|
37
|
-
Cowtech::RubyOnRails::
|
37
|
+
Cowtech::RubyOnRails::Scheduler.log "\t\tDumping data ..."
|
38
38
|
Cowtech::RubyOnRails::MongoUtils.run_command(dump_cmd + " " + dump_args.values.join(" "))
|
39
39
|
end
|
40
40
|
|
41
41
|
# Compress
|
42
|
-
Cowtech::RubyOnRails::
|
42
|
+
Cowtech::RubyOnRails::Scheduler.log "\t\tCompressing backup ..."
|
43
43
|
Cowtech::RubyOnRails::MongoUtils.run_command(@@log_compressor_command + " " + final_file + " " + dest_file.to_s)
|
44
44
|
FileUtils.rm_rf(dest_file.to_s)
|
45
45
|
|
46
46
|
# Send file via mail
|
47
47
|
if (Rails.env == "production" || rake_args["force"].to_boolean) && rake_args["email_class"].present? then
|
48
|
-
Cowtech::RubyOnRails::
|
48
|
+
Cowtech::RubyOnRails::Scheduler.log "\tForwarding backup file to requested email address..."
|
49
49
|
rake_args["email_class"].constantize.backup(final_file).deliver
|
50
50
|
end
|
51
51
|
|
52
|
-
Cowtech::RubyOnRails::
|
52
|
+
Cowtech::RubyOnRails::Scheduler.log "Backup saved in #{dest_file}.#{@@log_compressed_extension}"
|
53
53
|
end
|
54
54
|
|
55
55
|
def self.backup_clean
|
56
|
-
Cowtech::RubyOnRails::
|
56
|
+
Cowtech::RubyOnRails::Scheduler.log "--- Cleaning database backup files ..."
|
57
57
|
|
58
58
|
["backups/mysql/*.sql", "backups/mysql/backup/*.#{@@log_compressed_extension}"].each do |path|
|
59
59
|
Dir.glob(Rails.root + path) do |log_file|
|
60
|
-
Cowtech::RubyOnRails::
|
60
|
+
Cowtech::RubyOnRails::Scheduler.log "\tDeleting #{log_file.gsub(Rails.root.to_s + "/", "")} ..."
|
61
61
|
File.delete(log_file)
|
62
62
|
end
|
63
63
|
end
|
data/lib/cowtech/tasks/sql.rake
CHANGED
@@ -34,20 +34,20 @@ module Cowtech
|
|
34
34
|
FileUtils.mkdir_p(dir) if !File.directory?(dir)
|
35
35
|
|
36
36
|
# Execute command
|
37
|
-
Cowtech::RubyOnRails::
|
37
|
+
Cowtech::RubyOnRails::Scheduler.log "\tDumping data ..."
|
38
38
|
Cowtech::RubyOnRails::MysqlUtils.run_command(dump_cmd + " " + dump_args.values.join(" "))
|
39
39
|
|
40
40
|
# Compress
|
41
|
-
Cowtech::RubyOnRails::
|
41
|
+
Cowtech::RubyOnRails::Scheduler.log "\tCompressing backup ..."
|
42
42
|
Cowtech::RubyOnRails::MysqlUtils.run_command(@@log_compressor_command + " " + dest_file.to_s)
|
43
43
|
|
44
44
|
# Send file via mail
|
45
45
|
if (Rails.env == "production" || rake_args["force"].to_boolean) && rake_args["email_class"].present? then
|
46
|
-
Cowtech::RubyOnRails::
|
46
|
+
Cowtech::RubyOnRails::Scheduler.log "\tForwarding backup file to requested email address..."
|
47
47
|
rake_args["email_class"].constantize.backup(final_file).deliver
|
48
48
|
end
|
49
49
|
|
50
|
-
Cowtech::RubyOnRails::
|
50
|
+
Cowtech::RubyOnRails::Scheduler.log "Backup saved in #{final_file}"
|
51
51
|
end
|
52
52
|
|
53
53
|
# ALIAS
|
@@ -61,12 +61,12 @@ module Cowtech
|
|
61
61
|
@@log_compressed_extension = "bz2"
|
62
62
|
|
63
63
|
def self.to_fixtures
|
64
|
-
Cowtech::RubyOnRails::
|
64
|
+
Cowtech::RubyOnRails::Scheduler.log "--- Dumping database into fixtures ..."
|
65
65
|
sql = "SELECT * FROM %s"
|
66
66
|
skip_tables = ["schema_info"]
|
67
67
|
ActiveRecord::Base.establish_connection
|
68
68
|
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
|
69
|
-
Cowtech::RubyOnRails::
|
69
|
+
Cowtech::RubyOnRails::Scheduler.log "--- --- Dumping table #{table_name} ..."
|
70
70
|
i = "01"
|
71
71
|
File.open("#{RAILS_ROOT}/test/fixture/#{table_name}.yml", 'w') do |file|
|
72
72
|
data = ActiveRecord::Base.connection.select_all(sql % table_name)
|
@@ -79,7 +79,7 @@ module Cowtech
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def self.backup(rake_args)
|
82
|
-
Cowtech::RubyOnRails::
|
82
|
+
Cowtech::RubyOnRails::Scheduler.log "--- Backupping database ..."
|
83
83
|
# OTTENIAMO LA CONFIGURAZIONE
|
84
84
|
db_config = YAML.load_file(Rails.root + "config/database.yml")
|
85
85
|
env = Rails.env
|
@@ -89,11 +89,11 @@ module Cowtech
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def self.backup_clean
|
92
|
-
Cowtech::RubyOnRails::
|
92
|
+
Cowtech::RubyOnRails::Scheduler.log "--- Cleaning database backup files ..."
|
93
93
|
|
94
94
|
["backups/mysql/*.sql", "backups/mysql/backup/*.#{@@log_compressed_extension}"].each do |path|
|
95
95
|
Dir.glob(Rails.root + path) do |log_file|
|
96
|
-
Cowtech::RubyOnRails::
|
96
|
+
Cowtech::RubyOnRails::Scheduler.log "\tDeleting #{log_file.gsub(Rails.root.to_s + "/", "")} ..."
|
97
97
|
File.delete(log_file)
|
98
98
|
end
|
99
99
|
end
|
data/lib/cowtech/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cowtech-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.0.
|
4
|
+
version: 2.6.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-29 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cowtech-extensions
|
16
|
-
requirement: &
|
16
|
+
requirement: &70341847282100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70341847282100
|
25
25
|
description: A general purpose Rails utility plugin.
|
26
26
|
email: shogun_panda@me.com
|
27
27
|
executables: []
|