Class: Backs3::Restore
- Inherits:
-
Object
show all
- Includes:
- Backs3, Storage
- Defined in:
- lib/backs3/restore.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Backs3
#load_backup_info, #logger, #md5, #save_backup_info
Constructor Details
#initialize(options = {}) ⇒ Restore
Returns a new instance of Restore.
13
14
15
16
17
|
# File 'lib/backs3/restore.rb', line 13
def initialize(options = {})
@options = options
@options['prefix'] ||= ''
@backups = load_backup_info.sort{|a,b| a.date <=> b.date }
end
|
Class Method Details
.commands ⇒ Object
9
10
11
|
# File 'lib/backs3/restore.rb', line 9
def self.commands
%w(ls available restore cat info)
end
|
Instance Method Details
#available(backup_key = nil) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/backs3/restore.rb', line 19
def available(backup_key = nil)
if backup_key.nil?
puts "Backups available: #{@backups.map{|b| b.date}.join(", ")}"
else
unless backup = @backups.detect{|b| b.date.to_s == backup_key.to_s }
raise "No backup #{backup_key} available"
end
files = backup.all_files
puts "Backup information for #{backup.date}"
files.each do |file|
puts "\tFile: #{file.path}, backed up #{Time.at(file.backup_info.date).to_s}"
end
end
end
|
#cat(date, name) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/backs3/restore.rb', line 56
def cat(date, name)
backup = @backups.detect{|b| b.date.to_s == date.to_s}
raise "Cannot find backup #{date}" unless backup
file = backup.all_files.detect{|f| f.path == name}
raise "Cannot find file #{name}" unless file
puts storage.read(File.join(backup.date.to_s, name))
end
|
#info(file) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/backs3/restore.rb', line 36
def info(file)
files = @backups.collect{|b| b.files}.flatten.select{|f| f.path == file}
if files.empty?
puts "No information found for file #{file}"
else
puts "Backup information for file #{file}"
files.each do |f|
puts "\tBacked up #{Time.at(f.backup_info.date).to_s} in #{f.backup_info.date} with md5sum #{f.md5sum}"
end
end
end
|
#ls(backup) ⇒ Object
50
51
52
53
54
|
# File 'lib/backs3/restore.rb', line 50
def ls(backup)
storage.list(backup).each do |name|
puts name
end
end
|
#restore(date, file = nil) ⇒ Object
64
65
66
67
68
|
# File 'lib/backs3/restore.rb', line 64
def restore(date, file = nil)
backup = @backups.detect{|b| b.date.to_s == date.to_s}
raise 'Cannot find backup %s' % date if backup.nil?
backup.restore('/tmp', file)
end
|