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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -10
  3. data/bin/foreman-maintain-rotate-tar +18 -0
  4. data/definitions/checks/backup/certs_tar_exist.rb +24 -0
  5. data/definitions/checks/backup/directory_ready.rb +21 -0
  6. data/definitions/checks/candlepin/db_up.rb +29 -0
  7. data/definitions/checks/check_epel_repository.rb +21 -0
  8. data/definitions/checks/foreman/db_up.rb +29 -0
  9. data/definitions/checks/hammer_ping.rb +3 -1
  10. data/definitions/checks/mongo/db_up.rb +29 -0
  11. data/definitions/checks/mongo/tools_installed.rb +31 -0
  12. data/definitions/checks/repositories/validate.rb +0 -3
  13. data/definitions/checks/root_user.rb +12 -0
  14. data/definitions/features/candlepin.rb +16 -0
  15. data/definitions/features/candlepin_database.rb +3 -1
  16. data/definitions/features/downstream.rb +21 -22
  17. data/definitions/features/foreman_database.rb +2 -0
  18. data/definitions/features/foreman_proxy.rb +70 -7
  19. data/definitions/features/foreman_server.rb +29 -0
  20. data/definitions/features/foreman_tasks.rb +5 -1
  21. data/definitions/features/hammer.rb +158 -3
  22. data/definitions/features/installer.rb +106 -0
  23. data/definitions/features/instance.rb +39 -0
  24. data/definitions/features/katello.rb +43 -0
  25. data/definitions/features/mongo.rb +159 -0
  26. data/definitions/features/pulp.rb +30 -0
  27. data/definitions/features/puppet.rb +21 -0
  28. data/definitions/features/puppet_server.rb +2 -6
  29. data/definitions/features/service.rb +134 -0
  30. data/definitions/features/sync_plans.rb +1 -1
  31. data/definitions/features/tar.rb +69 -0
  32. data/definitions/procedures/backup/accessibility_confirmation.rb +14 -0
  33. data/definitions/procedures/backup/clean.rb +16 -0
  34. data/definitions/procedures/backup/compress_data.rb +26 -0
  35. data/definitions/procedures/backup/config_files.rb +36 -0
  36. data/definitions/procedures/backup/metadata.rb +56 -0
  37. data/definitions/procedures/backup/offline/candlepin_db.rb +57 -0
  38. data/definitions/procedures/backup/offline/foreman_db.rb +57 -0
  39. data/definitions/procedures/backup/offline/mongo.rb +56 -0
  40. data/definitions/procedures/backup/online/candlepin_db.rb +20 -0
  41. data/definitions/procedures/backup/online/foreman_db.rb +20 -0
  42. data/definitions/procedures/backup/online/mongo.rb +21 -0
  43. data/definitions/procedures/backup/online/pg_global_objects.rb +23 -0
  44. data/definitions/procedures/backup/online/safety_confirmation.rb +25 -0
  45. data/definitions/procedures/backup/prepare_directory.rb +29 -0
  46. data/definitions/procedures/backup/pulp.rb +68 -0
  47. data/definitions/procedures/backup/snapshot/clean_mount.rb +24 -0
  48. data/definitions/procedures/backup/snapshot/logical_volume_confirmation.rb +47 -0
  49. data/definitions/procedures/backup/snapshot/mount_base.rb +27 -0
  50. data/definitions/procedures/backup/snapshot/mount_candlepin_db.rb +48 -0
  51. data/definitions/procedures/backup/snapshot/mount_foreman_db.rb +48 -0
  52. data/definitions/procedures/backup/snapshot/mount_mongo.rb +35 -0
  53. data/definitions/procedures/backup/snapshot/mount_pulp.rb +24 -0
  54. data/definitions/procedures/backup/snapshot/prepare_mount.rb +16 -0
  55. data/definitions/procedures/foreman_tasks/fetch_tasks_status.rb +1 -0
  56. data/definitions/procedures/hammer_setup.rb +4 -39
  57. data/definitions/procedures/installer/upgrade.rb +1 -21
  58. data/definitions/procedures/repositories/setup.rb +0 -4
  59. data/definitions/procedures/service/base.rb +31 -0
  60. data/definitions/procedures/service/disable.rb +14 -0
  61. data/definitions/procedures/service/enable.rb +14 -0
  62. data/definitions/procedures/service/list.rb +26 -0
  63. data/definitions/procedures/service/restart.rb +49 -0
  64. data/definitions/procedures/service/start.rb +14 -0
  65. data/definitions/procedures/service/status.rb +14 -0
  66. data/definitions/procedures/service/stop.rb +14 -0
  67. data/definitions/scenarios/backup.rb +242 -0
  68. data/definitions/scenarios/services.rb +156 -0
  69. data/definitions/scenarios/upgrade_to_satellite_6_2.rb +2 -2
  70. data/definitions/scenarios/upgrade_to_satellite_6_2_z.rb +2 -2
  71. data/definitions/scenarios/upgrade_to_satellite_6_3.rb +2 -2
  72. data/definitions/scenarios/upgrade_to_satellite_6_3_z.rb +2 -2
  73. data/definitions/scenarios/upgrade_to_satellite_6_4.rb +79 -0
  74. data/definitions/scenarios/upgrade_to_satellite_6_4_z.rb +79 -0
  75. data/lib/foreman_maintain.rb +5 -0
  76. data/lib/foreman_maintain/cli.rb +4 -0
  77. data/lib/foreman_maintain/cli/backup_command.rb +157 -0
  78. data/lib/foreman_maintain/cli/base.rb +18 -8
  79. data/lib/foreman_maintain/cli/service_command.rb +112 -0
  80. data/lib/foreman_maintain/cli/transform_clamp_options.rb +1 -1
  81. data/lib/foreman_maintain/concerns/base_database.rb +57 -5
  82. data/lib/foreman_maintain/concerns/hammer.rb +0 -9
  83. data/lib/foreman_maintain/concerns/metadata.rb +3 -1
  84. data/lib/foreman_maintain/concerns/reporter.rb +12 -0
  85. data/lib/foreman_maintain/concerns/system_helpers.rb +45 -2
  86. data/lib/foreman_maintain/detector.rb +3 -3
  87. data/lib/foreman_maintain/error.rb +12 -0
  88. data/lib/foreman_maintain/executable.rb +29 -6
  89. data/lib/foreman_maintain/feature.rb +15 -0
  90. data/lib/foreman_maintain/param.rb +4 -3
  91. data/lib/foreman_maintain/reporter.rb +6 -2
  92. data/lib/foreman_maintain/reporter/cli_reporter.rb +26 -10
  93. data/lib/foreman_maintain/runner.rb +26 -15
  94. data/lib/foreman_maintain/runner/execution.rb +5 -1
  95. data/lib/foreman_maintain/scenario.rb +11 -3
  96. data/lib/foreman_maintain/upgrade_runner.rb +0 -2
  97. data/lib/foreman_maintain/utils.rb +2 -2
  98. data/lib/foreman_maintain/utils/command_runner.rb +0 -2
  99. data/lib/foreman_maintain/utils/hash_tools.rb +21 -0
  100. data/lib/foreman_maintain/utils/mongo_core.rb +37 -0
  101. data/lib/foreman_maintain/version.rb +1 -1
  102. metadata +58 -8
  103. data/definitions/features/katello_service.rb +0 -118
  104. data/definitions/procedures/katello_service/restart.rb +0 -24
  105. data/definitions/procedures/katello_service/start.rb +0 -19
  106. data/definitions/procedures/katello_service/stop.rb +0 -17
  107. data/lib/foreman_maintain/utils/facter.rb +0 -21
  108. data/lib/foreman_maintain/utils/hammer.rb +0 -79
@@ -0,0 +1,156 @@
1
+ module ForemanMaintain::Scenarios
2
+ class ServiceRestart < ForemanMaintain::Scenario
3
+ metadata do
4
+ description 'Restart Services'
5
+ tags :service_restart
6
+ label :service_restart
7
+ manual_detection
8
+ end
9
+
10
+ def compose
11
+ add_steps(find_checks(:root_user))
12
+ add_steps_with_context(Procedures::Service::Restart)
13
+ end
14
+
15
+ def set_context_mapping
16
+ context.map(:only,
17
+ Procedures::Service::Restart => :only)
18
+
19
+ context.map(:exclude,
20
+ Procedures::Service::Restart => :exclude)
21
+
22
+ context.map(:wait_for_hammer_ping,
23
+ Procedures::Service::Restart => :wait_for_hammer_ping)
24
+ end
25
+ end
26
+
27
+ class ServiceStop < ForemanMaintain::Scenario
28
+ metadata do
29
+ description 'Stop Services'
30
+ tags :service_stop
31
+ label :service_stop
32
+ manual_detection
33
+ end
34
+
35
+ def compose
36
+ add_steps(find_checks(:root_user))
37
+ add_steps_with_context(Procedures::Service::Stop)
38
+ end
39
+
40
+ def set_context_mapping
41
+ context.map(:only,
42
+ Procedures::Service::Stop => :only)
43
+
44
+ context.map(:exclude,
45
+ Procedures::Service::Stop => :exclude)
46
+ end
47
+ end
48
+
49
+ class ServiceStart < ForemanMaintain::Scenario
50
+ metadata do
51
+ description 'Start Services'
52
+ tags :service_start
53
+ label :service_start
54
+ manual_detection
55
+ end
56
+
57
+ def compose
58
+ add_steps(find_checks(:root_user))
59
+ add_steps_with_context(Procedures::Service::Start)
60
+ end
61
+
62
+ def set_context_mapping
63
+ context.map(:only,
64
+ Procedures::Service::Start => :only)
65
+
66
+ context.map(:exclude,
67
+ Procedures::Service::Start => :exclude)
68
+ end
69
+ end
70
+
71
+ class ServiceList < ForemanMaintain::Scenario
72
+ metadata do
73
+ description 'Service List'
74
+ tags :services_list
75
+ label :services_list
76
+ manual_detection
77
+ end
78
+
79
+ def compose
80
+ add_steps_with_context(Procedures::Service::List)
81
+ end
82
+
83
+ def set_context_mapping
84
+ context.map(:only,
85
+ Procedures::Service::List => :only)
86
+
87
+ context.map(:exclude,
88
+ Procedures::Service::List => :exclude)
89
+ end
90
+ end
91
+
92
+ class ServiceEnable < ForemanMaintain::Scenario
93
+ metadata do
94
+ description 'Enable Services'
95
+ tags :service_enable
96
+ label :service_enable
97
+ manual_detection
98
+ end
99
+
100
+ def compose
101
+ add_steps(find_checks(:root_user))
102
+ add_steps_with_context(Procedures::Service::Enable)
103
+ end
104
+
105
+ def set_context_mapping
106
+ context.map(:only,
107
+ Procedures::Service::Enable => :only)
108
+
109
+ context.map(:exclude,
110
+ Procedures::Service::Enable => :exclude)
111
+ end
112
+ end
113
+
114
+ class ServiceDisable < ForemanMaintain::Scenario
115
+ metadata do
116
+ description 'Disable Services'
117
+ tags :service_disable
118
+ label :service_disable
119
+ manual_detection
120
+ end
121
+
122
+ def compose
123
+ add_steps(find_checks(:root_user))
124
+ add_steps_with_context(Procedures::Service::Disable)
125
+ end
126
+
127
+ def set_context_mapping
128
+ context.map(:only,
129
+ Procedures::Service::Disable => :only)
130
+
131
+ context.map(:exclude,
132
+ Procedures::Service::Disable => :exclude)
133
+ end
134
+ end
135
+
136
+ class ServiceStatus < ForemanMaintain::Scenario
137
+ metadata do
138
+ description 'Status Services'
139
+ tags :service_status
140
+ label :service_status
141
+ manual_detection
142
+ end
143
+
144
+ def compose
145
+ add_steps_with_context(Procedures::Service::Status)
146
+ end
147
+
148
+ def set_context_mapping
149
+ context.map(:only,
150
+ Procedures::Service::Status => :only)
151
+
152
+ context.map(:exclude,
153
+ Procedures::Service::Status => :exclude)
154
+ end
155
+ end
156
+ end
@@ -33,7 +33,7 @@ module Scenarios::Satellite_6_2
33
33
 
34
34
  def compose
35
35
  add_steps(find_procedures(:pre_migrations))
36
- add_step(Procedures::KatelloService::Stop.new)
36
+ add_step(Procedures::Service::Stop.new)
37
37
  end
38
38
  end
39
39
 
@@ -57,7 +57,7 @@ module Scenarios::Satellite_6_2
57
57
  end
58
58
 
59
59
  def compose
60
- add_step(Procedures::KatelloService::Start.new)
60
+ add_step(Procedures::Service::Start.new)
61
61
  add_steps(find_procedures(:post_migrations))
62
62
  end
63
63
  end
@@ -33,7 +33,7 @@ module Scenarios::Satellite_6_2_z
33
33
 
34
34
  def compose
35
35
  add_steps(find_procedures(:pre_migrations))
36
- add_step(Procedures::KatelloService::Stop.new)
36
+ add_step(Procedures::Service::Stop.new)
37
37
  end
38
38
  end
39
39
 
@@ -57,7 +57,7 @@ module Scenarios::Satellite_6_2_z
57
57
  end
58
58
 
59
59
  def compose
60
- add_step(Procedures::KatelloService::Start.new)
60
+ add_step(Procedures::Service::Start.new)
61
61
  add_steps(find_procedures(:post_migrations))
62
62
  end
63
63
  end
@@ -34,7 +34,7 @@ module Scenarios::Satellite_6_3
34
34
 
35
35
  def compose
36
36
  add_steps(find_procedures(:pre_migrations))
37
- add_step(Procedures::KatelloService::Stop.new)
37
+ add_step(Procedures::Service::Stop.new)
38
38
  end
39
39
  end
40
40
 
@@ -58,7 +58,7 @@ module Scenarios::Satellite_6_3
58
58
  end
59
59
 
60
60
  def compose
61
- add_step(Procedures::KatelloService::Start.new)
61
+ add_step(Procedures::Service::Start.new)
62
62
  add_steps(find_procedures(:post_migrations))
63
63
  end
64
64
  end
@@ -33,7 +33,7 @@ module Scenarios::Satellite_6_3_z
33
33
 
34
34
  def compose
35
35
  add_steps(find_procedures(:pre_migrations))
36
- add_step(Procedures::KatelloService::Stop.new)
36
+ add_step(Procedures::Service::Stop.new)
37
37
  end
38
38
  end
39
39
 
@@ -57,7 +57,7 @@ module Scenarios::Satellite_6_3_z
57
57
  end
58
58
 
59
59
  def compose
60
- add_step(Procedures::KatelloService::Start.new)
60
+ add_step(Procedures::Service::Start.new)
61
61
  add_steps(find_procedures(:post_migrations))
62
62
  end
63
63
  end
@@ -0,0 +1,79 @@
1
+ module Scenarios::Satellite_6_4
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_to_satellite_6_4
6
+ confine do
7
+ feature(:downstream) && feature(:downstream).current_minor_version == '6.3'
8
+ end
9
+ instance_eval(&block)
10
+ end
11
+ end
12
+ end
13
+
14
+ class PreUpgradeCheck < Abstract
15
+ upgrade_metadata do
16
+ description 'Checks before upgrading to Satellite 6.4'
17
+ tags :pre_upgrade_checks
18
+ run_strategy :fail_slow
19
+ end
20
+
21
+ def compose
22
+ add_steps(find_checks(:default))
23
+ add_steps(find_checks(:pre_upgrade))
24
+ add_step(Checks::Repositories::Validate.new(:version => '6.4'))
25
+ end
26
+ end
27
+
28
+ class PreMigrations < Abstract
29
+ upgrade_metadata do
30
+ description 'Procedures before migrating to Satellite 6.4'
31
+ tags :pre_migrations
32
+ end
33
+
34
+ def compose
35
+ add_steps(find_procedures(:pre_migrations))
36
+ add_step(Procedures::Service::Stop.new)
37
+ end
38
+ end
39
+
40
+ class Migrations < Abstract
41
+ upgrade_metadata do
42
+ description 'Migration scripts to Satellite 6.4'
43
+ tags :migrations
44
+ end
45
+
46
+ def compose
47
+ add_step(Procedures::Repositories::Setup.new(:version => '6.4'))
48
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
49
+ add_step(Procedures::Installer::Upgrade.new)
50
+ end
51
+ end
52
+
53
+ class PostMigrations < Abstract
54
+ upgrade_metadata do
55
+ description 'Procedures after migrating to Satellite 6.4'
56
+ tags :post_migrations
57
+ end
58
+
59
+ def compose
60
+ add_step(Procedures::Service::Start.new)
61
+ add_steps(find_procedures(:post_migrations))
62
+ end
63
+ end
64
+
65
+ class PostUpgradeChecks < Abstract
66
+ upgrade_metadata do
67
+ description 'Checks after upgrading to Satellite 6.4'
68
+ tags :post_upgrade_checks
69
+ run_strategy :fail_slow
70
+ end
71
+
72
+ def compose
73
+ add_steps(find_checks(:default))
74
+ add_steps(find_checks(:post_upgrade))
75
+ end
76
+ end
77
+ end
78
+
79
+ ForemanMaintain::UpgradeRunner.register_version('6.4', :upgrade_to_satellite_6_4)
@@ -0,0 +1,79 @@
1
+ module Scenarios::Satellite_6_4_z
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_to_satellite_6_4_z
6
+ confine do
7
+ feature(:downstream) && feature(:downstream).current_minor_version == '6.4'
8
+ end
9
+ instance_eval(&block)
10
+ end
11
+ end
12
+ end
13
+
14
+ class PreUpgradeCheck < Abstract
15
+ upgrade_metadata do
16
+ description 'Checks before upgrading to Satellite 6.4.z'
17
+ tags :pre_upgrade_checks
18
+ run_strategy :fail_slow
19
+ end
20
+
21
+ def compose
22
+ add_steps(find_checks(:default))
23
+ add_steps(find_checks(:pre_upgrade))
24
+ add_step(Checks::Repositories::Validate.new(:version => '6.4'))
25
+ end
26
+ end
27
+
28
+ class PreMigrations < Abstract
29
+ upgrade_metadata do
30
+ description 'Procedures before migrating to Satellite 6.4.z'
31
+ tags :pre_migrations
32
+ end
33
+
34
+ def compose
35
+ add_steps(find_procedures(:pre_migrations))
36
+ add_step(Procedures::Service::Stop.new)
37
+ end
38
+ end
39
+
40
+ class Migrations < Abstract
41
+ upgrade_metadata do
42
+ description 'Migration scripts to Satellite 6.4.z'
43
+ tags :migrations
44
+ end
45
+
46
+ def compose
47
+ add_step(Procedures::Repositories::Setup.new(:version => '6.4'))
48
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
49
+ add_step(Procedures::Installer::Upgrade.new)
50
+ end
51
+ end
52
+
53
+ class PostMigrations < Abstract
54
+ upgrade_metadata do
55
+ description 'Procedures after migrating to Satellite 6.4.z'
56
+ tags :post_migrations
57
+ end
58
+
59
+ def compose
60
+ add_step(Procedures::Service::Start.new)
61
+ add_steps(find_procedures(:post_migrations))
62
+ end
63
+ end
64
+
65
+ class PostUpgradeChecks < Abstract
66
+ upgrade_metadata do
67
+ description 'Checks after upgrading to Satellite 6.4.z'
68
+ tags :post_upgrade_checks
69
+ run_strategy :fail_slow
70
+ end
71
+
72
+ def compose
73
+ add_steps(find_checks(:default))
74
+ add_steps(find_checks(:post_upgrade))
75
+ end
76
+ end
77
+ end
78
+
79
+ ForemanMaintain::UpgradeRunner.register_version('6.4.z', :upgrade_to_satellite_6_4_z)
@@ -11,6 +11,7 @@ require 'timeout'
11
11
  module ForemanMaintain
12
12
  require 'foreman_maintain/core_ext'
13
13
  require 'foreman_maintain/concerns/logger'
14
+ require 'foreman_maintain/concerns/reporter'
14
15
  require 'foreman_maintain/concerns/finders'
15
16
  require 'foreman_maintain/concerns/metadata'
16
17
  require 'foreman_maintain/concerns/scenario_metadata'
@@ -76,6 +77,10 @@ module ForemanMaintain
76
77
  @detector ||= Detector.new
77
78
  end
78
79
 
80
+ def reporter
81
+ @reporter ||= ForemanMaintain::Reporter::CLIReporter.new
82
+ end
83
+
79
84
  def available_features(*args)
80
85
  detector.available_features(*args)
81
86
  end
@@ -4,7 +4,9 @@ require 'foreman_maintain/cli/base'
4
4
  require 'foreman_maintain/cli/transform_clamp_options'
5
5
  require 'foreman_maintain/cli/health_command'
6
6
  require 'foreman_maintain/cli/upgrade_command'
7
+ require 'foreman_maintain/cli/backup_command'
7
8
  require 'foreman_maintain/cli/advanced_command'
9
+ require 'foreman_maintain/cli/service_command'
8
10
 
9
11
  module ForemanMaintain
10
12
  module Cli
@@ -13,7 +15,9 @@ module ForemanMaintain
13
15
 
14
16
  subcommand 'health', 'Health related commands', HealthCommand
15
17
  subcommand 'upgrade', 'Upgrade related commands', UpgradeCommand
18
+ subcommand 'backup', 'Backup server', BackupCommand
16
19
  subcommand 'advanced', 'Advanced tools for server maintenance', AdvancedCommand
20
+ subcommand 'service', 'Control applicable services', ServiceCommand
17
21
 
18
22
  def run(*arguments)
19
23
  logger.info("Running foreman-maintain command with arguments #{arguments.inspect}")
@@ -0,0 +1,157 @@
1
+ module ForemanMaintain
2
+ module Cli
3
+ module BackupCommon
4
+ def self.included(klass)
5
+ klass.extend ClassMethods
6
+ end
7
+
8
+ def backup_dir
9
+ @backup_dir ||= preserve_directory? ? backup_root_dir : backup_subdir
10
+ end
11
+
12
+ def timestamp
13
+ DateTime.now.strftime('%Y-%m-%d-%H-%M-%S')
14
+ end
15
+
16
+ def backup_subdir
17
+ name = feature(:instance).product_name.downcase.tr(' ', '-')
18
+ File.join(backup_root_dir, "#{name}-backup-" + timestamp)
19
+ end
20
+
21
+ def perform_backup(strategy, options = {})
22
+ backup_scenario = backup_scenario(options, strategy)
23
+ rescue_scenario = rescue_scenario(options, strategy)
24
+ puts "Starting backup: #{Time.now}"
25
+ run_scenario(backup_scenario, rescue_scenario)
26
+ puts "Done with backup: #{Time.now}"
27
+ final_message
28
+ exit runner.exit_code
29
+ end
30
+
31
+ module ClassMethods
32
+ # rubocop:disable Metrics/MethodLength
33
+ def common_backup_options
34
+ # TODO: BACKUP_DIR in f-m config - should be default?
35
+ parameter 'BACKUP_DIR', 'Path to backup dir',
36
+ :attribute_name => :backup_root_dir do |dir|
37
+ File.expand_path(dir)
38
+ end
39
+ option ['-s', '--skip-pulp-content'], :flag, 'Do not backup Pulp content'
40
+ option ['-p', '--preserve-directory'], :flag, 'Do not create a time-stamped subdirectory'
41
+ option ['-t', '--split-pulp-tar'], 'SPLIT_SIZE',
42
+ 'Split pulp data into files of a specified size, i.e. (100M, 50G). ' \
43
+ "See '--tape-length' in 'info tar' for all sizes" do |size|
44
+ self.class.valid_tape_size(size)
45
+ end
46
+ option ['-i', '--incremental'], 'PREVIOUS_BACKUP_DIR',
47
+ 'Backup changes since previous backup' do |dir|
48
+ unless File.directory?(dir)
49
+ raise ArgumentError, "Previous backup directory does not exist: #{dir}"
50
+ end
51
+ dir
52
+ end
53
+ proxy_name = ForemanMaintain.detector.feature(:downstream) ? 'Capsule' : 'Foreman Proxy'
54
+ option '--features', 'FEATURES',
55
+ "#{proxy_name} features to include in the backup. " \
56
+ 'Valid features are tftp, dns, dhcp, openscap, and all.', :multivalued => true
57
+ end
58
+ # rubocop:enable Metrics/MethodLength
59
+
60
+ def valid_tape_size(size)
61
+ begin
62
+ ForemanMaintain.detector.feature(:tar).validate_volume_size(size)
63
+ rescue ForemanMaintain::Error::Validation => e
64
+ raise ArgumentError, e.message
65
+ end
66
+ size
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def rescue_scenario(options, strategy)
73
+ Scenarios::BackupRescueCleanup.new({
74
+ :backup_dir => backup_dir,
75
+ :strategy => strategy,
76
+ :preserve_dir => preserve_directory?
77
+ }.merge(options))
78
+ end
79
+
80
+ def backup_scenario(options, strategy)
81
+ Scenarios::Backup.new({
82
+ :backup_dir => backup_dir,
83
+ :strategy => strategy,
84
+ :preserve_dir => preserve_directory?,
85
+ :proxy_features => features,
86
+ :tar_volume_size => split_pulp_tar,
87
+ :skip_pulp_content => skip_pulp_content?,
88
+ :incremental_dir => incremental
89
+ }.merge(options))
90
+ end
91
+
92
+ def final_message
93
+ if runner.quit?
94
+ if preserve_directory?
95
+ puts "Backup didn't finish. Incomplete backup is preserved in: #{backup_dir}"
96
+ else
97
+ puts "Backup didn't finish. Incomplete backup was removed."
98
+ end
99
+ else
100
+ puts "**** BACKUP Complete, contents can be found in: #{backup_dir} ****"
101
+ end
102
+ end
103
+ end
104
+
105
+ class OnlineBackupCommand < Base
106
+ include BackupCommon
107
+ interactive_option
108
+ common_backup_options
109
+
110
+ def execute
111
+ perform_backup(:online)
112
+ end
113
+ end
114
+
115
+ class OfflineBackupCommand < Base
116
+ include BackupCommon
117
+ interactive_option
118
+ common_backup_options
119
+ option '--include-db-dumps', :flag, 'Also dump full database schema before offline backup'
120
+
121
+ def execute
122
+ perform_backup(:offline,
123
+ :include_db_dumps => include_db_dumps?)
124
+ end
125
+ end
126
+
127
+ class SnapshotBackupCommand < Base
128
+ include BackupCommon
129
+ interactive_option
130
+ common_backup_options
131
+ option ['-d', '--snapshot-mount-dir'], 'SNAPSHOT_MOUNT_DIR',
132
+ "Override default directory ('/var/snap/') where the snapshots will be mounted",
133
+ :default => '/var/snap/' do |dir|
134
+ unless File.directory?(dir)
135
+ raise ArgumentError, "Snapshot mount directory does not exist: #{dir}"
136
+ end
137
+ dir
138
+ end
139
+ option ['-b', '--snapshot-block-size'], 'SNAPSHOT_BLOCK_SIZE',
140
+ 'Override default block size (2G)', :default => '2G'
141
+
142
+ def execute
143
+ perform_backup(:snapshot,
144
+ :snapshot_mount_dir => snapshot_mount_dir,
145
+ :snapshot_block_size => snapshot_block_size)
146
+ end
147
+ end
148
+
149
+ # rubocop:disable Metrics/LineLength
150
+ class BackupCommand < Base
151
+ subcommand 'online', 'Keep services online during backup', OnlineBackupCommand
152
+ subcommand 'offline', 'Shut down services to preserve consistent backup', OfflineBackupCommand
153
+ subcommand 'snapshot', 'Use snapshots of the databases to create backup', SnapshotBackupCommand
154
+ end
155
+ # rubocop:enable Metrics/LineLength
156
+ end
157
+ end