首先了解各种set值含义,参考: http://blog.csdn.net/rlhua/article/details/11849883
RMAN脚本: http://blog.csdn.net/rlhua/article/details/12714647
手工热备份脚本: http://blog.csdn.net/rlhua/article/details/11850629
1、新建两个目录,分别为cold_bak和hot_bak,分别用作冷备份和热备份转储的位置。
[oracle@rtest oracle]$ cd bak
[oracle@rtest bak]$ mkdir cold_bak
[oracle@rtest bak]$ mkdir hot_bak
[oracle@rtest bak]$ pwd
/u01/app/oracle/bak
[oracle@rtest bak]$ ls
cold_bak hot_bak
2、冷备份,即拷贝数据文件和控制文件到新的位置,转储。
首先查看需要备份的数据文件和控制文件的位置。
sys@TEST0910> select name from v$datafile order by 1;
NAME
----------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/test0910/example01.dbf
/u01/app/oracle/oradata/test0910/sysaux01.dbf
/u01/app/oracle/oradata/test0910/system01.dbf
/u01/app/oracle/oradata/test0910/testtb.dbf
/u01/app/oracle/oradata/test0910/undotbs01.dbf
/u01/app/oracle/oradata/test0910/users01.dbf
6 rows selected.
sys@TEST0910> select name from v$controlfile order by 1;
NAME
----------------------------------------------------------------------------------------------------
/u01/app/oracle/fast_recovery_area/test0910/control02.ctl
/u01/app/oracle/oradata/test0910/control01.ctl
3、拼SQL语句。执行操作系统拷贝命令。
sys@TEST0910> set verify on
sys@TEST0910> select 'host cp ' ||name|| ' &bakdir' from v$datafile order by 1;
Enter value for bakdir: /u01/app/oracle/bak/cold_bak
old 1: select 'host cp ' ||name|| ' &bakdir' from v$datafile order by 1
new 1: select 'host cp ' ||name|| ' /u01/app/oracle/bak/cold_bak' from v$datafile order by 1
'HOSTCP'||NAME||'/U01/APP/ORACLE/BAK/COLD_BAK'
----------------------------------------------------------------------------------------------------
host cp /u01/app/oracle/oradata/test0910/example01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/sysaux01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/system01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/testtb.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/undotbs01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/users01.dbf /u01/app/oracle/bak/cold_bak
6 rows selected.
sys@TEST0910> select 'host cp ' ||name|| ' &bakdir' from v$controlfile order by 1;
Enter value for bakdir: /u01/app/oracle/bak/cold_bak
old 1: select 'host cp ' ||name|| ' &bakdir' from v$controlfile order by 1
new 1: select 'host cp ' ||name|| ' /u01/app/oracle/bak/cold_bak' from v$controlfile order by 1
'HOSTCP'||NAME||'/U01/APP/ORACLE/BAK/COLD_BAK'
----------------------------------------------------------------------------------------------------
host cp /u01/app/oracle/fast_recovery_area/test0910/control02.ctl /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/control01.ctl /u01/app/oracle/bak/cold_bak
[oracle@rtest bak]$ vi cold_bak.sql
set echo off trimspool off heading off feedback off verify off time off
set pagesize 0 linesize 200
define bakdir='/u01/app/oracle/bak/cold_bak'
define bakscp='/u01/app/oracle/bak/cold_cmd.sql'
spool &bakscp
select 'host cp ' ||name|| ' &bakdir' from v$datafile order by 1;
select 'host cp ' ||name|| ' &bakdir' from v$controlfile order by 1;
spool off
shutdown immediate
@&bakscp
startup
sys@TEST0910> @/u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/example01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/sysaux01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/system01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/testtb.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/undotbs01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/users01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/fast_recovery_area/test0910/control02.ctl /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/control01.ctl /u01/app/oracle/bak/cold_bak
Database closed.
Database dismounted.
ORACLE instance shut down.
ORACLE instance started.
Total System Global Area 2505338880 bytes
Fixed Size 2230952 bytes
Variable Size 587203928 bytes
Database Buffers 1895825408 bytes
Redo Buffers 20078592 bytes
Database mounted.
Database opened.
系统位置查看:
[oracle@rtest bak]$ more cold_bak.sql
set echo off trimspool off heading off feedback off verify off time off
set pagesize 0 linesize 200
define bakdir='/u01/app/oracle/bak/cold_bak'
define bakscp='/u01/app/oracle/bak/cold_cmd.sql'
spool &bakscp
select 'host cp ' ||name|| ' &bakdir' from v$datafile order by 1;
select 'host cp ' ||name|| ' &bakdir' from v$controlfile order by 1;
spool off
shutdown immediate
@&bakscp
startup
[oracle@rtest bak]$ more cold_cmd.sql
host cp /u01/app/oracle/oradata/test0910/example01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/sysaux01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/system01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/testtb.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/undotbs01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/users01.dbf /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/fast_recovery_area/test0910/control02.ctl /u01/app/oracle/bak/cold_bak
host cp /u01/app/oracle/oradata/test0910/control01.ctl /u01/app/oracle/bak/cold_bak
[oracle@rtest bak]$ cd cold_bak
[oracle@rtest cold_bak]$ ls
control01.ctl control02.ctl example01.dbf sysaux01.dbf system01.dbf testtb.dbf undotbs01.dbf users01.dbf