Class: YOLOBackup::StoragePool::File

Inherits:
YOLOBackup::StoragePool show all
Defined in:
lib/yolo_backup/storage_pool/file.rb

Defined Under Namespace

Classes: Cleaner

Constant Summary collapse

OPTIONS =
%w{ path }

Instance Attribute Summary collapse

Attributes inherited from YOLOBackup::StoragePool

#name

Instance Method Summary collapse

Constructor Details

#initialize(name, options = nil) ⇒ File

Returns a new instance of File.



14
15
16
17
18
19
# File 'lib/yolo_backup/storage_pool/file.rb', line 14

def initialize(name, options = nil)
  super
  OPTIONS.each do |key|
    send("#{key}=", options[key]) if options[key]
  end
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



12
13
14
# File 'lib/yolo_backup/storage_pool/file.rb', line 12

def path
  @path
end

Instance Method Details

#cleanup(server) ⇒ Object



53
54
55
56
# File 'lib/yolo_backup/storage_pool/file.rb', line 53

def cleanup(server)
  cleaner = Cleaner.new(self, server)
  cleaner.cleanup
end

#initiate_backup(server) {|path| ... } ⇒ Object

Yields:



44
45
46
47
48
49
50
51
# File 'lib/yolo_backup/storage_pool/file.rb', line 44

def initiate_backup(server, &block)
  server_path = server_path(server)
  path = "#{server_path}/#{Time.now.iso8601}/"
  yield(path)
  latest_path = "#{server_path}/latest"
  ::File.unlink(latest_path) if ::File.symlink?(latest_path)
  ::File.symlink(path, latest_path)
end

#latest_backup(server) ⇒ Object



37
38
39
40
41
42
# File 'lib/yolo_backup/storage_pool/file.rb', line 37

def latest_backup(server)
  server_path = server_path(server)
  return nil unless ::File.directory?(server_path) && ::File.symlink?("#{server_path}/latest") && ::File.directory?("#{server_path}/latest")
  target = ::File.basename(::File.readlink("#{server_path}/latest"))
  Time.parse(target)
end

#ready?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/yolo_backup/storage_pool/file.rb', line 33

def ready?
  ::File.directory?(base_path) && ::File.readable?(base_path)
end

#statisticsObject



25
26
27
28
29
30
31
# File 'lib/yolo_backup/storage_pool/file.rb', line 25

def statistics
  stats = Sys::Filesystem.stat(base_path)
  {
    capacity: stats.blocks * stats.block_size,
    available: stats.blocks_available * stats.block_size
  }
end

#to_sObject



21
22
23
# File 'lib/yolo_backup/storage_pool/file.rb', line 21

def to_s
  "#{name} (#{wildcard_path})"
end