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
- #command_string(cmd) ⇒ Object
- #exec(cmd) ⇒ Object
- #from_file(file) ⇒ Object
- #global_lock_file ⇒ Object
- #global_state_file ⇒ Object
-
#initialize(options) ⇒ Config
constructor
A new instance of Config.
- #mongo(db, script) ⇒ Object
- #mongodump(*args) ⇒ Object
- #oplog_dump ⇒ Object
- #oplog_dump_folder ⇒ Object
Constructor Details
#initialize(options) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 |
# File 'lib/mongo_oplog_backup/config.rb', line 7 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.
5 6 7 |
# File 'lib/mongo_oplog_backup/config.rb', line 5 def @options end |
Instance Method Details
#backup_dir ⇒ Object
27 28 29 |
# File 'lib/mongo_oplog_backup/config.rb', line 27 def backup_dir [:dir] end |
#command_line_options ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mongo_oplog_backup/config.rb', line 31 def args = [] args << '--ssl' if [:ssl] [:host, :port, :username, :password].each do |option| args += ["--#{option}", [option].strip] if [option] end args += ['--authenticationDatabase', 'admin'] if [:username] args end |
#command_string(cmd) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mongo_oplog_backup/config.rb', line 72 def command_string(cmd) previous = nil filtered = cmd.map do |token| pwd = (previous == '--password') previous = token if pwd '***' else token end end filtered.shelljoin end |
#exec(cmd) ⇒ Object
59 60 61 62 |
# File 'lib/mongo_oplog_backup/config.rb', line 59 def exec(cmd) MongoOplogBackup.log.debug ">>> #{command_string(cmd)}" Command.execute(cmd) end |
#from_file(file) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mongo_oplog_backup/config.rb', line 13 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 |
#global_lock_file ⇒ Object
55 56 57 |
# File 'lib/mongo_oplog_backup/config.rb', line 55 def global_lock_file File.join(backup_dir, 'backup.lock') end |
#global_state_file ⇒ Object
51 52 53 |
# File 'lib/mongo_oplog_backup/config.rb', line 51 def global_state_file File.join(backup_dir, 'backup.json') end |
#mongo(db, script) ⇒ Object
68 69 70 |
# File 'lib/mongo_oplog_backup/config.rb', line 68 def mongo(db, script) exec(['mongo'] + + ['--quiet', '--norc', script]) end |
#mongodump(*args) ⇒ Object
64 65 66 |
# File 'lib/mongo_oplog_backup/config.rb', line 64 def mongodump(*args) exec(['mongodump'] + + args.flatten) end |
#oplog_dump ⇒ Object
47 48 49 |
# File 'lib/mongo_oplog_backup/config.rb', line 47 def oplog_dump File.join(oplog_dump_folder, 'local/oplog.rs.bson') end |
#oplog_dump_folder ⇒ Object
43 44 45 |
# File 'lib/mongo_oplog_backup/config.rb', line 43 def oplog_dump_folder File.join(backup_dir, 'tmp-dump') end |