Class: TarsnapPruner::Machine
- Inherits:
-
Object
- Object
- TarsnapPruner::Machine
- Defined in:
- lib/tarsnap_pruner/machine.rb
Overview
An instance of this class represents one machine that’s being backed up.
Instance Attribute Summary collapse
-
#key_file ⇒ Object
readonly
Returns the value of attribute key_file.
Class Method Summary collapse
Instance Method Summary collapse
- #archives ⇒ Object
- #delete(archives_to_delete) ⇒ Object
- #hostname ⇒ Object
-
#initialize(key_file, tarsnap = nil) ⇒ Machine
constructor
A new instance of Machine.
Constructor Details
Instance Attribute Details
#key_file ⇒ Object (readonly)
Returns the value of attribute key_file.
21 22 23 |
# File 'lib/tarsnap_pruner/machine.rb', line 21 def key_file @key_file end |
Class Method Details
.all ⇒ Object
12 13 14 |
# File 'lib/tarsnap_pruner/machine.rb', line 12 def self.all key_files.map { |f| new(f) } end |
.key_files ⇒ Object
8 9 10 |
# File 'lib/tarsnap_pruner/machine.rb', line 8 def self.key_files Dir.glob(File.join(ENV['KEY_DIRECTORY'], '*.key')).sort end |
Instance Method Details
#archives ⇒ Object
27 28 29 |
# File 'lib/tarsnap_pruner/machine.rb', line 27 def archives @tarsnap.list_archives.split.sort.map { |name| Archive.new(name) } end |
#delete(archives_to_delete) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tarsnap_pruner/machine.rb', line 31 def delete(archives_to_delete) if archives_to_delete.any? Dir.mktmpdir("cache-", ENV['CACHES_DIRECTORY']) do |cache_directory| # fsck so that we have an up-to-date cache (required for pruning). This # means that each machine will have to fsck again, but there's apparently # no way around it. # Ref: http://mail.tarsnap.com/tarsnap-users/msg00512.html @tarsnap.fsck(cache_directory) archives_to_delete.each do |archive| @tarsnap.delete(archive, cache_directory) end end end end |
#hostname ⇒ Object
23 24 25 |
# File 'lib/tarsnap_pruner/machine.rb', line 23 def hostname key_file =~ /tarsnap-(.*)\.key$/ ? $1 : 'unknown' end |