1. Export Prod Database
The procedure SCHEMA_REFRESH.EXPORT_PROD creates the export file. This procedure is the API for the export Data Pump.This is where Data Pump export utility is executed from the Test server against the production database remotely. The export dump file is saved on the Test server; see Listing 1.
procedure export_prod
as
ind NUMBER; -- Loop index
h1 NUMBER; -- Data Pump job handle
percent_done NUMBER; -- Percentage of job complete
job_state VARCHAR2(30); -- To keep track of job state
le ku$_LogEntry; -- For WIP and error messages
js ku$_JobStatus; -- The job status from get_status
-- jd ku$_JobDesc; -- The job description from get_status
sts ku$_Status; -- The status object returned by get_status
begin
h1 := dbms_datapump.open (operation => 'EXPORT', remote_link => 'ESCIS.ETA.DIR.LABOR.GOV', job_mode => 'SCHEMA', version => 'COMPATIBLE');
dbms_datapump.set_parallel(handle => h1, degree => 1);
dbms_datapump.add_file(handle => h1, filename => 'EXPDAT.LOG', filetype => 3);
DBMS_DATAPUMP.metadata_filter (HANDLE =>h1,NAME => 'EXCLUDE_PATH_EXPR',VALUE=>'IN(''JOB'')');
DBMS_DATAPUMP.metadata_filter (HANDLE =>h1,NAME => 'EXCLUDE_PATH_EXPR',VALUE=>'IN(''SYNONYM'')');
dbms_datapump.metadata_filter(handle => h1, name => 'NAME_EXPR', value =>'!=''MULTIMEDIA''' , object_type => 'TABLE');
dbms_datapump.add_file(handle => h1, filename => 'refresh.dmp', filetype => 1);
dbms_datapump.metadata_filter(handle => h1, name => 'SCHEMA_EXPR', value => 'IN(''WEB_USER'', ''R11'' )');
dbms_datapump.start_job(handle => h1, skip_current => 0, abort_step => 0);
percent_done := 0;
job_state := 'UNDEFINED';
while (job_state != 'COMPLETED') and (job_state != 'STOPPED') loop
dbms_datapump.get_status(h1,
dbms_datapump.ku$_status_job_error +
dbms_datapump.ku$_status_job_status +
dbms_datapump.ku$_status_wip,-1,job_state,sts);
js := sts.job_status;
if js.percent_done != percent_done
then
dbms_output.put_line('*** Job percent done = ' ||
to_char(js.percent_done));
percent_done := js.percent_done;
end if;
-- If any work-in-progress (WIP) or error messages were received for the job,
-- display them.
if (bitand(sts.mask,dbms_datapump.ku$_status_wip) != 0)
then
le := sts.wip;
else
if (bitand(sts.mask,dbms_datapump.ku$_status_job_error) != 0)
then
le := sts.error;
else
le := null;
end if;
end if;
if le is not null
then
ind := le.FIRST;
while ind is not null loop
dbms_output.put_line(le(ind).LogText);
ind := le.NEXT(ind);
end loop;
end if;
end loop;
Note: The command below shows how the export is performed remotely:
h1 := dbms_datapump.open (operation => 'EXPORT', remote_link => 'ESCIS.ETA.DIR.LABOR.GOV', job_mode => 'SCHEMA', version => 'COMPATIBLE');
where 'ESCIS.ETA.DIR.LABOR.GOV' is name of the database link that's linked to the Production database.
Note: The following excerpt from Listing 1 shows how to list schemas to be exported:
dbms_datapump.metadata_filter(handle => h1, name => 'SCHEMA_EXPR', value => 'IN(''WEB_USER'', ''R11'' )');
where the schema names to be exported are "WEB_USER" and "R11".
Note: The following excerpt from Listing 1 shows how to exclude tables from the export:
dbms_datapump.metadata_filter(handle => h1, name => 'NAME_EXPR', value =>'!=''MULTIMEDIA''' , object_type => 'TABLE');
where "MULTIMEDIA" is the name of my table to be excluded.


