Class: Nearline::Models::Manifest
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Nearline::Models::Manifest
- Defined in:
- lib/nearline/manifest.rb
Overview
A Manifest represents the corpus of ArchivedFiles and set of Log messages resulting from a backup attempt
Instance Attribute Summary collapse
-
#backup_exclusions ⇒ Object
Just needed when you create a manifest.
-
#backup_paths ⇒ Object
Just needed when you create a manifest.
Class Method Summary collapse
-
.backup(system_name, backup_paths, backup_exclusions) ⇒ Object
Underlying implementation of Nearline.backup.
-
.incomplete_manifests ⇒ Object
Find all Manifest entries which have never finished.
-
.latest_for(system_name) ⇒ Object
Find the latest Manifest for a system.
- .restore_all_missing(system_name) ⇒ Object
Instance Method Summary collapse
- #add_log(message) ⇒ Object
- #before_destroy ⇒ Object
-
#restore_all_missing ⇒ Object
Restore all missing files from this manifest back to the filesystem.
-
#summary ⇒ Object
A simple string reporting the performance of the manifest.
- #total_size ⇒ Object
Instance Attribute Details
#backup_exclusions ⇒ Object
Just needed when you create a manifest
29 30 31 |
# File 'lib/nearline/manifest.rb', line 29 def backup_exclusions @backup_exclusions end |
#backup_paths ⇒ Object
Just needed when you create a manifest
27 28 29 |
# File 'lib/nearline/manifest.rb', line 27 def backup_paths @backup_paths end |
Class Method Details
.backup(system_name, backup_paths, backup_exclusions) ⇒ Object
Underlying implementation of Nearline.backup
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/nearline/manifest.rb', line 32 def self.backup(system_name, backup_paths, backup_exclusions) manifest = self.new(:system_name => system_name) manifest.save! FileFinder.recurse(backup_paths, backup_exclusions) do |file_name| $stdout.write file_name + " " af = ArchivedFile.create_for(file_name, manifest) if (!af.nil?) manifest.archived_files << af $stdout.write "#{Time.at(af.mtime).asctime}" if (!af.file_content.nil?) $stdout.write" (#{af.file_content.file_size} bytes)" end $stdout.write("\n") end end manifest.completed_at = Time.now manifest.save! manifest end |
.incomplete_manifests ⇒ Object
Find all Manifest entries which have never finished.
They are:
-
Currently under-way
-
Have failed in some untimely way
66 67 68 |
# File 'lib/nearline/manifest.rb', line 66 def self.incomplete_manifests self.find_all_by_completed_at(nil) end |
.latest_for(system_name) ⇒ Object
Find the latest Manifest for a system
55 56 57 58 59 |
# File 'lib/nearline/manifest.rb', line 55 def self.latest_for(system_name) m_result = self.connection.select_one("select id from manifests where system_name='#{system_name}' order by created_at desc") raise "No manifest found" if m_result.nil? self.find(m_result["id"]) end |
.restore_all_missing(system_name) ⇒ Object
70 71 72 73 |
# File 'lib/nearline/manifest.rb', line 70 def self.restore_all_missing(system_name) manifest = latest_for(system_name) manifest.restore_all_missing end |
Instance Method Details
#add_log(message) ⇒ Object
89 90 91 92 93 |
# File 'lib/nearline/manifest.rb', line 89 def add_log() puts log = Nearline::Models::Log.new({:message => , :manifest_id => self.id}) log.save! end |
#before_destroy ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/nearline/manifest.rb', line 95 def before_destroy archived_files.each do |af| af.orphan_check end logs.each do |log| log.destroy end end |
#restore_all_missing ⇒ Object
Restore all missing files from this manifest back to the filesystem
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/nearline/manifest.rb', line 76 def restore_all_missing files_restored = [] self.archived_files.each do |af| begin File.stat(af.path) rescue af.restore files_restored << af.path end end return files_restored end |
#summary ⇒ Object
A simple string reporting the performance of the manifest
115 116 117 118 119 |
# File 'lib/nearline/manifest.rb', line 115 def summary completed = (completed_at.nil?) ? "DNF" : completed_at "#{system_name}; started: #{created_at}; finished: #{completed}; " + "#{archived_files.size} files; #{logs.size} Errors reported" end |
#total_size ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/nearline/manifest.rb', line 104 def total_size size = 0 archived_files.each do |af| unless af.file_content.nil? size += af.file_content.file_size.to_i end end size end |