Class: PuppetX::EnterpriseModules::Oracle::RmanCommand
- Includes:
- EasyType::Encryption, EasyType::Template, Settings
- Defined in:
- lib/puppet_x/enterprisemodules/oracle/rman_command.rb
Overview
docs
Instance Attribute Summary collapse
-
#catalog_conn ⇒ Object
readonly
Returns the value of attribute catalog_conn.
-
#sid ⇒ Object
readonly
Returns the value of attribute sid.
-
#target_conn ⇒ Object
readonly
Returns the value of attribute target_conn.
Attributes inherited from Command
#os_user, #password, #timeout, #username
Instance Method Summary collapse
- #command_string(arguments = '') ⇒ Object
- #execute(arguments, powershell_script = '') ⇒ Object
- #execute_sql_command(command, output_file) ⇒ Object
-
#initialize(options = {}) ⇒ RmanCommand
constructor
A new instance of RmanCommand.
Methods included from Settings
#asm_sid?, #asm_sids, #configuration, #configuration_for, #configuration_value_for, #container_db?, #database_sid?, #database_sids, #default_asm_sid, #default_database_sid, #default_sids, included, #local_pdb?, #mgmt_sid?, #mgmt_sids, #normal_db?, #num_default_asm_sids, #num_default_database_sids, #read_from_yaml, #registered_sids, #remote_sid?, #running_asm_sids, #running_database_sids, #running_db?, #running_mgmt_sids, #running_mt_database_sids, #running_nopdb_database_sids, #running_normal_database_sids, #running_pdb?, #running_primary_database_sids, #running_sids, #settings_file, #valid_asm_sid?, #valid_database_sid, #valid_sid?
Methods included from Information
#cached_sid_value, #cluster?, #cluster_instances, #containerdb?, #database_properties, #database_version, #db_create_file_dest, #db_domain, #db_for, #diagnostic_dest, included, #local_sid_for_db, #open_pdbs, #oracle_major_version, #oracle_managed_files_enabled?, #pdb?, #primary?, #rootdb?, #seeddb?, #sid_for, #value_for_init_param
Constructor Details
#initialize(options = {}) ⇒ RmanCommand
Returns a new instance of RmanCommand.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet_x/enterprisemodules/oracle/rman_command.rb', line 25 def initialize( = {}) target = [:target_conn].nil? ? 'target /' : "target #{[:target_conn]}" catalog = [:catalog_conn].nil? ? 'nocatalog' : "catalog #{[:catalog_conn]}" super("rman #{target} #{catalog}", , RMAN_VALID_OPTIONS) # # Set only values that are needed # # rubocop:disable Lint/UselessAssignment os_user = configuration_value_for(@sid, 'os_user') # rubocop:enable Lint/UselessAssignment @oracle_home = configuration_value_for(@sid, 'oracle_home') @contained_by = configuration_value_for(@sid, 'contained_by') @host_sid = if @contained_by.nil? || @contained_by.empty? @sid else @contained_by end end |
Instance Attribute Details
#catalog_conn ⇒ Object (readonly)
Returns the value of attribute catalog_conn.
23 24 25 |
# File 'lib/puppet_x/enterprisemodules/oracle/rman_command.rb', line 23 def catalog_conn @catalog_conn end |
#sid ⇒ Object (readonly)
Returns the value of attribute sid.
23 24 25 |
# File 'lib/puppet_x/enterprisemodules/oracle/rman_command.rb', line 23 def sid @sid end |
#target_conn ⇒ Object (readonly)
Returns the value of attribute target_conn.
23 24 25 |
# File 'lib/puppet_x/enterprisemodules/oracle/rman_command.rb', line 23 def target_conn @target_conn end |
Instance Method Details
#command_string(arguments = '') ⇒ Object
44 45 46 47 48 |
# File 'lib/puppet_x/enterprisemodules/oracle/rman_command.rb', line 44 def command_string(arguments = '') "su - #{@os_user} -c \"cd #{working_dir};export PERL5LIB=$(ls -d #{@oracle_home}/perl/lib/[0-9]*);export NLS_LANG=english;export ORACLE_SID=#{@host_sid};export ORACLE_HOME=#{@oracle_home};unset TNS_ADMIN;unset TWO_TASK;export PATH=#{@oracle_home}/bin:$PATH; #{@command} <<-EOF #{arguments}; EOF\"" end |
#execute(arguments, powershell_script = '') ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/puppet_x/enterprisemodules/oracle/rman_command.rb', line 50 def execute(arguments, powershell_script = '') = { :failonfail => true, :combine => true } command = if Puppet::Util::Platform.windows? %(powershell -File "#{powershell_script}") else command_string(arguments) end Puppet.debug "rman_command.rb: Executing #{@command} command: #{arguments} as user #{os_user}" value = Puppet::Util::Execution.execute(command, ) Puppet.debug "rman_command.rb: Output:\n #{value}" value.encode!('UTF-8', :invalid => :replace, :undef => :replace) # Strip 'header' and 'footer' value[/\n\nRMAN> \n(.*)\nRMAN> /m, 1] end |
#execute_sql_command(command, output_file) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/puppet_x/enterprisemodules/oracle/rman_command.rb', line 66 def execute_sql_command(command, output_file) # # Do the stuff # Puppet.debug "rman_command.rb: Executing sql statement :\n #{command}" script = command_file(template('ora_config/ora_config/execute.sql.erb', binding)) if Puppet::Util::Platform.windows? # rubocop:disable Lint/UselessAssignment powershell_script = command_file(template('ora_config/ora_config/rman_command.ps1.erb', binding), type = '.ps1') # rubocop:enable Lint/UselessAssignment Puppet.debug "rman_command.rb: Using powershell script: #{powershell_script}" end if username Puppet.debug "rman_command.rb: Connecting to oracle_sid #{@sid} with connect_string \"#{@connect_string}\" as user #{username} and privilege #{@syspriv}" else Puppet.debug "rman_command.rb: Connecting to oracle_sid #{@sid} with connect_string \"#{@connect_string}\" as user #{@sys_username} and privilege #{@syspriv}" end execute("@#{script}", powershell_script) content = File.read(output_file) content.encode!('UTF-8', :invalid => :replace, :undef => :replace) content end |