Class: ForemanMaintain::Utils::Backup
Constant Summary
collapse
- ONLINE_BACKUP =
'online'.freeze
- OFFLINE_BACKUP =
'offline'.freeze
Concerns::OsFacts::FALLBACK_OS_RELEASE_FILE, Concerns::OsFacts::OS_RELEASE_FILE
Instance Attribute Summary collapse
Instance Method Summary
collapse
#check_max_version, #check_min_version, #command_present?, #directory_empty?, #execute, #execute!, #execute?, #execute_runner, #execute_with_status, #file_exists?, #file_nonzero?, #find_dir_containing_file, #find_package, #find_symlinks, #foreman_plugin_name, #format_shell_args, #hammer_package, #hammer_plugin_name, #hostname, included, #package_manager, #package_version, #packages_action, #parse_csv, #parse_json, #proxy_plugin_name, #repository_manager, #ruby_prefix, #server?, #shellescape, #systemd_installed?, #version
#centos?, #cpu_cores, #deb_major_version, #debian?, #debian_or_ubuntu?, #el8?, #el?, #el_major_version, #el_short_name, #facts, #memory, #os_id, #os_id_like_list, #os_name, #os_release_file, #os_version, #os_version_codename, #os_version_id, #rhel?, #ubuntu?, #ubuntu_major_version
#check, #detector, #feature, #find_all_scenarios, #find_procedures, #find_scenarios, #procedure
#logger
Constructor Details
#initialize(backup_dir) ⇒ Backup
Returns a new instance of Backup.
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/foreman_maintain/utils/backup.rb', line 17
def initialize(backup_dir)
@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
|
Instance Attribute Details
#foreman_offline_files ⇒ Object
Returns the value of attribute foreman_offline_files.
10
11
12
|
# File 'lib/foreman_maintain/utils/backup.rb', line 10
def foreman_offline_files
@foreman_offline_files
end
|
#foreman_online_files ⇒ Object
Returns the value of attribute foreman_online_files.
10
11
12
|
# File 'lib/foreman_maintain/utils/backup.rb', line 10
def foreman_online_files
@foreman_online_files
end
|
#fpc_offline_files ⇒ Object
Returns the value of attribute fpc_offline_files.
10
11
12
|
# File 'lib/foreman_maintain/utils/backup.rb', line 10
def fpc_offline_files
@fpc_offline_files
end
|
#fpc_online_files ⇒ Object
Returns the value of attribute fpc_online_files.
10
11
12
|
# File 'lib/foreman_maintain/utils/backup.rb', line 10
def fpc_online_files
@fpc_online_files
end
|
#katello_offline_files ⇒ Object
Returns the value of attribute katello_offline_files.
10
11
12
|
# File 'lib/foreman_maintain/utils/backup.rb', line 10
def katello_offline_files
@katello_offline_files
end
|
#katello_online_files ⇒ Object
Returns the value of attribute katello_online_files.
10
11
12
|
# File 'lib/foreman_maintain/utils/backup.rb', line 10
def katello_online_files
@katello_online_files
end
|
#standard_files ⇒ Object
Returns the value of attribute standard_files.
10
11
12
|
# File 'lib/foreman_maintain/utils/backup.rb', line 10
def standard_files
@standard_files
end
|
Instance Method Details
#backup_type ⇒ Object
267
268
269
|
# File 'lib/foreman_maintain/utils/backup.rb', line 267
def backup_type
online_backup? ? ONLINE_BACKUP : OFFLINE_BACKUP
end
|
#check_backup ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/foreman_maintain/utils/backup.rb', line 59
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) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/foreman_maintain/utils/backup.rb', line 84
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? ⇒ Boolean
263
264
265
|
# File 'lib/foreman_maintain/utils/backup.rb', line 263
def different_source_os?
source_os_version != "#{os_name} #{os_version}"
end
|
#dumps_for_hybrid_db_setup(dbs_hash) ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/foreman_maintain/utils/backup.rb', line 168
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 ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/foreman_maintain/utils/backup.rb', line 29
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? ⇒ Boolean
163
164
165
166
|
# File 'lib/foreman_maintain/utils/backup.rb', line 163
def foreman_logical_backup?
check_file_existence(:present => [:pgsql_data, :foreman_dump],
:absent => [:candlepin_dump, :pulpcore_dump])
end
|
#foreman_online_backup? ⇒ Boolean
158
159
160
161
|
# File 'lib/foreman_maintain/utils/backup.rb', line 158
def foreman_online_backup?
check_file_existence(:present => [:foreman_dump],
:absent => [:candlepin_dump, :pgsql_data, :pulpcore_dump])
end
|
#foreman_standard_backup? ⇒ Boolean
153
154
155
156
|
# File 'lib/foreman_maintain/utils/backup.rb', line 153
def foreman_standard_backup?
check_file_existence(:present => [:pgsql_data],
:absent => [:candlepin_dump, :foreman_dump, :pulpcore_dump])
end
|
#fpc_hybrid_db_backup? ⇒ Boolean
146
147
148
149
150
151
|
# File 'lib/foreman_maintain/utils/backup.rb', line 146
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? ⇒ Boolean
140
141
142
143
144
|
# File 'lib/foreman_maintain/utils/backup.rb', line 140
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? ⇒ Boolean
134
135
136
137
138
|
# File 'lib/foreman_maintain/utils/backup.rb', line 134
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? ⇒ Boolean
127
128
129
130
131
132
|
# File 'lib/foreman_maintain/utils/backup.rb', line 127
def fpc_standard_backup?
present = [:pgsql_data]
absent = [:candlepin_dump, :foreman_dump, :pulpcore_dump]
check_file_existence(:present => present,
:absent => absent)
end
|
#incremental? ⇒ Boolean
243
244
245
|
# File 'lib/foreman_maintain/utils/backup.rb', line 243
def incremental?
!!metadata.fetch('incremental', false)
end
|
#installed_rpms ⇒ Object
251
252
253
|
# File 'lib/foreman_maintain/utils/backup.rb', line 251
def installed_rpms
metadata.fetch('rpms', metadata.fetch(:rpms, []))
end
|
#katello_hybrid_db_backup? ⇒ Boolean
121
122
123
124
125
|
# File 'lib/foreman_maintain/utils/backup.rb', line 121
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? ⇒ Boolean
114
115
116
117
118
119
|
# File 'lib/foreman_maintain/utils/backup.rb', line 114
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? ⇒ Boolean
107
108
109
110
111
112
|
# File 'lib/foreman_maintain/utils/backup.rb', line 107
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? ⇒ Boolean
100
101
102
103
104
105
|
# File 'lib/foreman_maintain/utils/backup.rb', line 100
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) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/foreman_maintain/utils/backup.rb', line 41
def map_file(backup_dir, filename)
file_path = File.join(backup_dir, filename)
present = File.exist?(file_path)
{
:present => present,
:path => file_path,
}
end
|
212
213
214
215
216
217
218
|
# File 'lib/foreman_maintain/utils/backup.rb', line 212
def metadata
if file_map[:metadata][:present]
YAML.load_file(file_map[:metadata][:path])
else
{}
end
end
|
#online_backup? ⇒ Boolean
247
248
249
|
# File 'lib/foreman_maintain/utils/backup.rb', line 247
def online_backup?
!!metadata.fetch('online', false)
end
|
#present_files ⇒ Object
50
51
52
53
|
# File 'lib/foreman_maintain/utils/backup.rb', line 50
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? ⇒ Boolean
220
221
222
|
# File 'lib/foreman_maintain/utils/backup.rb', line 220
def pulp_tar_split?
File.exist?(File.join(@backup_dir, 'pulp_data.part0002'))
end
|
#source_os_version ⇒ Object
259
260
261
|
# File 'lib/foreman_maintain/utils/backup.rb', line 259
def source_os_version
metadata.fetch('os_version', 'unknown')
end
|
#sql_dump_files_exist? ⇒ Boolean
233
234
235
236
237
|
# File 'lib/foreman_maintain/utils/backup.rb', line 233
def sql_dump_files_exist?
file_map[:foreman_dump][:present] ||
file_map[:candlepin_dump][:present] ||
file_map[:pulpcore_dump][:present]
end
|
#sql_needs_dump_restore? ⇒ Boolean
239
240
241
|
# File 'lib/foreman_maintain/utils/backup.rb', line 239
def sql_needs_dump_restore?
!sql_tar_files_exist? && sql_dump_files_exist?
end
|
#sql_tar_files_exist? ⇒ Boolean
229
230
231
|
# File 'lib/foreman_maintain/utils/backup.rb', line 229
def sql_tar_files_exist?
file_map[:pgsql_data][:present]
end
|
#tar_backups_exist? ⇒ Boolean
224
225
226
227
|
# File 'lib/foreman_maintain/utils/backup.rb', line 224
def tar_backups_exist?
file_map[:pulp_data][:present] ||
file_map[:pgsql_data][:present]
end
|
#valid_backup? ⇒ Boolean
55
56
57
|
# File 'lib/foreman_maintain/utils/backup.rb', line 55
def valid_backup?
file_map[:config_files][:present] && check_backup
end
|
#valid_foreman_backup? ⇒ Boolean
80
81
82
|
# File 'lib/foreman_maintain/utils/backup.rb', line 80
def valid_foreman_backup?
foreman_standard_backup? || foreman_online_backup? || foreman_logical_backup?
end
|
#valid_fpc_backup? ⇒ Boolean
69
70
71
72
|
# File 'lib/foreman_maintain/utils/backup.rb', line 69
def valid_fpc_backup?
fpc_online_backup? || fpc_standard_backup? || fpc_logical_backup? || \
fpc_hybrid_db_backup?
end
|
#valid_katello_backup? ⇒ Boolean
74
75
76
77
78
|
# File 'lib/foreman_maintain/utils/backup.rb', line 74
def valid_katello_backup?
katello_online_backup? || katello_standard_backup? || katello_logical_backup? || \
katello_hybrid_db_backup?
end
|
#validate_hostname? ⇒ Boolean
187
188
189
190
|
# File 'lib/foreman_maintain/utils/backup.rb', line 187
def validate_hostname?
metadata.fetch('hostname', nil) == hostname
end
|
#validate_interfaces ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/foreman_maintain/utils/backup.rb', line 192
def validate_interfaces
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? ⇒ Boolean
255
256
257
|
# File 'lib/foreman_maintain/utils/backup.rb', line 255
def with_puppetserver?
installed_rpms.any? { |rpm| rpm.start_with?('puppetserver-') }
end
|