cowtech-rails 2.3.1.0 → 2.3.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,15 +3,70 @@
3
3
  # This file is part of the cowtech-rails gem. Copyright (C) 2011 and above Shogun <shogun_panda@me.com>.
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
+ module Cowtech
7
+ module RubyOnRails
8
+ class MongoUtils
9
+ @@log_compressor_command = "tar cjvf"
10
+ @@log_compressed_extension = "tbz2"
11
+
12
+ def self.run_command(cmd); system(cmd) end
13
+
14
+ def self.backup
15
+ puts "--- Backupping MongoDB ..."
16
+
17
+ # Get configuration
18
+ mongo_config = YAML.load_file(Rails.root + "config/mongoid.yml")
19
+ databases = mongo_config["backup_databases"].as_s.split(/\s*,\s*/)
20
+ return if databases.blank?
21
+
22
+ # Set output dir
23
+ dest_file = Rails.root + "backups/mongodb/mongo-#{Time.now.strftime("%Y%m%d-%H%M%S")}"
24
+
25
+ # Create directory
26
+ dir = File.dirname(dest_file)
27
+ FileUtils.mkdir_p(dir) if !File.directory?(dir)
28
+
29
+ databases.each do |db|
30
+ puts "\t\tBackupping DB #{db} ..."
31
+
32
+ dump_cmd = "mongodump"
33
+ dump_args = {"" => "-o \"#{dest_file}\"", "database" => "-d #{db}"}
34
+
35
+ # Execute command
36
+ puts "\t\tDumping data ..."
37
+ Cowtech::RubyOnRails::MongoUtils.run_command(dump_cmd + " " + dump_args.values.join(" "))
38
+ end
39
+
40
+ # Compress
41
+ puts "\t\tCompressing backup ..."
42
+ Cowtech::RubyOnRails::MongoUtils.run_command(@@log_compressor_command + " " + dest_file.to_s + "." + @@log_compressed_extension + " " + dest_file.to_s)
43
+ FileUtils.rm_rf(dest_file.to_s)
44
+
45
+ puts "Backup saved in #{dest_file}.#{@@log_compressed_extension}"
46
+ end
47
+
48
+ def self.backup_clean
49
+ puts "--- Cleaning database backup files ..."
50
+
51
+ ["backups/mysql/*.sql", "backups/mysql/backup/*.#{@@log_compressed_extension}"].each do |path|
52
+ Dir.glob(Rails.root + path) do |log_file|
53
+ puts "\tDeleting #{log_file.gsub(Rails.root.to_s + "/", "")} ..."
54
+ File.delete(log_file)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
6
61
 
7
62
  namespace :mongodb do
8
63
  desc "Backups MongoDB collections"
9
64
  task :backup do |task|
10
-
65
+ Cowtech::RubyOnRails::MongoUtils.backup
11
66
  end
12
67
 
13
68
  desc "Clean every backup file"
14
69
  task :backup_clean do |task|
15
-
70
+ Cowtech::RubyOnRails::MongoUtils.backup_clean
16
71
  end
17
72
  end
@@ -49,7 +49,7 @@ module Cowtech
49
49
  end
50
50
  end
51
51
 
52
- class Cowtech::RubyOnRails::SqlUtils
52
+ class SqlUtils
53
53
  @@log_compressor_command = "bzip2"
54
54
  @@log_compressed_extension = "bz2"
55
55
 
@@ -9,7 +9,7 @@ module Cowtech
9
9
  module Version
10
10
  MAJOR = 2
11
11
  MINOR = 3
12
- PATCH = 1
12
+ PATCH = 2
13
13
  BUILD = 0
14
14
 
15
15
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
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.3.1.0
4
+ version: 2.3.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cowtech-extensions
16
- requirement: &70273274114300 !ruby/object:Gem::Requirement
16
+ requirement: &70306162535880 !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: *70273274114300
24
+ version_requirements: *70306162535880
25
25
  description: A general purpose Rails utility plugin.
26
26
  email: shogun_panda@me.com
27
27
  executables: []