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
- #use_compression? ⇒ Boolean
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
30 31 32 |
# File 'lib/mongo_oplog_backup/config.rb', line 30 def backup_dir [:dir] end |
#command_line_options ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mongo_oplog_backup/config.rb', line 38 def args = [] args << '--ssl' if [:ssl] args << '--sslAllowInvalidCertificates' if [:sslAllowInvalidCertificates] [:host, :port, :username, :password, :sslCAFile].each do |option| args += ["--#{option}", [option].strip] if [option] end args += ['--authenticationDatabase', 'admin'] if [:username] args end |
#command_string(cmd) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/mongo_oplog_backup/config.rb', line 84 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
71 72 73 74 |
# File 'lib/mongo_oplog_backup/config.rb', line 71 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 26 27 28 |
# File 'lib/mongo_oplog_backup/config.rb', line 13 def from_file file = {} unless file.nil? conf = YAML.load_file(file) [:gzip] = conf["gzip"] unless conf["gzip"].nil? [:ssl] = conf["ssl"] unless conf["ssl"].nil? [:sslAllowInvalidCertificates] = conf["sslAllowInvalidCertificates"] unless conf["sslAllowInvalidCertificates"].nil? [:sslCAFile] = conf["sslCAFile"] unless conf["sslCAFile"].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
67 68 69 |
# File 'lib/mongo_oplog_backup/config.rb', line 67 def global_lock_file File.join(backup_dir, 'backup.lock') end |
#global_state_file ⇒ Object
63 64 65 |
# File 'lib/mongo_oplog_backup/config.rb', line 63 def global_state_file File.join(backup_dir, 'backup.json') end |
#mongo(db, script) ⇒ Object
80 81 82 |
# File 'lib/mongo_oplog_backup/config.rb', line 80 def mongo(db, script) exec(['mongo'] + + ['--quiet', '--norc', script]) end |
#mongodump(*args) ⇒ Object
76 77 78 |
# File 'lib/mongo_oplog_backup/config.rb', line 76 def mongodump(*args) exec(['mongodump'] + + args.flatten) end |
#oplog_dump ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/mongo_oplog_backup/config.rb', line 55 def oplog_dump if use_compression? File.join(oplog_dump_folder, 'local/oplog.rs.bson.gz') else File.join(oplog_dump_folder, 'local/oplog.rs.bson') end end |
#oplog_dump_folder ⇒ Object
51 52 53 |
# File 'lib/mongo_oplog_backup/config.rb', line 51 def oplog_dump_folder File.join(backup_dir, 'tmp-dump') end |
#use_compression? ⇒ Boolean
34 35 36 |
# File 'lib/mongo_oplog_backup/config.rb', line 34 def use_compression? !![:gzip] end |