Class: MongoOplogBackup::Config
- Inherits:
-
Object
- Object
- MongoOplogBackup::Config
- Defined in:
- lib/mongo_oplog_backup/config.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #backup_dir ⇒ Object
- #command_line_options ⇒ Object
- #exec(cmd) ⇒ Object
- #from_file(file) ⇒ Object
-
#initialize(options) ⇒ Config
constructor
A new instance of Config.
- #lock_file ⇒ Object
- #mongo(db, script) ⇒ Object
- #mongodump(args) ⇒ Object
- #oplog_dump ⇒ Object
- #oplog_dump_folder ⇒ Object
- #state_file ⇒ Object
Constructor Details
#initialize(options) ⇒ Config
Returns a new instance of Config.
5 6 7 8 9 |
# File 'lib/mongo_oplog_backup/config.rb', line 5 def initialize() config_file = .delete(:file) # Command line options take precedence @options = from_file(config_file).merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/mongo_oplog_backup/config.rb', line 3 def @options end |
Instance Method Details
#backup_dir ⇒ Object
25 26 27 |
# File 'lib/mongo_oplog_backup/config.rb', line 25 def backup_dir [:dir] end |
#command_line_options ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/mongo_oplog_backup/config.rb', line 29 def ssl = [:ssl] ? '--ssl ' : '' host = [:host] ? "--host #{[:host].strip} " : '' port = [:port] ? "--port #{[:port].strip} " : '' username = [:username] ? "--username #{[:username].strip} " : '' password = [:password] ? "--password #{[:password].strip} " : '' "#{host}#{port}#{ssl}#{username}#{password}" end |
#exec(cmd) ⇒ Object
54 55 56 57 |
# File 'lib/mongo_oplog_backup/config.rb', line 54 def exec(cmd) MongoOplogBackup.log.debug ">>> #{cmd}" `#{cmd}` end |
#from_file(file) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mongo_oplog_backup/config.rb', line 11 def from_file file = {} unless file.nil? conf = YAML.load_file(file) [:ssl] = conf["ssl"] unless conf["ssl"].nil? [:host] = conf["host"] unless conf["host"].nil? [:port] = conf["port"].to_s unless conf["port"].nil? [:username] = conf["username"] unless conf["username"].nil? [:password] = conf["password"] unless conf["password"].nil? end end |
#lock_file ⇒ Object
50 51 52 |
# File 'lib/mongo_oplog_backup/config.rb', line 50 def lock_file File.join(backup_dir, 'backup.lock') end |
#mongo(db, script) ⇒ Object
63 64 65 |
# File 'lib/mongo_oplog_backup/config.rb', line 63 def mongo(db, script) exec("mongo #{} --quiet --norc #{db} #{script}") end |
#mongodump(args) ⇒ Object
59 60 61 |
# File 'lib/mongo_oplog_backup/config.rb', line 59 def mongodump(args) MongoOplogBackup.log.info exec("mongodump #{} #{args}") end |
#oplog_dump ⇒ Object
42 43 44 |
# File 'lib/mongo_oplog_backup/config.rb', line 42 def oplog_dump File.join(oplog_dump_folder, 'local/oplog.rs.bson') end |
#oplog_dump_folder ⇒ Object
38 39 40 |
# File 'lib/mongo_oplog_backup/config.rb', line 38 def oplog_dump_folder File.join(backup_dir, 'dump') end |
#state_file ⇒ Object
46 47 48 |
# File 'lib/mongo_oplog_backup/config.rb', line 46 def state_file File.join(backup_dir, 'backup.json') end |