host move D:\admin\DATABASE\datapumpdir\EXPDP_DATABASE*.DMP D:\admin\DATABASE\datapumpdir\old\.
DECLARE
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
rtn_code number:=0;
BEGIN
h1 := dbms_datapump.open (operation => 'EXPORT',
job_mode => 'SCHEMA', job_name => 'EXPDP_DATABASE'||to_char(sysdate,'YYYYMMDD'),
version => 'COMPATIBLE');
dbms_datapump.set_parallel(handle => h1, degree => 4);
dbms_datapump.add_file(handle => h1, filename => 'EXPDP_DATABASE_'||to_char(sysdate,'YYYYMMDD')||'.LOG',
directory => 'SCHEMA_NAME_EXPDP', filetype => 3);
dbms_datapump.set_parameter(handle => h1, name => 'KEEP_MASTER', value => 0);
dbms_datapump.metadata_filter(handle => h1, name => 'SCHEMA_EXPR', value => 'IN(''SCHEMA_NAME'')');
dbms_datapump.add_file(handle => h1, filename => 'EXPDP_DATABASE%%U.DMP', directory => 'SCHEMA_NAME_EXPDP', filetype => 1);
dbms_datapump.set_parameter(handle => h1, name => 'INCLUDE_METADATA', value => 1);
dbms_datapump.set_parameter(handle => h1, name => 'DATA_ACCESS_METHOD', value => 'AUTOMATIC');
dbms_datapump.set_parameter(handle => h1, name => 'ESTIMATE', value => 'BLOCKS');
dbms_datapump.start_job(handle => h1, skip_current => 0, abort_step => 0);
percent_done := 0;
job_state := 'UNDEFINED';
-- dbms_output.put_line('here1');
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 the percentage done changed, display the new value.
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;
-- Indicate that the job finished and detach from it.
if job_state != 'COMPLETED' then
rtn_code:=1;
end if;
dbms_output.put_line('Job has completed, rtn_code='||to_char(rtn_code));
dbms_output.put_line('Final job state = ' || job_state);
dbms_datapump.detach(h1);
EXCEPTION
WHEN OTHERS THEN
rtn_code:=1;
dbms_output.put_line('Job FAILED, rtn_code='||to_char(rtn_code));
END;
/
|