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



125
126
127
128
129
# File 'lib/simple_backup/source/abstract.rb', line 125

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

#backup_fileObject



121
122
123
# File 'lib/simple_backup/source/abstract.rb', line 121

def backup_file
  @backup_file
end

#cleanupObject



114
115
116
117
118
119
# File 'lib/simple_backup/source/abstract.rb', line 114

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)


59
60
61
# File 'lib/simple_backup/source/abstract.rb', line 59

def configure(options = {})
  raise NotImplementedError
end

#descObject



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

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

#getObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/simple_backup/source/abstract.rb', line 91

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



67
68
69
# File 'lib/simple_backup/source/abstract.rb', line 67

def keep_last
  @keep_last
end

#keep_last=(value) ⇒ Object



63
64
65
# File 'lib/simple_backup/source/abstract.rb', line 63

def keep_last=(value)
  @keep_last = value
end

#nameObject



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

def name
  @name
end

#name=(value) ⇒ Object



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

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

#supports(backend) ⇒ Object



131
132
133
134
135
136
# File 'lib/simple_backup/source/abstract.rb', line 131

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

  TRUE
end

#tmp_base_path=(value) ⇒ Object



79
80
81
# File 'lib/simple_backup/source/abstract.rb', line 79

def tmp_base_path=(value)
  @tmp_base_path = value
end

#typeObject



83
84
85
# File 'lib/simple_backup/source/abstract.rb', line 83

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