Class: Backup::Instance
- Inherits:
-
Object
- Object
- Backup::Instance
- Defined in:
- lib/backup.rb
Instance Attribute Summary collapse
-
#file_item ⇒ Object
readonly
Returns the value of attribute file_item.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #create!(local_path, increment = false) ⇒ Object
-
#initialize(root_path, cloud = false, *args) ⇒ Instance
constructor
A new instance of Instance.
- #jar_versions(jar) ⇒ Object
- #jars ⇒ Object
- #key=(path) ⇒ Object
- #restore_jar_to(hash, timestamp, to) ⇒ Object
Constructor Details
#initialize(root_path, cloud = false, *args) ⇒ Instance
Returns a new instance of Instance.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/backup.rb', line 10 def initialize(root_path, cloud = false, *args) if cloud @file_item = Backup::FileItem.for :cloud, *args else @file_item = Backup::FileItem.for :local end @hostname = Socket.gethostname @root_path = "#{root_path}/#{@hostname}" @timestamp = Backup::Timestamp.create end |
Instance Attribute Details
#file_item ⇒ Object (readonly)
Returns the value of attribute file_item.
8 9 10 |
# File 'lib/backup.rb', line 8 def file_item @file_item end |
#hostname ⇒ Object
Returns the value of attribute hostname.
8 9 10 |
# File 'lib/backup.rb', line 8 def hostname @hostname end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
8 9 10 |
# File 'lib/backup.rb', line 8 def root_path @root_path end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
8 9 10 |
# File 'lib/backup.rb', line 8 def @timestamp end |
Instance Method Details
#create!(local_path, increment = false) ⇒ Object
31 32 33 34 |
# File 'lib/backup.rb', line 31 def create!(local_path, increment = false) jar = Jar.new(@file_item, @root_path, local_path) jar.save(increment) end |
#jar_versions(jar) ⇒ Object
40 41 42 |
# File 'lib/backup.rb', line 40 def jar_versions(jar) Jar.jar_versions(@file_item, @root_path, jar, !!jar[/^[0-9a-z]{32}$/]) end |
#jars ⇒ Object
36 37 38 |
# File 'lib/backup.rb', line 36 def jars Jar.all(@file_item, @root_path) end |
#key=(path) ⇒ Object
27 28 29 |
# File 'lib/backup.rb', line 27 def key=(path) @key = open(path).read end |
#restore_jar_to(hash, timestamp, to) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/backup.rb', line 44 def restore_jar_to(hash, , to) files = Jar.fetch_index_for(@file_item, @root_path, hash, ) files.keys.sort.each do |file| restore_file = File.join(to, file) current_file = files[file] if current_file[:checksum].nil? try_create_dir restore_file File.chmod current_file[:mode], restore_file File.chown current_file[:uid], current_file[:gid], restore_file file_ok = @file_item.stat(restore_file)[restore_file] check_mode(restore_file, file_ok[:mode], current_file[:mode]) check_rights( restore_file, file_ok[:uid], file_ok[:gid], current_file[:uid], current_file[:gid] ) else try_create_dir(File.dirname restore_file) begin File.open(restore_file, "w") do |f| f.chmod current_file[:mode] f.chown current_file[:uid], current_file[:gid] remote_path = "#{@root_path}/#{hash}/#{current_file[:timestamp]}" remote_path += "/#{@file_item.file_hash file}" data = @file_item.read_file remote_path f.puts data end file_ok = @file_item.stat(restore_file)[restore_file] check_mode(restore_file, file_ok[:mode], current_file[:mode]) check_rights( restore_file, file_ok[:uid], file_ok[:gid], current_file[:uid], current_file[:gid] ) rescue Errno::EACCES puts_fail "Permission denied for #{restore_file.dark_green}" end end end end |