Module: Nearline
- Defined in:
- lib/nearline/log.rb,
lib/nearline/block.rb,
lib/nearline/schema.rb,
lib/nearline/system.rb,
lib/nearline/manifest.rb,
lib/nearline/file_content.rb,
lib/nearline/archived_file.rb,
lib/nearline/file_sequencer.rb,
lib/nearline/module_methods.rb,
lib/nearline/file_information.rb
Defined Under Namespace
Modules: Models, Utilities Classes: SchemaVersionException
Constant Summary collapse
- VERSION =
Version of the software
"0.1.0"
- DB_VERSION =
Last version that changed the database structure
"0.1.0"
- AR_MODELS =
Array of every Nearline Model using an ActiveRecord connection
Nearline::Models.constants.map do |m| Nearline::Models.const_get(m) end.select do |c| c.superclass == ActiveRecord::Base end
Class Method Summary collapse
-
.backup(system_name, backup_paths, backup_exclusions = []) ⇒ Object
Performs a backup labeled for system_name, Recursing through a single string or an array of backup_paths, Excluding any path matching any of the regular expressions in the backup_exclusions array or single string.
-
.connect(config = "development") ⇒ Object
Establishes a connection only to the Nearline ActiveDirectory models.
-
.connect!(config = "development") ⇒ Object
Establishes the ActiveRecord connection.
- .raise_failing_version_check ⇒ Object
-
.restore(system_name, latest_date_time = Time.now) ⇒ Object
Restore all missing files from the latest backup for system_name and backed up no later than latest_date_time.
-
.schema_version ⇒ Object
Returns the nearline version of the database.
-
.version_check? ⇒ Boolean
Returns true only if the Nearline version matches the schema.
-
.what_would_restore(system_name, latest_date_time = Time.now) ⇒ Object
Returns an array of paths that would be restored given the provided parameters.
Class Method Details
.backup(system_name, backup_paths, backup_exclusions = []) ⇒ Object
Performs a backup labeled for system_name, Recursing through a single string or an array of backup_paths, Excluding any path matching any of the regular expressions in the backup_exclusions array or single string.
Expects the Nearline database connection has already been established
Returns a Manifest for the backup
Examples
Backup my laptop, recursing my home folder, skipping .svn folders
Nearline.backup(‘my_laptop’,‘/home/me’, ‘/\.svn/’)
Backup my laptop, recurse /home/me and /var/svn
Nearline.backup(‘my_laptop’, [‘/home/me’, ‘/var/svn’])
96 97 98 99 100 101 102 103 |
# File 'lib/nearline/module_methods.rb', line 96 def backup(system_name, backup_paths,backup_exclusions= []) raise_failing_version_check Nearline::Models::System.backup( system_name, Utilities.string_to_array(backup_paths), Utilities.string_to_array(backup_exclusions) ) end |
.connect(config = "development") ⇒ Object
Establishes a connection only to the Nearline ActiveDirectory models
Will not change the ActiveRecord::Base connection
Will not establish Nearline tables in the database
Accepts a Hash to establish the connection or a String referring to an entry in config/database.yml.
Examples
Nearline.connect(=> ‘sqlite3’, :database => ‘data/sqlite.db’)
Nearline.connect ‘production’
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nearline/module_methods.rb', line 61 def connect(config="development") # These are the ActiveRecord models in place # Each one needs an explicit establish_connection # if you don't want it running though ActiveRecord::Base if (config.is_a? String) hash = YAML.load_file("config/database.yml")[config] else hash = config end AR_MODELS.each do |m| m.establish_connection(hash) end nil end |
.connect!(config = "development") ⇒ Object
Establishes the ActiveRecord connection
Accepts a Hash to establish the connection or a String referring to an entry in config/database.yml.
Will establish the Nearline database tables if they are absent.
Stomps on any ActiveRecord::Base.establish_connection you might have already established.
Examples
Nearline.connect!(=> ‘sqlite3’, :database => ‘data/sqlite.db’)
Nearline.connect! ‘production’
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nearline/module_methods.rb', line 32 def connect!(config="development") if (config.is_a? String) ActiveRecord::Base.establish_connection( YAML.load_file("config/database.yml")[config] ) elsif (config.is_a? Hash) ActiveRecord::Base.establish_connection(config) end unless Nearline::Models::Block.table_exists? Nearline::Models.generate_schema end nil end |
.raise_failing_version_check ⇒ Object
147 148 149 150 151 |
# File 'lib/nearline/module_methods.rb', line 147 def raise_failing_version_check unless version_check? raise SchemaVersionException.for_version(schema_version) end end |
.restore(system_name, latest_date_time = Time.now) ⇒ Object
Restore all missing files from the latest backup for system_name and backed up no later than latest_date_time
All modified or existing files are left alone
Expects the Nearline database connection has already been established
Returns an Array of paths restored
124 125 126 127 |
# File 'lib/nearline/module_methods.rb', line 124 def restore(system_name, latest_date_time = Time.now) raise_failing_version_check Nearline::Models::System.restore_all_missing(system_name, latest_date_time) end |
.schema_version ⇒ Object
Returns the nearline version of the database
137 138 139 140 141 142 143 144 145 |
# File 'lib/nearline/module_methods.rb', line 137 def schema_version begin return Nearline::Models::Block.connection.select_value( "select version from nearline_version" ) rescue return "" end end |
.version_check? ⇒ Boolean
Returns true only if the Nearline version matches the schema
154 155 156 |
# File 'lib/nearline/module_methods.rb', line 154 def version_check? Nearline::DB_VERSION == schema_version() end |
.what_would_restore(system_name, latest_date_time = Time.now) ⇒ Object
Returns an array of paths that would be restored given the provided parameters
131 132 133 134 |
# File 'lib/nearline/module_methods.rb', line 131 def what_would_restore(system_name, latest_date_time = Time.now) raise_failing_version_check Nearline::Models::System.what_would_restore(system_name, latest_date_time) end |