Class: StellarCoreBackup::Utils
- Inherits:
-
Object
- Object
- StellarCoreBackup::Utils
- Includes:
- Contracts
- Defined in:
- lib/stellar-core-backup/utils.rb
Class Method Summary collapse
- .cleanbucket(bucket_dir) ⇒ Object
- .cleanup(working_dir) ⇒ Object
- .confirm_shasums_definitive(working_dir, backup_archive) ⇒ Object
- .create_backup_dir(dir) ⇒ Object
- .create_backup_tar(working_dir, backup_dir) ⇒ Object
- .create_working_dir(dir) ⇒ Object
- .num_cores? ⇒ Boolean
- .readable?(file) ⇒ Boolean
- .remove_working_dir(working_dir) ⇒ Object
- .writable?(file) ⇒ Boolean
Instance Method Summary collapse
- #extract_backup(backup_archive) ⇒ Object
-
#initialize(config) ⇒ Utils
constructor
A new instance of Utils.
Constructor Details
#initialize(config) ⇒ Utils
Returns a new instance of Utils.
8 9 10 11 12 13 |
# File 'lib/stellar-core-backup/utils.rb', line 8 def initialize(config) @config = config @working_dir = StellarCoreBackup::Utils.create_working_dir(@config.get('working_dir')) @db_restore = StellarCoreBackup::Restore::Database.new(@config) @fs_restore = StellarCoreBackup::Restore::Filesystem.new(@config) end |
Class Method Details
.cleanbucket(bucket_dir) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/stellar-core-backup/utils.rb', line 63 def self.cleanbucket(bucket_dir) if FileUtils.remove(Dir.glob(bucket_dir+'/*')) then puts 'info: cleaning up workspace' return true else return false end end |
.cleanup(working_dir) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/stellar-core-backup/utils.rb', line 73 def self.cleanup(working_dir) if FileUtils.remove_dir(working_dir) then puts 'info: cleaning up workspace' return true else return false end end |
.confirm_shasums_definitive(working_dir, backup_archive) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/stellar-core-backup/utils.rb', line 83 def self.confirm_shasums_definitive(working_dir, backup_archive) # create an array of filesunpacked into the working_dir Dir.chdir(working_dir) files_present=Dir.glob('./**/*') # remove directories and shasum details from file array files_present.delete('./'+File.basename(backup_archive)) files_present.delete('./core-db') files_present.delete('./SHA256SUMS') files_present.delete('./SHA256SUMS.sig') # now delete the file names in the shasums file from the array # we are expecting an array of zero length after this process File.open("SHA256SUMS").each { |sha_file| files_present.delete(sha_file.split(' ')[1].chomp) } if files_present.none? then return true else return false end end |
.create_backup_dir(dir) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/stellar-core-backup/utils.rb', line 32 def self.create_backup_dir(dir) unless Dir.exists?(dir) then Dir.mkdir dir end return dir end |
.create_backup_tar(working_dir, backup_dir) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/stellar-core-backup/utils.rb', line 40 def self.create_backup_tar(working_dir, backup_dir) puts 'info: creating backup tarball' tar_file = "#{backup_dir}/core-backup-#{Time.now.to_i}.tar" Dir.chdir(working_dir) # archive the working directory StellarCoreBackup::Tar.pack(tar_file, '.') return tar_file end |
.create_working_dir(dir) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/stellar-core-backup/utils.rb', line 16 def self.create_working_dir(dir) working_dir = dir + "/#{Process.pid}" unless Dir.exists?(working_dir) then Dir.mkdir working_dir end return working_dir end |
.num_cores? ⇒ Boolean
131 132 133 134 |
# File 'lib/stellar-core-backup/utils.rb', line 131 def self.num_cores?() require 'etc' return Etc.nprocessors end |
.readable?(file) ⇒ Boolean
107 108 109 110 111 112 113 114 115 |
# File 'lib/stellar-core-backup/utils.rb', line 107 def self.readable?(file) if File.readable?(file) then puts "info: #{file} readable" return true else puts "error: cannot read #{file}" raise Errno::EACCES end end |
.remove_working_dir(working_dir) ⇒ Object
25 26 27 28 29 |
# File 'lib/stellar-core-backup/utils.rb', line 25 def self.remove_working_dir(working_dir) if Dir.exists?(working_dir) then Dir.rmdir working_dir + "/#{Process.pid}" end end |
.writable?(file) ⇒ Boolean
119 120 121 122 123 124 125 126 127 |
# File 'lib/stellar-core-backup/utils.rb', line 119 def self.writable?(file) if File.writable?(file) then puts "info: #{file} writeable" return true else puts "error: cannot write to #{file}" raise Errno::EACCES end end |
Instance Method Details
#extract_backup(backup_archive) ⇒ Object
50 51 52 53 54 |
# File 'lib/stellar-core-backup/utils.rb', line 50 def extract_backup(backup_archive) # extract the backup archive into the working directory StellarCoreBackup::Tar.unpack(backup_archive, @working_dir) return end |