冷备份数据库的步骤
(1)关闭数据库;
(2)备份所有相关的数据库文件:初始化参数文件、控制文件(可用select name from v$controlfile;列出所有
控制文件)、数据文件(可用select name from v$datafile;列出所有数据文件)、Redo日志(可用select member from v$logfile;列出所有redo日志文件)、归档的Redo日志(可用select sequence#,first_time from v$loghist;列出所有归档redo日志文件的顺序号和产生时间)。
冷备份数据库的步骤
(1)关闭数据库;
(2)备份所有相关的数据库文件:
初始化参数文件(show parameter spfile;)
控制文件(可用select name from v$controlfile;列出所有控制文件)
数据文件(可用select name from v$datafile;列出所有数据文件)
Redo日志(可用select member from v$logfile;列出所有redo日志文件)
归档的Redo日志(可用select sequence#,first_time from v$loghist;列出所有归档redo日志文件的顺序号和产生时间)
sql>shutdown immediate;
sql>!cp /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfilesktest.ora /oraclebackup/spfilesktest.ora
sql>!cp /u01/app/oracle/oradata/sktest/control01.ctl /oraclebackup/control01.ctl
sql>!cp /u01/app/oracle/flash_recovery_area/sktest/control02.ctl /oraclebackup/control02.ctl
sql>!cp /u01/app/oracle/oradata/sktest/system01.dbf /oraclebackup/system01.dbf
sql>!cp /u01/app/oracle/oradata/sktest/sysaux01.dbf /oraclebackup/sysaux01.dbf
sql>!cp /u01/app/oracle/oradata/sktest/undotbs01.dbf /oraclebackup/undotbs01.dbf
sql>!cp /u01/app/oracle/oradata/sktest/users01.dbf /oraclebackup/users01.dbf
sql>!cp /u01/app/oracle/oradata/sktest/skuser.dbf /oraclebackup/skuser.dbf
sql>!cp /u01/app/oracle/oradata/sktest/UMSITE001.dbf /oraclebackup/UMSITE001.dbf
sql>!cp /u01/app/oracle/oradata/sktest/redo01.log /oraclebackup/redo01.log
sql>!cp /u01/app/oracle/oradata/sktest/redo02.log /oraclebackup/redo02.log
sql>!cp /u01/app/oracle/oradata/sktest/redo03.log /oraclebackup/redo03.log
sql>!cp /u01/app/oracle/oradata/sktest/redo04.log /oraclebackup/redo04.log
sql>startup
[oracle@linuxForOra coldbackup]$ vi coldbak.sql
第一种脚本:
#rem desc:offline full backup database
$ORACLE_HOME/bin/sqlplus "/as sysdba" <<EOF
shutdown immediate
!cp /u01/oracle/oradata/general10g/*.dbf /u01/oracle/coldbackup/
!cp /u01/oracle/oradata/general10g/*.ctl /u01/oracle/coldbackup/
!cp /u01/oracle/oradata/general10g/*.log /u01/oracle/coldbackup/
startup
第二种脚本:
set pagesize 0 linesize 32767 feedback off verify off trimspool on termout off trimout on serveroutput on
define fil=/u01/oracle/coldbk.sql
define log=/u01/oracle/coldbk.log
spool &fil
prompt connect sys/syspass@general10g as sysdba;
prompt shutdown immediate;
select 'host cp ' file_name '/u01/oracle/coldbackup' substr(file_name,instr(file_name,'/',-1,1)) from dba_data_files;
prompt startup
spool off
spool &log
@&fil;
spool off;
注意:脚本改成可执行权限
rman恢复实践
su - oracle
$rman
connect target /
show all;
设定参数:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/oracle/arch/rman/controlfile%F.ctnl';
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT '/u01/app/oracle/arch/rman/full%t.bak';
数据库rman 全备
rman>backup database plus archivelog delete input;
备份产生的三个文件
-rw-r----- 1 oracle oinstall 7143424 Jan 28 18:05 controlfilec-2719028776-20100128-01.ctnl
-rw-r----- 1 oracle oinstall 41074688 Jan 28 18:03 full709495428.bak
-rw-r----- 1 oracle oinstall 763379712 Jan 28 18:05 full709495432.bak
-rw-r----- 1 oracle oinstall 17920 Jan 28 18:05 full709495518.bak
rman恢复
------------------
1、启动数据库到 nomount 状态
$sqlplus / as sysdba
SQL> startup nomount
2、spfile 恢复
$rman nocatalog
rman> connect target /
run {
allocate channel c1 DEVICE TYPE DISK format '/arch/rman/controlfile%F.ctnl';
restore spfile to pfile '/arch/pfile.ora' from '/arch/rman/controlfilec-2719028776-20100128-01.ctnl';
release channel c1;
}
3、控制文件恢复
run {
allocate channel c1 DEVICE TYPE DISK format '/arch/rman/controlfile%F.ctnl';
restore controlfile from '/arch/rman/controlfilec-2719028776-20100128-01.ctnl';
release channel c1;
}
4、全库恢复
在恢复控制文件的情况下,可以修改数据到 mount状态,进行全库的恢复
rman> alter database mount;
run {
allocate channel c1 device type disk format '/arch/rman/full%t.bak';
restore database;
release channel c1;
}
5、恢复archivelog
run {
allocate channel c1 device type disk format '/arch/rman/full%t.bak';
restore archivelog all;
}
run {
allocate channel c1 device type disk format '/arch/rman/full%t.bak';
restore archivelog from logseq=72 until logseq=73;
}
6、redolog 恢复
SQL>recover database using backup controlfile until cancel;
SQL>alter database open resetlogs; //现在有redolog 产生了,还有temp表空间文件也生成了或者分开两步执行
SQL>select * from dual;
全库成功恢复
--转自