01 March 2017

Export the jobs from Cloud Control

In case you need to backup your jobs from Cloud Control, you can use emcli for that. This will give you a quick way to backup or export the job for use elsewhere.

You can setup a script like:

EXPJOB=/home/oracle/export_jobs.sh
echo repdir=/backup/jobs > $EXPJOB

$OMSHOME/bin/emcli login -username=sysman -password=PassWord01

# One command to create the job
$OMSHOME/bin/emcli export_jobs -preview | awk '{ print "./emcli 
export_jobs -file=$repdir/" $1 ".zip -name=\x27" $1 "\x27" }' | sort >> $EXPJOB

#make it executable
chmod 740 $EXPJOB


# run the export
$EXPJOB


The EXPJOB that you create, will look like:

export repdir=/backup/jobs
./emcli export_jobs -file=$repdir/MYJOB01.zip -name='MYJOB01'
./emcli export_jobs -file=$repdir/MYJOB02.zip -name='MYJOB02'
./emcli export_jobs -file=$repdir/MYJOB03.zip -name='MYJOB03'
./emcli export_jobs -file=$repdir/MYJOB04.zip -name='MYJOB04'

If you run it, (from $OMSHOME/bin), it wil generate a seperate zip file for every job.
The zip file contains a single xml file for that job.

If you decide to import it, it will become available in the Job Library.

The import is easily done on the zip file, like:

 ./emcli import_jobs -file=$repdir/MYJOB01.zip

Hope this helps.

01 November 2016

get column result as a row

Today, I had to create a single row from:

Select tablespace_name from dba_tablespaces ;

TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS


This can easily be done with (11.2 and up):

select contents,listagg(TABLESPACE_NAME,',')
  within group
  (order by CONTENTS) my_tbs
  from dba_tablespaces
  group by contents;


CONTENTS  MY_TBS
--------- ---------------------------------------------
PERMANENT SYSAUX,SYSTEM,USERS

TEMPORARY TEMP
UNDO      UNDOTBS1


This works nice!

29 March 2016

kill repeating job when running longer than n minutes


Some repeating jobs may be running in a loop now and then, or should be killed after N minutes for whatever reason you may think off.

You can raise an event when a scheduled job is running longer than N minutes, but this event has to be handled. Otherwise, the job will just continue to run.

Below a small example how to set this up for MYJOB. Important to run from the job owner!

--connect as jobowner: 
conn jobowner/password

-- create a table for output
create table JOB_OUTPUT (
    log_date timestamp with time zone
   ,output varchar2(4000));

-- add an event queue subscriber for this user's messages

exec dbms_scheduler.add_event_queue_subscriber('myagent');

-- set the maximum run time for the jobbegin
  dbms_scheduler.set_attribute(name=>'MYJOB',attribute=>'max_run_duration',value=> numtodsinterval(120,'minute'));
end;
/

-- create a 'sniper' job to kill MYJOB - based on eventbegin
dbms_scheduler.create_job
 ('KILL_MYJOB',
  job_type=>'plsql_block',
  job_action=>

      'insert into job_output values(systimestamp, ''kill_myjob started'');
       dbms_scheduler.stop_job(''KILL_MYJOB'',false);',
  event_condition =>
      'tab.user_data.object_name = ''MYJOB'' and
       tab.user_data.event_type = ''JOB_OVER_MAX_DUR''',
  queue_spec =>'sys.scheduler$_event_queue,myagent',
  enabled=>true);
end;
/

-- you can see in the output table if the job was killed: 

select * from JOB_OUTPUT;


31 December 2015

Migrating your Software Library in Oracle Enterprise Manager 12.1.0.5

The Software Library should be kept on a location where multiple OMS instances can reach it under the same path-name when working with multiple-OMS.
So some sort of shared storage is needed. This may lead to the need to migrate your software libary.

This is a very simple task once you've seen it. Below I will move the software libary from:
/oracle/software/softlib to a new mountpoint /swlib .

First, go to the Software Libary under Setup > Provisioning and Patching.



Second, observe the software library you have and click Add button to create a new one.




Third, select the old software library and select Migrate and Remove button.



Fourth, in the popup window, select your target software libary from the pulldown.


 Observe the confirmation box and click View Job.


The job runs for a few minutes, just wait or get some coffee.


Now the old software library is gone from the Cloud Control:

 But it's still on your host:



So you can free up that space by removing the old directory.

Further reading:
https://docs.oracle.com/cd/E24628_01/doc.121/e24473/softwarelib.htm#EMADM11710