Class: BackupMinister::Server
- Inherits:
-
BackupMinister
- Object
- BackupMinister
- BackupMinister::Server
- Defined in:
- lib/backup_minister/server.rb
Instance Method Summary collapse
-
#location_accessible? ⇒ Bool
Is it possible to wright to target backups location?.
- #place_database_backup(project_name, backup_file_path, project_config = {}) ⇒ Object
-
#place_file(file, location) ⇒ Object
Place file to directory.
-
#project_files_location(project_name, project_config = {}) ⇒ String?
Path to project directory for files.
-
#project_location(project_name, project_config = {}) ⇒ String?
Path to root project’s directory.
Methods inherited from BackupMinister
#backup_minister_installed?, #create_nested_directory, #execute, #execute_with_result, #file_sha256_hash, #initialize, #project_config, #software_installed?, #system_config
Constructor Details
This class inherits a constructor from BackupMinister
Instance Method Details
#location_accessible? ⇒ Bool
Is it possible to wright to target backups location?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/backup_minister/server.rb', line 6 def location_accessible? result = false location = system_config('server', 'location') if location.nil? LOGGER.error 'Location path is not set.' else if File.directory?(location) LOGGER.debug "Directory `#{location}` exists." result = true else LOGGER.debug "Directory `#{location}` doesn't exists. Will try to create it." result = create_nested_directory(location) end end result end |
#place_database_backup(project_name, backup_file_path, project_config = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/backup_minister/server.rb', line 28 def place_database_backup(project_name, backup_file_path, project_config = {}) return false unless location_accessible? result = false project_location = project_location(project_name, project_config) result = place_file(backup_file_path, "#{project_location}/database") if project_location result end |
#place_file(file, location) ⇒ Object
Place file to directory
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/backup_minister/server.rb', line 42 def place_file(file, location) result = false if File.exist?(file) if File.directory?(location) or create_nested_directory(location) begin FileUtils.move file, location LOGGER.debug "File #{file} moved to #{location}." result = true rescue Error => error LOGGER.warn "Can't move file with error: #{error.}." end end else LOGGER.warn "No such file #{file}." end result end |
#project_files_location(project_name, project_config = {}) ⇒ String?
Path to project directory for files
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/backup_minister/server.rb', line 93 def project_files_location(project_name, project_config = {}) result = nil project_dir = project_location(project_name, project_config) if project_dir files_path = '/files' full_files_path = project_dir + files_path result = full_files_path if File.directory?(full_files_path) or create_nested_directory(full_files_path) end result end |
#project_location(project_name, project_config = {}) ⇒ String?
Path to root project’s directory
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/backup_minister/server.rb', line 69 def project_location(project_name, project_config = {}) result = nil project_dir = project_config['remote_project_location'] || project_name.underscore project_dir = /[^\/]([a-zA-Z0-9\-_])+([\/])?\z/.match(project_dir).to_a.first if project_dir project_full_path = system_config('server', 'location') + '/' + project_dir if File.directory?(project_full_path) or create_nested_directory(project_full_path) LOGGER.debug "Project location is #{project_full_path}." result = project_full_path end else LOGGER.error "Could not get project location for #{project_name}." end result end |