Class: DBGet::Dump

Inherits:
Object
  • Object
show all
Includes:
Constants, Utils
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

Instance Method Summary collapse

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_dateObject (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_nameObject

Returns the value of attribute backup_name.



11
12
13
# File 'lib/dbget/dump.rb', line 11

def backup_name
  @backup_name
end

#cleanObject (readonly)

Returns the value of attribute clean.



10
11
12
# File 'lib/dbget/dump.rb', line 10

def clean
  @clean
end

#collectionsObject

Returns the value of attribute collections.



11
12
13
# File 'lib/dbget/dump.rb', line 11

def collections
  @collections
end

#dateObject (readonly)

Returns the value of attribute date.



10
11
12
# File 'lib/dbget/dump.rb', line 10

def date
  @date
end

#dbObject (readonly)

Returns the value of attribute db.



8
9
10
# File 'lib/dbget/dump.rb', line 8

def db
  @db
end

#db_typeObject (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_dumpObject

Returns the value of attribute decrypted_dump.



11
12
13
# File 'lib/dbget/dump.rb', line 11

def decrypted_dump
  @decrypted_dump
end

#encrypted_dumpObject (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_dbObject

Returns the value of attribute target_db.



11
12
13
# File 'lib/dbget/dump.rb', line 11

def target_db
  @target_db
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/dbget/dump.rb', line 8

def user
  @user
end

#verboseObject (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_fileObject



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

Returns:

  • (Boolean)


46
47
48
# File 'lib/dbget/dump.rb', line 46

def clean?
  @clean
end

#decrypt_dumpObject



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_nameObject



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

Returns:

  • (Boolean)


62
63
64
# File 'lib/dbget/dump.rb', line 62

def in_cache?(file)
  File.exists? file
end

#prepareObject



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_dbObject



34
35
36
# File 'lib/dbget/dump.rb', line 34

def set_final_db
  @target_db = @custom_name || @backup_name
end