mongolly 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2673114b4273f7cb2b9e76dfac820be156200a2b
4
- data.tar.gz: 53b0137133a333b476912a4d4df01154cb25376f
3
+ metadata.gz: 3e4b3656a62e82093372d9bd79ed0fbff1edb236
4
+ data.tar.gz: fed24b679b86b489fc9f16b204bfb5d8ce9ece2e
5
5
  SHA512:
6
- metadata.gz: ebb1cc2d144a477ff4c9d9fded158a9c198954d8e4dbe50f1acdf4c2113cb62a9379b4b7fb694ee51ee20dbba4f26fe4422e7ebcb303702615ffae0b1c91ddde
7
- data.tar.gz: 2176c4248b46d3c1ebae1c193c113214cb24dbfdd6136fa29890b3ee28c74ad0136f615f5f6549c3d3e6eaae1ce635de9ddc67485bc69671b172e2f94aa777c7
6
+ metadata.gz: dee271cc8eb5c8535783835d5fb31024aa8e881bd1036eabf552618f4491fd4253ac1d2cfd18574669cbabfc6483de7c505704f7550e2432fb0c2237ec853cb4
7
+ data.tar.gz: 79de13b84da8ea7af451d0b11405728dd62e0aed7a46627c41ffbf1ebdd118f729a841a231feb35c32da467d43a8a51514ca066f3ebb97bfa2d7c25caa539498
data/README.md CHANGED
@@ -2,9 +2,28 @@
2
2
 
3
3
  **Easy backups for EBS-based MongoDB Databases**
4
4
 
5
- More details coming soon.
5
+ Mongolly is a collection of extensions to the [Mongo] Ruby driver and the [Amazon Web Services
6
+ Ruby SDK] that make backing up MongoDB-- even with a complex topology-- as easy as:
6
7
 
7
- ## Installation
8
+ `$ mongolly backup`
9
+
10
+ Mongolly's namesake and patron saint is [Dolly], the world's first cloned Mammal.
11
+
12
+ [Amazon Web Services Ruby SDK]: http://aws.amazon.com/sdkforruby/
13
+ [Mongo]: https://github.com/mongodb/mongo-ruby-driver
14
+ [Dolly]: http://en.wikipedia.org/wiki/Dolly_(sheep)
15
+
16
+ Mongolly is being actively used in production, however as with anything that touches your data or is responsible for something as important as backups, you should review the code and test heavily to make sure that it works properly for you.
17
+
18
+ ### Prerequisites
19
+
20
+ Mongolly makes the following assumptions about your MongoDB topology:
21
+
22
+ 1. The data files for your database are stored on EBS volumes.
23
+ 1. Your database or cluster resides within a single AWS region.
24
+ 1. Your EBS volumes are tagged with an identifier ("mongolly" by default) so that the script can properly backup the right volumes for a given instance.
25
+
26
+ ### Installation
8
27
 
9
28
  Add this line to your application's Gemfile:
10
29
 
@@ -12,15 +31,35 @@ Add this line to your application's Gemfile:
12
31
 
13
32
  And then execute:
14
33
 
15
- $ bundle
34
+ $ bundle install
16
35
 
17
- Or install it yourself as:
36
+ Or install it yourself:
18
37
 
19
38
  $ gem install mongolly
20
39
 
21
- ## Usage
40
+ ### Usage
41
+
42
+ The first time you run Mongolly, an empty configuration file will be written to `~/.mongolly`. You *must* now review this file and add the appropriate configuration for your database.
43
+
44
+ The configuration options are:
45
+
46
+ * **database** - db connection string (or for a replica set, array of connection strings). Example: `localhost:27017`
47
+ * **db_username** - db username with administrative privileges
48
+ * **db_password** -- db password
49
+ * **access_key_id** -- AWS Access Key
50
+ * **secret_access_key -- AWS Secret Key
51
+ * **region** -- AWS Region where your cluster is located
52
+ * **log_level** -- Logging level, `info` by default
53
+ * **mongo_start_command** -- The command that's issued on the mongo config server to start the config DB
54
+ * **mongo_stop_command** -- The command that's issued on the mongo config server to stop the config DB
55
+ * **config_server_ssh_user** -- The use to ssh to the config server as
56
+ * **config_server_ssh_keypath** -- The path to the ssh keys
57
+ * **volume_tag** -- The tag name identifying volumes to back up. Default is `mongolly`
58
+
59
+ Once you have created your configuration file, you are now ready to backup your database. That's as simple as:
60
+
61
+ `$ mongolly backup`
22
62
 
23
- `mongolly help usage`
24
63
 
25
64
  ## Contributing
26
65
 
@@ -32,5 +71,7 @@ Or install it yourself as:
32
71
 
33
72
  ### Copyright
34
73
 
35
- Copyright (c) 2012 Michael Saffitz. See LICENSE.txt for
74
+ Copyright (c) 2012-3 Michael Saffitz [@msaffitz](http://www.twitter.com/msaffitz)
75
+
76
+ See LICENSE.txt for
36
77
  further details.
@@ -6,6 +6,7 @@ require 'retries'
6
6
  class Mongo::MongoClient
7
7
  MAX_DISABLE_BALANCER_WAIT = 60*8 # 8 Minutes
8
8
  REPLICA_SNAPSHOT_THRESHOLD = 60*5 # 5 Minutes
9
+ REPLICA_SNAPSHOT_PREFER_HIDDEN = true
9
10
 
10
11
  def snapshot_ebs(options={})
11
12
 
@@ -32,12 +33,12 @@ class Mongo::MongoClient
32
33
  ssh_command(options[:config_server_ssh_user], config_server, options[:mongo_start_command], options[:config_server_ssh_keypath])
33
34
  end
34
35
  else
35
- backup_instance(snapshot_ebs_target(REPLICA_SNAPSHOT_THRESHOLD), options, false )
36
+ backup_instance(snapshot_ebs_target(REPLICA_SNAPSHOT_THRESHOLD, REPLICA_SNAPSHOT_PREFER_HIDDEN), options, false )
36
37
  end
37
38
  end
38
39
 
39
40
  protected
40
- def snapshot_ebs_target(threshold=nil)
41
+ def snapshot_ebs_target(threshold=nil, prefer_hidden=nil)
41
42
  host_port.join(':')
42
43
  end
43
44
 
@@ -2,21 +2,28 @@ require 'mongo'
2
2
 
3
3
  class Mongo::MongoReplicaSetClient
4
4
 
5
- def most_current_secondary(threshold = 0)
5
+ def most_current_secondary(threshold = 0, prefer_hidden = true)
6
6
  replica = self['admin'].command( replSetGetStatus: 1 )
7
- secondaries = replica['members'].select { |m| m['state'] == 2 }.sort_by { |m| m['name'] }
7
+ secondaries = replica['members'].select { |m| m['state'] == 2 }.sort_by { |m| [m['optime'], m['name']] }
8
8
  most_current = secondaries.first
9
- secondaries[1..-1].each do |secondary|
10
- if (secondary['optime'] - most_current['optime']) > threshold
11
- most_current = secondary
9
+
10
+ hidden = self['local']['system']['replset'].find_one['members'].select { |mem| mem['hidden'] }.map { |mem| mem['host'] }
11
+
12
+ if prefer_hidden && !hidden.include?(most_current['name'])
13
+ secondaries[1..-1].each do |secondary|
14
+ if hidden.include?(secondary['name']) && (most_current['optime'] - secondary['optime']) < threshold
15
+ most_current = secondary
16
+ break
17
+ end
12
18
  end
13
19
  end
14
- @mongolly_logger.debug("Found most current secondary #{most_current['name']}")
20
+
21
+ @mongolly_logger.debug("Found most current secondary #{most_current['name']}, hidden: #{hidden.include? most_current['name']}")
15
22
  most_current['name']
16
23
  end
17
24
 
18
25
  protected
19
- def snapshot_ebs_target(threshold = 0)
20
- most_current_secondary(threshold)
26
+ def snapshot_ebs_target(threshold = 0, prefer_hidden = true)
27
+ most_current_secondary(threshold, prefer_hidden)
21
28
  end
22
29
  end
@@ -1,3 +1,3 @@
1
1
  module Mongolly
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -17,12 +17,12 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency("thor", ["~> 0.15.4"])
21
- gem.add_dependency("mongo", ["~> 1.8.3"])
22
- gem.add_dependency("bson_ext", ["~> 1.8.3"])
23
- gem.add_dependency("aws-sdk", ["~> 1.9.5"])
20
+ gem.add_dependency("thor")
21
+ gem.add_dependency("mongo")
22
+ gem.add_dependency("bson_ext")
23
+ gem.add_dependency("aws-sdk")
24
24
  gem.add_dependency("ipaddress")
25
- gem.add_dependency("net-ssh", ["~> 2.0"])
25
+ gem.add_dependency("net-ssh")
26
26
  gem.add_dependency("retries")
27
27
 
28
28
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongolly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Saffitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-23 00:00:00.000000000 Z
11
+ date: 2013-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.15.4
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.15.4
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mongo
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.8.3
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.8.3
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bson_ext
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.8.3
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 1.8.3
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: aws-sdk
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.9.5
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
- version: 1.9.5
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ipaddress
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: net-ssh
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
- version: '2.0'
89
+ version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
- version: '2.0'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: retries
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  version: '0'
152
152
  requirements: []
153
153
  rubyforge_project:
154
- rubygems_version: 2.1.4
154
+ rubygems_version: 2.1.9
155
155
  signing_key:
156
156
  specification_version: 4
157
157
  summary: Easy backups for EBS-based MongoDB Databases