Class: SimpleBackup::Backend::Local

Inherits:
Abstract
  • Object
show all
Defined in:
lib/simple_backup/backend/local.rb

Instance Method Summary collapse

Methods inherited from Abstract

#desc, #name, #name=, #type

Instance Method Details

#cleanup(source) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/simple_backup/backend/local.rb', line 19

def cleanup(source)
  storage_path = get_storage_path(source)

  files = ::Dir.glob(::File.join(storage_path, '*.tar.gz')).sort

  to_persist = files
  to_persist = files.slice(source.keep_last * -1, source.keep_last) if files.length > source.keep_last
  to_remove = files - to_persist

  @@logger.scope_start
  to_remove.each do |file|
    FileUtils.rm(file)
    @@logger.debug "Old backup '#{file}' for source '#{source.desc.strip}' cleaned up from '#{desc.strip}'"
  end
  @@logger.scope_end
end

#configure(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/simple_backup/backend/local.rb', line 4

def configure(options = {})
  raise "Must provide :path option" unless options[:path]

  @path = options[:path]

  raise "#{@path} does not exists" unless ::File.exist?(@path)
  raise "#{@path} is not a directory" unless ::File.directory?(@path)
  raise "#{@path} is not writable" unless ::File.writable?(@path)
end

#store(source) ⇒ Object



14
15
16
17
# File 'lib/simple_backup/backend/local.rb', line 14

def store(source)
  storage_path = get_storage_path(source)
  FileUtils.cp source.backup_file, storage_path
end