Here is some dynamic SQL that you can run on your current database. You will need to change
things like '||CHR(36)||'{DBPASS} to your password for sys and '/&oraclesid/' to the old database,
as well as '||CHR(36)||'{TARGET_SID}/')||''' to your new database. Basically play with the queries
until you get the right output.
Code:
DEFINE oraclesid='&1'
select '#!/bin/bash' from dual;
select 'export TARGET_SID='||CHR(36)||'{1}' from dual;
select '. /oracle/bin/set_oracle_env.sh '||CHR(36)||'{TARGET_SID}' from dual;
select '. /oracle/bin/getPwd.sh `'||CHR(36)||
'{ORACLE_HOME}/bin/sqlplus -s -v | cut -d" " -f3 | cut -d"." -f1-2`'
from dual;
select 'echo "sid name |${TARGET_SID}|"' from dual;
select 'rman << EOF' from dual;
select 'connect catalog '||CHR(36)||'{DBPASS};' from dual;
select 'connect target /;' from dual;
select 'set echo on;' from dual;
select 'set dbid '||dbid||';' from v$database;
select 'run {' from dual;
select ' set command id to ''clone'';' from dual;
select ' SET NEWNAME FOR DATAFILE '||file_id||' TO '''||
REPLACE(file_name, '/&oraclesid/', '/'||CHR(36)||'{TARGET_SID}/')||''';' line
from dba_data_files
order by file_id;
select ' SET NEWNAME FOR TEMPFILE '||file_id||' TO '''||
REPLACE(file_name, '/&oraclesid/', '/'||CHR(36)||'{TARGET_SID}/')||''';' line
from dba_temp_files
order by file_name;
select ' restore controlfile;' from dual;
select ' alter database mount;' from dual;
select ' restore database force;'
from dual;
select ' recover database;'
from dual;
select '}' from dual;
select 'EOF' from dual;