Class: SimpleBackup::Source::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_backup/source/abstract.rb

Direct Known Subclasses

Dir, File, Mysql

Constant Summary collapse

@@logger =
Utils::Logger.instance

Instance Method Summary collapse

Instance Method Details

#backends=(value) ⇒ Object



80
81
82
83
84
# File 'lib/simple_backup/source/abstract.rb', line 80

def backends=(value)
  @backends = []
  @backends = @backends + value if value.kind_of?(Array)
  @backends << value unless value.kind_of?(Array)
end

#backup_fileObject



76
77
78
# File 'lib/simple_backup/source/abstract.rb', line 76

def backup_file
  @backup_file
end

#cleanupObject



69
70
71
72
73
74
# File 'lib/simple_backup/source/abstract.rb', line 69

def cleanup
  return nil unless @backup_file

  FileUtils.rm (@backup_file)
  @@logger.debug "Temporary backup file #{@backup_file} was removed"
end

#configure(options = {}) ⇒ Object

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/simple_backup/source/abstract.rb', line 14

def configure(options = {})
  raise NotImplementedError
end

#descObject



42
43
44
# File 'lib/simple_backup/source/abstract.rb', line 42

def desc
  '%5s :: %s' % [type, @name]
end

#getObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/simple_backup/source/abstract.rb', line 46

def get
  return @backup_file if @backup_file

  @@logger.scope_start :info, "Getting archive for: #{desc}"

  @tmp_dir = ::File.join(get_tmp, "simple_backup-#{SimpleBackup::TIMESTAMP}-#{SecureRandom.uuid}")
  FileUtils.mkdir_p @tmp_dir, mode: 0700

  @@logger.debug "Created tmp directory #{@tmp_dir}"

  data_exists = prepare_data
  archive_data if data_exists

  @@logger.warning "No data for: #{desc}" unless data_exists

  FileUtils.rm_rf(@tmp_dir)
  @@logger.debug "Removed tmp directory #{@tmp_dir}"

  @backup_file
ensure
  @@logger.scope_end
end

#keep_lastObject



22
23
24
# File 'lib/simple_backup/source/abstract.rb', line 22

def keep_last
  @keep_last
end

#keep_last=(value) ⇒ Object



18
19
20
# File 'lib/simple_backup/source/abstract.rb', line 18

def keep_last=(value)
  @keep_last = value
end

#nameObject



30
31
32
# File 'lib/simple_backup/source/abstract.rb', line 30

def name
  @name
end

#name=(value) ⇒ Object



26
27
28
# File 'lib/simple_backup/source/abstract.rb', line 26

def name=(value)
  @name = value.gsub(/[^a-zA-Z0-9\-\_\. ]*/, '').gsub(/\s+/, '_').downcase
end

#supports(backend) ⇒ Object



86
87
88
89
90
91
# File 'lib/simple_backup/source/abstract.rb', line 86

def supports(backend)
  return TRUE unless @backends
  return FALSE unless @backends.include?(backend.name)

  TRUE
end

#tmp_base_path=(value) ⇒ Object



34
35
36
# File 'lib/simple_backup/source/abstract.rb', line 34

def tmp_base_path=(value)
  @tmp_base_path = value
end

#typeObject



38
39
40
# File 'lib/simple_backup/source/abstract.rb', line 38

def type
  self.class.name.split('::').last.gsub(/[^a-zA-Z0-9\-\_\. ]*/, '').gsub(/\s+/, '_').downcase
end