Class: SystemBackup

Inherits:
Object
  • Object
show all
Defined in:
lib/gatgets/dar_backup/system_backup.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backup_file, backup_folder_path, current_folder) ⇒ SystemBackup

Returns a new instance of SystemBackup.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gatgets/dar_backup/system_backup.rb', line 15

def initialize(backup_file, backup_folder_path, current_folder)
  @name      = backup_file.split('.').first
  @isolate   = has_isolate?("#{ backup_folder_path }/#{ @name }")
  @dump      = has_dump?("#{ backup_folder_path }/#{ @name }")
  @slices    = slices_for(backup_folder_path, @name)
  @size      = 0
  @slices.each do |slice|
    @size += File.size("#{ backup_folder_path }/#{ slice }")
  end
  @type      = @name.include?('complet') ? 'complet' : 'diff'
  @folder    = backup_folder_path.split('/').last
  @current   = @folder == current_folder

  @full_dar_path = "#{ backup_folder_path }/#{ @name }"

end

Instance Attribute Details

#currentObject

Returns the value of attribute current.



12
13
14
# File 'lib/gatgets/dar_backup/system_backup.rb', line 12

def current
  @current
end

#dumpObject

Returns the value of attribute dump.



9
10
11
# File 'lib/gatgets/dar_backup/system_backup.rb', line 9

def dump
  @dump
end

#folderObject

Returns the value of attribute folder.



11
12
13
# File 'lib/gatgets/dar_backup/system_backup.rb', line 11

def folder
  @folder
end

#full_dar_pathObject

Returns the value of attribute full_dar_path.



13
14
15
# File 'lib/gatgets/dar_backup/system_backup.rb', line 13

def full_dar_path
  @full_dar_path
end

#isolateObject

Returns the value of attribute isolate.



4
5
6
# File 'lib/gatgets/dar_backup/system_backup.rb', line 4

def isolate
  @isolate
end

#isolate_slicesObject

Returns the value of attribute isolate_slices.



5
6
7
# File 'lib/gatgets/dar_backup/system_backup.rb', line 5

def isolate_slices
  @isolate_slices
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/gatgets/dar_backup/system_backup.rb', line 3

def name
  @name
end

#sizeObject

Returns the value of attribute size.



7
8
9
# File 'lib/gatgets/dar_backup/system_backup.rb', line 7

def size
  @size
end

#size_niceObject

Returns the value of attribute size_nice.



8
9
10
# File 'lib/gatgets/dar_backup/system_backup.rb', line 8

def size_nice
  @size_nice
end

#slicesObject

Returns the value of attribute slices.



6
7
8
# File 'lib/gatgets/dar_backup/system_backup.rb', line 6

def slices
  @slices
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/gatgets/dar_backup/system_backup.rb', line 10

def type
  @type
end

Class Method Details

.find(how_many, path_to_search, conditions = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gatgets/dar_backup/system_backup.rb', line 33

def self.find(how_many, path_to_search, conditions = {})

  current_folder = nil
  if File.exists?("#{ path_to_search }/current")
    current_folder = File.readlink("#{ path_to_search }/current").gsub(/\//,'')
  end
  all_backups = get_backups_in(path_to_search, current_folder)
  backups     = []

  all_backups.each do |backup|
    backups << backup if SystemBackup.valid_backup_file?(backup, conditions)
  end
  if how_many == :first
    return_backups = backups.first
  elsif how_many == :last
    return_backups = backups.last
  elsif how_many == :all
    return_backups = backups
  else
    raise Gat::GatgetProcessException.new("Undefined return backups symbol #{ how_many }", "find")
  end

  return_backups
end

Instance Method Details

#search_pattern(pattern) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gatgets/dar_backup/system_backup.rb', line 59

def search_pattern(pattern)
  unless self.has_dump?(self.full_dar_path)
    raise  Gat::GatgetProcessException.new("Unable to search_pattern withour dump. Create it first", "search_pattern")
  end

  results = ''

  dump_file = File.open("#{ self.full_dar_path }_dump", "r")

  dump_file.each_line do |line|
    if line.include?(pattern)
      results << line
    end
  end

  results
end