Class: DBGet::Dump
- Inherits:
-
Object
- Object
- DBGet::Dump
- Defined in:
- lib/dbget/dump.rb
Constant Summary
Constants included from Constants
Constants::CONFIG_PATH, Constants::MONGO_FILE_EXT, Constants::MONGO_INDEX_FILE
Instance Attribute Summary collapse
-
#append_date ⇒ Object
readonly
Returns the value of attribute append_date.
-
#backup_name ⇒ Object
Returns the value of attribute backup_name.
-
#clean ⇒ Object
readonly
Returns the value of attribute clean.
-
#collections ⇒ Object
Returns the value of attribute collections.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#db_type ⇒ Object
readonly
Returns the value of attribute db_type.
-
#decrypted_dump ⇒ Object
Returns the value of attribute decrypted_dump.
-
#encrypted_dump ⇒ Object
readonly
Returns the value of attribute encrypted_dump.
-
#target_db ⇒ Object
Returns the value of attribute target_db.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #cache_file ⇒ Object
- #clean? ⇒ Boolean
- #decrypt_dump ⇒ Object
- #form_db_name ⇒ Object
- #in_cache?(file) ⇒ Boolean
-
#initialize(opts) ⇒ Dump
constructor
A new instance of Dump.
- #prepare ⇒ Object
- #set_final_db ⇒ Object
Methods included from Utils
compress_file, decode_file, decompress_file, get_converted_date, get_files, randomize, say, say_with_time, to_bool
Constructor Details
#initialize(opts) ⇒ Dump
Returns a new instance of Dump.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dbget/dump.rb', line 13 def initialize(opts) @db = opts['db'] @db_type = opts['db_type'] @user = opts['user'] @server = opts['server'] @custom_name = opts['custom_name'] @collections = opts['collections'] @date = opts['date'] @clean = opts['clean'] @verbose = opts['verbose'] @append_date = opts['append_date'] @storage_path = File.join(DBGet.base_backups_path, @server, @db_type) end |
Instance Attribute Details
#append_date ⇒ Object (readonly)
Returns the value of attribute append_date.
10 11 12 |
# File 'lib/dbget/dump.rb', line 10 def append_date @append_date end |
#backup_name ⇒ Object
Returns the value of attribute backup_name.
11 12 13 |
# File 'lib/dbget/dump.rb', line 11 def backup_name @backup_name end |
#clean ⇒ Object (readonly)
Returns the value of attribute clean.
10 11 12 |
# File 'lib/dbget/dump.rb', line 10 def clean @clean end |
#collections ⇒ Object
Returns the value of attribute collections.
11 12 13 |
# File 'lib/dbget/dump.rb', line 11 def collections @collections end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
10 11 12 |
# File 'lib/dbget/dump.rb', line 10 def date @date end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
8 9 10 |
# File 'lib/dbget/dump.rb', line 8 def db @db end |
#db_type ⇒ Object (readonly)
Returns the value of attribute db_type.
8 9 10 |
# File 'lib/dbget/dump.rb', line 8 def db_type @db_type end |
#decrypted_dump ⇒ Object
Returns the value of attribute decrypted_dump.
11 12 13 |
# File 'lib/dbget/dump.rb', line 11 def decrypted_dump @decrypted_dump end |
#encrypted_dump ⇒ Object (readonly)
Returns the value of attribute encrypted_dump.
9 10 11 |
# File 'lib/dbget/dump.rb', line 9 def encrypted_dump @encrypted_dump end |
#target_db ⇒ Object
Returns the value of attribute target_db.
11 12 13 |
# File 'lib/dbget/dump.rb', line 11 def target_db @target_db end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/dbget/dump.rb', line 8 def user @user end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
10 11 12 |
# File 'lib/dbget/dump.rb', line 10 def verbose @verbose end |
Instance Method Details
#cache_file ⇒ Object
66 67 68 69 70 71 |
# File 'lib/dbget/dump.rb', line 66 def cache_file file = File.join(DBGet.cache_path, decrypted_file_name) file.concat('.tar') if @db_type.eql? 'mongo' file end |
#clean? ⇒ Boolean
46 47 48 |
# File 'lib/dbget/dump.rb', line 46 def clean? @clean end |
#decrypt_dump ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dbget/dump.rb', line 50 def decrypt_dump unless @encrypted_dump.nil? if in_cache? cache_file file_path = cache_file elsif File.exists? @encrypted_dump file_path = Utils.decompress_file(decrypt_file(copy_to_cache(@encrypted_dump))) end file_path end end |
#form_db_name ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/dbget/dump.rb', line 38 def form_db_name if !date.nil? and append_date self.target_db = "#{self.user}_#{self.target_db}_#{Utils.get_converted_date(self.date)}" else self.target_db = "#{self.user}_#{self.target_db}" end end |
#in_cache?(file) ⇒ Boolean
62 63 64 |
# File 'lib/dbget/dump.rb', line 62 def in_cache?(file) File.exists? file end |
#prepare ⇒ Object
29 30 31 32 |
# File 'lib/dbget/dump.rb', line 29 def prepare @backup_name = get_backup_name @encrypted_dump = get_encrypted_dump end |
#set_final_db ⇒ Object
34 35 36 |
# File 'lib/dbget/dump.rb', line 34 def set_final_db @target_db = @custom_name || @backup_name end |