class ManageIQ::ApplianceConsole::DatabaseAdmin
Constants
- DB_DEFAULT_DUMP_FILE
- DB_DUMP_WARNING
- DB_RESTORE_FILE
- LOCAL_FILE_VALIDATOR
- USER_PROMPT
Attributes
action[R]
backup_type[R]
database_opts[R]
delete_agree[R]
filename[R]
Public Class Methods
new(action = :restore, input = $stdin, output = $stdout)
click to toggle source
Calls superclass method
# File lib/manageiq/appliance_console/database_admin.rb, line 28 def initialize(action = :restore, input = $stdin, output = $stdout) super(input, output) @action = action @database_opts = {:dbname => DatabaseConfiguration.database_name} end
Public Instance Methods
activate()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 51 def activate clear_screen setting_header ask_to_delete_backup_after_restore confirm_and_execute end
allowed_to_execute?()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 98 def allowed_to_execute? return true unless action == :restore say("\nNote: A database restore cannot be undone. The restore will use the file: #{uri}.\n") agree("Are you sure you would like to restore the database? (Y/N): ") end
ask_file_location()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 59 def ask_file_location @database_opts[:local_file] = just_ask(*filename_prompt_args) end
ask_for_tables_to_exclude_in_dump()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 70 def ask_for_tables_to_exclude_in_dump if action == :dump && should_exclude_tables? say(<<-PROMPT.strip_heredoc) To exclude tables from the dump, enter them in a space separated list. For example: > metrics_* vim_performance_states event_streams PROMPT table_excludes = ask_for_many("table", "tables to exclude", "metrics_* vim_performance_states event_streams", 255, Float::INFINITY) @database_opts[:exclude_table_data] = table_excludes end || true end
ask_questions()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 39 def ask_questions setting_header if action == :restore && LinuxAdmin::Service.new("evmserverd").running? say("\nDatabase restore failed. Please execute the \“Stop EVM Server Processes\” command and try again.") press_any_key raise MiqSignalError end say(DB_DUMP_WARNING) if action == :dump ask_file_location ask_for_tables_to_exclude_in_dump end
ask_to_delete_backup_after_restore()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 63 def ask_to_delete_backup_after_restore if action == :restore say("The local database restore file is located at: '#{uri}'.\n") @delete_agree = agree("Should this file be deleted after completing the restore? (Y/N): ") end end
confirm_and_execute()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 90 def confirm_and_execute if allowed_to_execute? processing_message run_action end press_any_key end
file_options()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 105 def file_options @file_options ||= I18n.t("database_admin.menu_order").each_with_object({}) do |file_option, h| # special anonymous ftp sites are defined by uri uri = URI(file_option) if uri.scheme h["#{uri.scheme} to #{uri.host}"] = file_option unless skip_file_location?(uri.host) else h[I18n.t("database_admin.#{file_option}")] = file_option end end end
setting_header()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 117 def setting_header say("#{I18n.t("advanced_settings.db#{action}")}\n\n") end
uri()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 35 def uri @database_opts[:local_file] end
Private Instance Methods
backup()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 188 def backup result = PostgresAdmin.backup(database_opts) ManageIQ::ApplianceConsole.logger.info("[#{@database_opts[:dbname]}] database has been backed up to file: [#{uri}]") result end
dump()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 194 def dump result = PostgresAdmin.backup_pg_dump(database_opts) ManageIQ::ApplianceConsole.logger.info("[#{@database_opts[:dbname]}] database has been dumped up to file: [#{uri}]") result end
filename_prompt_args()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 141 def filename_prompt_args return restore_prompt_args if action == :restore default = action == :dump ? DB_DEFAULT_DUMP_FILE : DB_RESTORE_FILE prompt = "location to save the #{action} file to" [prompt, default, nil, "file that exists"] end
processing_message()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 169 def processing_message msg = if action == :restore "\nRestoring the database..." else "\nRunning Database #{action} to #{uri}..." end say(msg) end
remote_file_prompt_args_for(remote_type)
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 155 def remote_file_prompt_args_for(remote_type) prompt = if action == :restore "location of the remote backup file" else "location to save the remote #{action} file to" end prompt += "\nExample: #{sample_url}" [prompt, remote_type] end
restore()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 200 def restore result = PostgresAdmin.restore(database_opts.merge(:backup_type => backup_type)) ManageIQ::ApplianceConsole.logger.info("[#{@database_opts[:dbname]}] database has been restored from file: [#{uri}]") result end
restore_prompt_args()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 148 def restore_prompt_args default = DB_RESTORE_FILE validator = LOCAL_FILE_VALIDATOR prompt = "location of the local restore file" [prompt, default, validator, "file that exists"] end
run_action()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 178 def run_action success = send(action) if success && action == :restore && delete_agree say("\nRemoving the database restore file #{uri}...") File.delete(uri) elsif !success say("\nDatabase #{action} failed. Check the logs for more information") end end
sample_url()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 165 def sample_url I18n.t("database_admin.sample_url.nfs") end
should_exclude_tables?()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 129 def should_exclude_tables? ask_yn?("Would you like to exclude tables in the dump") do |q| q.readline = true end end
should_split_output?()
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 135 def should_split_output? ask_yn?("Would you like to split the #{action} output into multiple parts") do |q| q.readline = true end end
skip_file_location?(hostname)
click to toggle source
# File lib/manageiq/appliance_console/database_admin.rb, line 123 def skip_file_location?(hostname) config = custom_endpoint_config_for(hostname) return false unless config && config[:enabled_for].present? !Array(config[:enabled_for]).include?(action.to_s) end