foreman_maintain 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +48 -10
- data/bin/foreman-maintain-rotate-tar +18 -0
- data/definitions/checks/backup/certs_tar_exist.rb +24 -0
- data/definitions/checks/backup/directory_ready.rb +21 -0
- data/definitions/checks/candlepin/db_up.rb +29 -0
- data/definitions/checks/check_epel_repository.rb +21 -0
- data/definitions/checks/foreman/db_up.rb +29 -0
- data/definitions/checks/hammer_ping.rb +3 -1
- data/definitions/checks/mongo/db_up.rb +29 -0
- data/definitions/checks/mongo/tools_installed.rb +31 -0
- data/definitions/checks/repositories/validate.rb +0 -3
- data/definitions/checks/root_user.rb +12 -0
- data/definitions/features/candlepin.rb +16 -0
- data/definitions/features/candlepin_database.rb +3 -1
- data/definitions/features/downstream.rb +21 -22
- data/definitions/features/foreman_database.rb +2 -0
- data/definitions/features/foreman_proxy.rb +70 -7
- data/definitions/features/foreman_server.rb +29 -0
- data/definitions/features/foreman_tasks.rb +5 -1
- data/definitions/features/hammer.rb +158 -3
- data/definitions/features/installer.rb +106 -0
- data/definitions/features/instance.rb +39 -0
- data/definitions/features/katello.rb +43 -0
- data/definitions/features/mongo.rb +159 -0
- data/definitions/features/pulp.rb +30 -0
- data/definitions/features/puppet.rb +21 -0
- data/definitions/features/puppet_server.rb +2 -6
- data/definitions/features/service.rb +134 -0
- data/definitions/features/sync_plans.rb +1 -1
- data/definitions/features/tar.rb +69 -0
- data/definitions/procedures/backup/accessibility_confirmation.rb +14 -0
- data/definitions/procedures/backup/clean.rb +16 -0
- data/definitions/procedures/backup/compress_data.rb +26 -0
- data/definitions/procedures/backup/config_files.rb +36 -0
- data/definitions/procedures/backup/metadata.rb +56 -0
- data/definitions/procedures/backup/offline/candlepin_db.rb +57 -0
- data/definitions/procedures/backup/offline/foreman_db.rb +57 -0
- data/definitions/procedures/backup/offline/mongo.rb +56 -0
- data/definitions/procedures/backup/online/candlepin_db.rb +20 -0
- data/definitions/procedures/backup/online/foreman_db.rb +20 -0
- data/definitions/procedures/backup/online/mongo.rb +21 -0
- data/definitions/procedures/backup/online/pg_global_objects.rb +23 -0
- data/definitions/procedures/backup/online/safety_confirmation.rb +25 -0
- data/definitions/procedures/backup/prepare_directory.rb +29 -0
- data/definitions/procedures/backup/pulp.rb +68 -0
- data/definitions/procedures/backup/snapshot/clean_mount.rb +24 -0
- data/definitions/procedures/backup/snapshot/logical_volume_confirmation.rb +47 -0
- data/definitions/procedures/backup/snapshot/mount_base.rb +27 -0
- data/definitions/procedures/backup/snapshot/mount_candlepin_db.rb +48 -0
- data/definitions/procedures/backup/snapshot/mount_foreman_db.rb +48 -0
- data/definitions/procedures/backup/snapshot/mount_mongo.rb +35 -0
- data/definitions/procedures/backup/snapshot/mount_pulp.rb +24 -0
- data/definitions/procedures/backup/snapshot/prepare_mount.rb +16 -0
- data/definitions/procedures/foreman_tasks/fetch_tasks_status.rb +1 -0
- data/definitions/procedures/hammer_setup.rb +4 -39
- data/definitions/procedures/installer/upgrade.rb +1 -21
- data/definitions/procedures/repositories/setup.rb +0 -4
- data/definitions/procedures/service/base.rb +31 -0
- data/definitions/procedures/service/disable.rb +14 -0
- data/definitions/procedures/service/enable.rb +14 -0
- data/definitions/procedures/service/list.rb +26 -0
- data/definitions/procedures/service/restart.rb +49 -0
- data/definitions/procedures/service/start.rb +14 -0
- data/definitions/procedures/service/status.rb +14 -0
- data/definitions/procedures/service/stop.rb +14 -0
- data/definitions/scenarios/backup.rb +242 -0
- data/definitions/scenarios/services.rb +156 -0
- data/definitions/scenarios/upgrade_to_satellite_6_2.rb +2 -2
- data/definitions/scenarios/upgrade_to_satellite_6_2_z.rb +2 -2
- data/definitions/scenarios/upgrade_to_satellite_6_3.rb +2 -2
- data/definitions/scenarios/upgrade_to_satellite_6_3_z.rb +2 -2
- data/definitions/scenarios/upgrade_to_satellite_6_4.rb +79 -0
- data/definitions/scenarios/upgrade_to_satellite_6_4_z.rb +79 -0
- data/lib/foreman_maintain.rb +5 -0
- data/lib/foreman_maintain/cli.rb +4 -0
- data/lib/foreman_maintain/cli/backup_command.rb +157 -0
- data/lib/foreman_maintain/cli/base.rb +18 -8
- data/lib/foreman_maintain/cli/service_command.rb +112 -0
- data/lib/foreman_maintain/cli/transform_clamp_options.rb +1 -1
- data/lib/foreman_maintain/concerns/base_database.rb +57 -5
- data/lib/foreman_maintain/concerns/hammer.rb +0 -9
- data/lib/foreman_maintain/concerns/metadata.rb +3 -1
- data/lib/foreman_maintain/concerns/reporter.rb +12 -0
- data/lib/foreman_maintain/concerns/system_helpers.rb +45 -2
- data/lib/foreman_maintain/detector.rb +3 -3
- data/lib/foreman_maintain/error.rb +12 -0
- data/lib/foreman_maintain/executable.rb +29 -6
- data/lib/foreman_maintain/feature.rb +15 -0
- data/lib/foreman_maintain/param.rb +4 -3
- data/lib/foreman_maintain/reporter.rb +6 -2
- data/lib/foreman_maintain/reporter/cli_reporter.rb +26 -10
- data/lib/foreman_maintain/runner.rb +26 -15
- data/lib/foreman_maintain/runner/execution.rb +5 -1
- data/lib/foreman_maintain/scenario.rb +11 -3
- data/lib/foreman_maintain/upgrade_runner.rb +0 -2
- data/lib/foreman_maintain/utils.rb +2 -2
- data/lib/foreman_maintain/utils/command_runner.rb +0 -2
- data/lib/foreman_maintain/utils/hash_tools.rb +21 -0
- data/lib/foreman_maintain/utils/mongo_core.rb +37 -0
- data/lib/foreman_maintain/version.rb +1 -1
- metadata +58 -8
- data/definitions/features/katello_service.rb +0 -118
- data/definitions/procedures/katello_service/restart.rb +0 -24
- data/definitions/procedures/katello_service/start.rb +0 -19
- data/definitions/procedures/katello_service/stop.rb +0 -17
- data/lib/foreman_maintain/utils/facter.rb +0 -21
- data/lib/foreman_maintain/utils/hammer.rb +0 -79
@@ -0,0 +1,21 @@
|
|
1
|
+
module Procedures::Backup
|
2
|
+
module Online
|
3
|
+
class Mongo < ForemanMaintain::Procedure
|
4
|
+
metadata do
|
5
|
+
description 'Backup Mongo online'
|
6
|
+
tags :backup
|
7
|
+
for_feature :mongo
|
8
|
+
preparation_steps do
|
9
|
+
[Checks::Mongo::DBUp.new, Checks::Mongo::ToolsInstalled.new]
|
10
|
+
end
|
11
|
+
param :backup_dir, 'Directory where to backup to', :required => true
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
with_spinner('Getting dump of Mongo DB') do
|
16
|
+
feature(:mongo).dump(File.join(@backup_dir, 'mongo_dump'))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Procedures::Backup
|
2
|
+
module Online
|
3
|
+
class PgGlobalObjects < ForemanMaintain::Procedure
|
4
|
+
metadata do
|
5
|
+
description 'Backup Postgres global objects online'
|
6
|
+
tags :backup
|
7
|
+
param :backup_dir, 'Directory where to backup to', :required => true
|
8
|
+
confine do
|
9
|
+
feature(:foreman_database) || feature(:candlepin_database)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
if feature(:foreman_database).local? || feature(:candlepin_database).local?
|
15
|
+
local_db = feature(:foreman_database).local? ? :foreman_database : :candlepin_database
|
16
|
+
feature(local_db).backup_global_objects(File.join(@backup_dir, 'pg_globals.dump'))
|
17
|
+
else
|
18
|
+
skip 'Backup of global objects is not supported for remote databases.'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Procedures::Backup
|
2
|
+
module Online
|
3
|
+
class SafetyConfirmation < ForemanMaintain::Procedure
|
4
|
+
metadata do
|
5
|
+
description 'Data consistency warning'
|
6
|
+
tags :backup
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
answer = ask_decision(
|
11
|
+
"*** WARNING: The online backup is intended for making a copy of the data\n" \
|
12
|
+
'*** for debugging purposes only.' \
|
13
|
+
" The backup routine can not ensure 100% consistency while the\n" \
|
14
|
+
"*** backup is taking place as there is a chance there may be data mismatch between\n" \
|
15
|
+
'*** Mongo and Postgres databases while the services are live.' \
|
16
|
+
" If you wish to utilize the online backup\n" \
|
17
|
+
'*** for production use you need to ensure that there are' \
|
18
|
+
" no modifications occurring during\n" \
|
19
|
+
"*** your backup run.\n\nDo you want to proceed?", 'y(yes), q(quit)'
|
20
|
+
)
|
21
|
+
abort! unless answer == :yes
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Procedures::Backup
|
2
|
+
class PrepareDirectory < ForemanMaintain::Procedure
|
3
|
+
metadata do
|
4
|
+
description 'Prepare backup Directory'
|
5
|
+
tags :backup
|
6
|
+
param :backup_dir, 'Directory where to backup to', :required => true
|
7
|
+
param :preserve_dir, 'Directory where to backup to', :flag => true
|
8
|
+
param :incremental_dir, 'Changes since specified backup only'
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
puts "Creating backup folder #{@backup_dir}"
|
13
|
+
|
14
|
+
unless @preserve_dir
|
15
|
+
FileUtils.mkdir_p @backup_dir
|
16
|
+
FileUtils.chmod_R 0o770, @backup_dir
|
17
|
+
end
|
18
|
+
|
19
|
+
if local_psql_database? && !@preserve_dir
|
20
|
+
FileUtils.chown_R(nil, 'postgres', @backup_dir)
|
21
|
+
end
|
22
|
+
|
23
|
+
FileUtils.rm(Dir.glob(File.join(@backup_dir, '.*.snar'))) if @preserve_dir
|
24
|
+
if @incremental_dir
|
25
|
+
FileUtils.cp(Dir.glob(File.join(@incremental_dir, '.*.snar')), @backup_dir)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Procedures::Backup
|
2
|
+
class Pulp < ForemanMaintain::Procedure
|
3
|
+
metadata do
|
4
|
+
description 'Backup Pulp data'
|
5
|
+
tags :backup
|
6
|
+
for_feature :pulp
|
7
|
+
param :backup_dir, 'Directory where to backup to', :required => true
|
8
|
+
param :tar_volume_size, 'Size of tar volume (indicates splitting)'
|
9
|
+
param :ensure_unchanged, 'Ensure the data did not change during backup'
|
10
|
+
param :skip, 'Skip Pulp content during backup'
|
11
|
+
param :mount_dir, 'Snapshot mount directory'
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
skip if @skip
|
16
|
+
with_spinner('Collecting Pulp data') do
|
17
|
+
FileUtils.cd(pulp_dir) do
|
18
|
+
if @ensure_unchanged
|
19
|
+
ensure_dir_unchanged { pulp_backup }
|
20
|
+
else
|
21
|
+
pulp_backup
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def pulp_backup
|
30
|
+
feature(:tar).run(
|
31
|
+
:archive => File.join(@backup_dir, 'pulp_data.tar'),
|
32
|
+
:command => 'create',
|
33
|
+
:exclude => ['var/lib/pulp/katello-export'],
|
34
|
+
:listed_incremental => File.join(@backup_dir, '.pulp.snar'),
|
35
|
+
:transform => 's,^,var/lib/pulp/,S',
|
36
|
+
:volume_size => @tar_volume_size
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def pulp_dir
|
41
|
+
return feature(:pulp).data_dir if @mount_dir.nil?
|
42
|
+
mount_point = File.join(@mount_dir, 'pulp')
|
43
|
+
feature(:pulp).find_base_directory(mount_point)
|
44
|
+
end
|
45
|
+
|
46
|
+
def ensure_dir_unchanged
|
47
|
+
matching = false
|
48
|
+
backup_file = File.join(@backup_dir, '.pulp.snar')
|
49
|
+
alternate_backup = File.join(@backup_dir, '.pulp.snar.backup')
|
50
|
+
until matching
|
51
|
+
FileUtils.cp(backup_file, alternate_backup) if File.exist? backup_file
|
52
|
+
checksum1 = compute_checksum
|
53
|
+
yield
|
54
|
+
checksum2 = compute_checksum
|
55
|
+
matching = (checksum1 == checksum2)
|
56
|
+
FileUtils.rm backup_file unless matching
|
57
|
+
if File.exist? alternate_backup
|
58
|
+
matching ? FileUtils.rm(alternate_backup) : FileUtils.mv(alternate_backup, backup_file)
|
59
|
+
end
|
60
|
+
logger.info("Data in #{pulp_dir} changed during backup. Retrying...") unless matching
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def compute_checksum
|
65
|
+
execute!("find . -printf '%T@\n' | sha1sum")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Procedures::Backup
|
2
|
+
module Snapshot
|
3
|
+
class CleanMount < ForemanMaintain::Procedure
|
4
|
+
metadata do
|
5
|
+
description 'Remove the snapshot mount points'
|
6
|
+
tags :backup
|
7
|
+
param :mount_dir, 'Snapshot mount directory', :required => true
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
%w[pulp mongodb pgsql].each do |database|
|
12
|
+
mount_point = File.join(@mount_dir, database)
|
13
|
+
|
14
|
+
if File.exist?(mount_point) && !execute("mount|grep #{mount_point}").empty?
|
15
|
+
execute("umount #{mount_point}")
|
16
|
+
end
|
17
|
+
|
18
|
+
snapshot_location = get_lv_path("#{database}-snap")
|
19
|
+
execute("lvremove #{snapshot_location} -f") unless snapshot_location.empty?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Procedures::Backup
|
2
|
+
module Snapshot
|
3
|
+
class LogicalVolumeConfirmation < ForemanMaintain::Procedure
|
4
|
+
metadata do
|
5
|
+
description 'Check if backup is on different logical volume then the source'
|
6
|
+
tags :backup
|
7
|
+
param :backup_dir, 'Directory where to backup to', :required => true
|
8
|
+
param :skip_pulp, 'Skip Pulp content during backup'
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
backup_lv = get_lv_info(@backup_dir)
|
13
|
+
|
14
|
+
dbs = {}
|
15
|
+
dbs[:pulp] = 'Pulp' if feature(:pulp) && !@skip_pulp
|
16
|
+
dbs[:mongo] = 'Mongo' if db_local?(:mongo)
|
17
|
+
dbs[:candlepin_database] = 'Candlepin' if db_local?(:candlepin_database)
|
18
|
+
dbs[:foreman_database] = 'Foreman' if db_local?(:foreman_database)
|
19
|
+
|
20
|
+
shared_lv = dbs.inject([]) do |list, (db_label, db_name)|
|
21
|
+
db_lv = get_lv_info(feature(db_label).data_dir)
|
22
|
+
list << db_name if db_lv == backup_lv
|
23
|
+
list
|
24
|
+
end
|
25
|
+
confirm(shared_lv) if shared_lv.any?
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def db_local?(db)
|
31
|
+
feature(:instance).database_local?(db)
|
32
|
+
end
|
33
|
+
|
34
|
+
def confirm(shared_lv)
|
35
|
+
answer = ask_decision('*** WARNING: The chosen backup location is mounted on the same' \
|
36
|
+
" logical volume as the location of #{shared_lv.join(', ')}.\n" \
|
37
|
+
'*** It is highly suggested to backup to a different logical volume than' \
|
38
|
+
" the #{shared_lv.join(', ')} database.\n" \
|
39
|
+
'*** If you would like to continue, the snapshot size will be required to be at least' \
|
40
|
+
"the size of the actual #{shared_lv.join(', ')} database.\n" \
|
41
|
+
"*** You can skip this confirmation with the '-y' flag.\n\n" \
|
42
|
+
'Do you want to proceed(y/n)?', 'y(yes), q(quit)')
|
43
|
+
abort! unless answer == :yes
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Procedures::Backup
|
2
|
+
module Snapshot
|
3
|
+
class MountBase < ForemanMaintain::Procedure
|
4
|
+
metadata do
|
5
|
+
advanced_run false
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.common_params(context)
|
9
|
+
context.instance_eval do
|
10
|
+
param :mount_dir, 'Snapshot mount directory', :required => true
|
11
|
+
param :block_size, 'Snapshot block size', :default => '2G'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def mount_snapshot(database, lv_type)
|
16
|
+
FileUtils.mkdir_p(mount_location(database))
|
17
|
+
options = lv_type == 'xfs' ? '-onouuid,ro' : '-oro'
|
18
|
+
lv_name = "#{database}-snap"
|
19
|
+
execute!("mount #{get_lv_path(lv_name)} #{mount_location(database)} #{options}")
|
20
|
+
end
|
21
|
+
|
22
|
+
def mount_location(database)
|
23
|
+
File.join(@mount_dir, database)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'procedures/backup/snapshot/mount_base'
|
2
|
+
module Procedures::Backup
|
3
|
+
module Snapshot
|
4
|
+
class MountCandlepinDB < MountBase
|
5
|
+
metadata do
|
6
|
+
description 'Create and mount snapshot of Candlepin DB'
|
7
|
+
tags :backup
|
8
|
+
label :backup_snapshot_mount_candlepin_db
|
9
|
+
for_feature :candlepin_database
|
10
|
+
preparation_steps { Checks::Candlepin::DBUp.new unless feature(:candlepin_database).local? }
|
11
|
+
MountBase.common_params(self)
|
12
|
+
param :backup_dir, 'Directory where to backup to'
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
if feature(:candlepin_database).local?
|
17
|
+
snapshot
|
18
|
+
else
|
19
|
+
dump_candlepin
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def dump_candlepin
|
26
|
+
puts 'LV snapshots are not supported for remote databases. Doing postgres dump instead... '
|
27
|
+
with_spinner('Getting Candlepin DB dump') do
|
28
|
+
feature(:candlepin_database).dump_db(File.join(@backup_dir, 'candlepin.dump'))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def snapshot
|
33
|
+
mount_point = mount_location('pgsql')
|
34
|
+
FileUtils.mkdir_p(mount_point) unless File.directory?(mount_point)
|
35
|
+
if directory_empty?(mount_point)
|
36
|
+
with_spinner('Creating snapshot of Postgres') do |spinner|
|
37
|
+
lv_info = get_lv_info(feature(:candlepin_database).data_dir)
|
38
|
+
create_lv_snapshot('pgsql-snap', @block_size, lv_info[0])
|
39
|
+
spinner.update("Mounting snapshot of Postgres on #{mount_point}")
|
40
|
+
mount_snapshot('pgsql', lv_info[1])
|
41
|
+
end
|
42
|
+
else
|
43
|
+
puts 'Snapshot of Postgres is already mounted'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'procedures/backup/snapshot/mount_base'
|
2
|
+
module Procedures::Backup
|
3
|
+
module Snapshot
|
4
|
+
class MountForemanDB < MountBase
|
5
|
+
metadata do
|
6
|
+
description 'Create and mount snapshot of Foreman DB'
|
7
|
+
tags :backup
|
8
|
+
label :backup_snapshot_mount_foreman_db
|
9
|
+
for_feature :foreman_database
|
10
|
+
preparation_steps { Checks::Foreman::DBUp.new unless feature(:foreman_database).local? }
|
11
|
+
MountBase.common_params(self)
|
12
|
+
param :backup_dir, 'Directory where to backup to'
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
if feature(:foreman_database).local?
|
17
|
+
snapshot
|
18
|
+
else
|
19
|
+
dump_foreman
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def dump_foreman
|
26
|
+
puts 'LV snapshots are not supported for remote databases. Doing postgres dump instead... '
|
27
|
+
with_spinner('Getting Foreman DB dump') do
|
28
|
+
feature(:foreman_database).dump_db(File.join(@backup_dir, 'foreman.dump'))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def snapshot
|
33
|
+
mount_point = mount_location('pgsql')
|
34
|
+
FileUtils.mkdir_p(mount_point) unless File.directory?(mount_point)
|
35
|
+
if directory_empty?(mount_point)
|
36
|
+
with_spinner('Creating snapshot of Postgres') do |spinner|
|
37
|
+
lv_info = get_lv_info(feature(:foreman_database).data_dir)
|
38
|
+
create_lv_snapshot('pgsql-snap', @block_size, lv_info[0])
|
39
|
+
spinner.update("Mounting snapshot of Postgres on #{mount_point}")
|
40
|
+
mount_snapshot('pgsql', lv_info[1])
|
41
|
+
end
|
42
|
+
else
|
43
|
+
puts 'Snapshot of Postgres is already mounted'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'procedures/backup/snapshot/mount_base'
|
2
|
+
module Procedures::Backup
|
3
|
+
module Snapshot
|
4
|
+
class MountMongo < MountBase
|
5
|
+
metadata do
|
6
|
+
description 'Create and mount snapshot of Mongo DB'
|
7
|
+
tags :backup
|
8
|
+
for_feature :mongo
|
9
|
+
preparation_steps do
|
10
|
+
unless feature(:mongo).local?
|
11
|
+
[Checks::Mongo::DBUp.new, Checks::Mongo::ToolsInstalled.new]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
MountBase.common_params(self)
|
15
|
+
param :backup_dir, 'Directory where to backup to'
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
if feature(:mongo).local?
|
20
|
+
with_spinner('Creating snapshot of Mongo DB') do |spinner|
|
21
|
+
lv_info = get_lv_info(feature(:mongo).data_dir)
|
22
|
+
create_lv_snapshot('mongodb-snap', @block_size, lv_info[0])
|
23
|
+
spinner.update("Mounting snapshot of Mongo DB on #{mount_location('mongodb')}")
|
24
|
+
mount_snapshot('mongodb', lv_info[1])
|
25
|
+
end
|
26
|
+
else
|
27
|
+
puts 'LV snapshots are not supported for remote databases. Doing dump instead...'
|
28
|
+
with_spinner('Getting dump of Mongo DB') do
|
29
|
+
feature(:mongo).dump(File.join(@backup_dir, 'mongo_dump'))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'procedures/backup/snapshot/mount_base'
|
2
|
+
module Procedures::Backup
|
3
|
+
module Snapshot
|
4
|
+
class MountPulp < MountBase
|
5
|
+
metadata do
|
6
|
+
description 'Create and mount snapshot of Pulp data'
|
7
|
+
tags :backup
|
8
|
+
for_feature :pulp
|
9
|
+
MountBase.common_params(self)
|
10
|
+
param :skip, 'Skip Pulp content during backup'
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
skip if @skip
|
15
|
+
with_spinner('Creating snapshot of Pulp') do |spinner|
|
16
|
+
lv_info = get_lv_info(feature(:pulp).data_dir)
|
17
|
+
create_lv_snapshot('pulp-snap', @block_size, lv_info[0])
|
18
|
+
spinner.update("Mounting snapshot of Pulp on #{mount_location('pulp')}")
|
19
|
+
mount_snapshot('pulp', lv_info[1])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Procedures::Backup
|
2
|
+
module Snapshot
|
3
|
+
class PrepareMount < ForemanMaintain::Procedure
|
4
|
+
metadata do
|
5
|
+
description 'Prepare mount point for the snapshot'
|
6
|
+
tags :backup
|
7
|
+
param :mount_dir, 'Snapshot mount directory', :required => true
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
logger.debug("Creating snap dir: #{@mount_dir}")
|
12
|
+
FileUtils.mkdir_p @mount_dir
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|