class ForemanMaintain::Utils::Backup
Attributes
foreman_offline_files[RW]
foreman_online_files[RW]
fpc_offline_files[RW]
fpc_online_files[RW]
katello_offline_files[RW]
katello_online_files[RW]
standard_files[RW]
Public Class Methods
new(backup_dir)
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 14 def initialize(backup_dir) # fpc stands for foreman proxy w/ content @backup_dir = backup_dir @standard_files = ['config_files.tar.gz'] @foreman_online_files = ['foreman.dump'] @foreman_offline_files = ['pgsql_data.tar.gz'] @katello_online_files = @foreman_online_files + ['candlepin.dump', 'pulpcore.dump'] @katello_offline_files = ['pgsql_data.tar.gz'] @fpc_online_files = ['pulpcore.dump'] @fpc_offline_files = ['pgsql_data.tar.gz'] end
Public Instance Methods
check_backup()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 56 def check_backup if feature(:instance).foreman_proxy_with_content? valid_fpc_backup? elsif feature(:katello) valid_katello_backup? else valid_foreman_backup? end end
check_file_existence(existence_map)
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 81 def check_file_existence(existence_map) existence_map[:present].each do |file| unless file_map[file][:present] return false end end existence_map[:absent].each do |file| if file_map[file][:present] return false end end true end
different_source_os?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 273 def different_source_os? source_os_version != "#{os_name} #{os_version}" end
dumps_for_hybrid_db_setup(dbs_hash)
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 165 def dumps_for_hybrid_db_setup(dbs_hash) present = [] absent = [] dbs_hash.each do |data_file, dbs| dbs.each do |db| feature_label = "#{db}_database" dump_file = "#{db}_dump" if feature(feature_label.to_sym).local? present |= [data_file] absent << dump_file.to_sym else present << dump_file.to_sym end end absent |= [data_file] unless present.include?(data_file) end [present, absent] end
file_map()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 26 def file_map @file_map ||= { :pgsql_data => map_file(@backup_dir, 'pgsql_data.tar.gz'), :pulp_data => map_file(@backup_dir, 'pulp_data.tar'), :foreman_dump => map_file(@backup_dir, 'foreman.dump'), :candlepin_dump => map_file(@backup_dir, 'candlepin.dump'), :config_files => map_file(@backup_dir, 'config_files.tar.gz'), :metadata => map_file(@backup_dir, 'metadata.yml'), :pulpcore_dump => map_file(@backup_dir, 'pulpcore.dump'), } end
foreman_logical_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 160 def foreman_logical_backup? check_file_existence(:present => [:pgsql_data, :foreman_dump], :absent => [:candlepin_dump, :pulpcore_dump]) end
foreman_online_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 155 def foreman_online_backup? check_file_existence(:present => [:foreman_dump], :absent => [:candlepin_dump, :pgsql_data, :pulpcore_dump]) end
foreman_standard_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 150 def foreman_standard_backup? check_file_existence(:present => [:pgsql_data], :absent => [:candlepin_dump, :foreman_dump, :pulpcore_dump]) end
fpc_hybrid_db_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 143 def fpc_hybrid_db_backup? all_dbs = { :pgsql_data => ['pulpcore'] } present, absent = dumps_for_hybrid_db_setup(all_dbs) absent.concat [:candlepin_dump, :foreman_dump] check_file_existence(:present => present, :absent => absent) end
fpc_logical_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 137 def fpc_logical_backup? present = [:pulpcore_dump, :pgsql_data] absent = [:candlepin_dump, :foreman_dump] check_file_existence(:present => present, :absent => absent) end
fpc_online_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 131 def fpc_online_backup? present = [:pulpcore_dump] absent = [:pgsql_data, :candlepin_dump, :foreman_dump] check_file_existence(:present => present, :absent => absent) end
fpc_standard_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 124 def fpc_standard_backup? present = [:pgsql_data] absent = [:candlepin_dump, :foreman_dump, :pulpcore_dump] check_file_existence(:present => present, :absent => absent) end
incremental?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 249 def incremental? !!metadata.fetch('incremental', false) end
installed_rpms()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 257 def installed_rpms metadata.fetch('rpms', metadata.fetch(:rpms, [])) end
katello_hybrid_db_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 118 def katello_hybrid_db_backup? all_dbs = { :pgsql_data => %w[candlepin foreman pulpcore] } present, absent = dumps_for_hybrid_db_setup(all_dbs) check_file_existence(:present => present, :absent => absent) end
katello_logical_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 111 def katello_logical_backup? present = [:pgsql_data, :candlepin_dump, :foreman_dump, :pulpcore_dump] absent = [] check_file_existence(:present => present, :absent => absent) end
katello_online_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 104 def katello_online_backup? present = [:candlepin_dump, :foreman_dump, :pulpcore_dump] absent = [:pgsql_data] check_file_existence(:present => present, :absent => absent) end
katello_standard_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 97 def katello_standard_backup? present = [:pgsql_data] absent = [:candlepin_dump, :foreman_dump, :pulpcore_dump] check_file_existence(:present => present, :absent => absent) end
map_file(backup_dir, filename)
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 38 def map_file(backup_dir, filename) file_path = File.join(backup_dir, filename) present = File.exist?(file_path) { :present => present, :path => file_path, } end
metadata()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 226 def metadata if file_map[:metadata][:present] YAML.load_file(file_map[:metadata][:path]) else {} end end
online_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 253 def online_backup? !!metadata.fetch('online', false) end
present_files()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 47 def present_files present_files = file_map.select { |_k, v| v[:present] } present_files.values.map { |f| File.basename(f[:path]) } end
pulp_tar_split?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 234 def pulp_tar_split? File.exist?(File.join(@backup_dir, 'pulp_data.part0002')) end
source_os_version()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 269 def source_os_version metadata.fetch('os_version', 'unknown') end
sql_dump_files_exist?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 243 def sql_dump_files_exist? file_map[:foreman_dump][:present] || file_map[:candlepin_dump][:present] || (feature(:pulpcore_database) && file_map[:pulpcore_dump][:present]) end
tar_backups_exist?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 238 def tar_backups_exist? file_map[:pulp_data][:present] || file_map[:pgsql_data][:present] end
valid_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 52 def valid_backup? file_map[:config_files][:present] && check_backup end
valid_foreman_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 77 def valid_foreman_backup? foreman_standard_backup? || foreman_online_backup? || foreman_logical_backup? end
valid_fpc_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 66 def valid_fpc_backup? fpc_online_backup? || fpc_standard_backup? || fpc_logical_backup? || \ fpc_hybrid_db_backup? end
valid_katello_backup?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 71 def valid_katello_backup? katello_online_backup? || katello_standard_backup? || katello_logical_backup? || \ # Katello can have setup where some of dbs are external but not all katello_hybrid_db_backup? end
validate_hostname?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 184 def validate_hostname? # make sure that the system hostname is the same as the backup hostname_from_metadata = metadata.fetch('hostname', nil) if hostname_from_metadata hostname_from_metadata == hostname else config_tarball = file_map[:config_files][:path] tar_cmd = "tar zxf #{config_tarball} etc/httpd/conf/httpd.conf --to-stdout --occurrence=1" status, httpd_config = execute_with_status(tar_cmd) # Incremental backups sometimes don't include httpd.conf. Since a "base" backup # is restored before an incremental, we can assume that the hostname is checked # during the base backup restore if status == 0 match = httpd_config.match(/\s*ServerName\s+"*([^ "]+)"*\s*$/) match ? match[1] == hostname : false else true end end end
validate_interfaces()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 206 def validate_interfaces # I wanted to do `Socket.getifaddrs.map(&:name).uniq`, # but this has to work with Ruby 2.0, and Socket.getifaddrs is 2.1+ errors = {} system_interfaces = Dir.entries('/sys/class/net') - ['.', '..'] proxy_config = metadata.fetch('proxy_config', {}) %w[dns dhcp].each do |feature| next unless proxy_config.fetch(feature, false) wanted_interface = proxy_config.fetch("#{feature}_interface", 'lo') unless system_interfaces.include?(wanted_interface) errors[feature] = { 'configured' => wanted_interface, 'available' => system_interfaces } end end return errors end
with_puppetserver?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 261 def with_puppetserver? installed_rpms.any? { |rpm| rpm.start_with?('puppetserver-') } end
with_qpidd?()
click to toggle source
# File lib/foreman_maintain/utils/backup.rb, line 265 def with_qpidd? installed_rpms.any? { |rpm| rpm.start_with?('qpid-cpp-server-') } end