' --用于创建控制文件的语句,丢失了部分信息
控制文件发生变化情况
alter database [add |drop] logfile
alter database [add |drop] logfile member
alter database [add |drop] logfile group
alter database [archivelog |noarchivelog]
alter database rename file
create tablespace
alter tablespace [add | rename] datafile
alter tablespace [read write | read only]
drop tablespace
更多关于控制文件请参考:Oracle 控制文件
五、参数文件的热备
create pfile from spfile ;
create pfile = '' from spfile;
更多关于参数文件请参考:Oracle 参数文件
六、临时表空间的数据文件、日志文件不需要备份
--查看临时表空间
SQL> select tablespace_name from dba_temp_files;
TABLESPACE_NAME
------------------------------
TEMP
--查看临时表空间的数据文件
SQL> select name from v$tempfile;
NAME
------------------------------------------------------
/u01/app/oracle/oradata/orcl/temp01.dbf
--将临时表空间置为备份模式,收到了错误的提示
SQL> alter tablespace temp begin backup;
alter tablespace temp begin backup
*
ERROR at line 1:
ORA-03217: invalid option for alter of TEMPORARY TABLESPACE
--将临时表空间置为备份模式,收到了错误的提示
SQL> alter temporary tablespace temp begin backup;
alter temporary tablespace temp begin backup
*
ERROR at line 1:
ORA-00940: invalid ALTER command
七、热备脚本
1.基于数据库热备的脚本
SQL> ho cat /tmp/tmphotbak.sql;
set feedback off
set heading off
set verify off
set trimspool off
set pagesize 0
set linesize 200
define dir = '/u01/app/oracle/hotbak'
define script = '/tmp/hotbak.sql'
spool &script
select 'ho cp ' ||name|| ' &dir' from v$datafile;
spool off
alter database begin backup;
start &script
alter database end backup;
alter database backup controlfile to '&dir/controlbak.ctl';
create pfile = '&dir/initorcl.ora' from spfile;
SQL> start /tmp/tmphotbak.sql; --执行该脚本即可对数据库进行热备
2.基于表空间热备的脚本
SQL> ho cat /tmp/tmphotbak_tb.sql
set feedback off
set heading off
set verify off
set trimspool off
set pagesize 0
set linesize 200
define dir = '/u01/app/oracle/hotbak'
define script = '/tmp/hotbak_tb.sql'
ho rm &script
ho rm &dir/*
spool &script
select 'alter tablespace '|| tablespace_name ||' begin backup ;' ||
chr(10)||'ho cp ' || file_name || ' &dir ' ||
chr(10)||'alter tablespace '|| tablespace_name || ' end backup;'
from dba_data_files order by tablespace_name;
spool off
start &script
alter database backup controlfile to '&dir/controlbak.ctl';
create pfile = '&dir/initorcl.ora' from spfile;
SQL> start /tmp/tmphotbak.sql; --执行该脚本即可对数据库基于表空间进行热备
八、备份的相关视图
v$backup
SQL> desc v$backup;
Name Null? Type
----------------------------------------- -------- ---------------------
FILE# NUMBER
STATUS VARCHAR2(18)
CHANGE# NUMBER --记录备份时的SCN号
TIME DATE
SQL> select * from v$backup; --状态为NOT ACTIVE ,此时没有任何数据处于备份状态
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ---------
1 NOT ACTIVE 1006747 16-AUG-10
2 NOT ACTIVE 1006793 16-AUG-10
3 NOT ACTIVE 1006729 16-AUG-10
4 NOT ACTIVE 1006807 16-AUG-10
5 NOT ACTIVE 1006717 16-AUG-10
SQL> alter tablespace users begin backup; --对表空间users进行热备
Tablespace altered.
SQL> select * from v$backup; --对应的file# 为的处于ACTIVE状态
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ---------
1 NOT ACTIVE 1006747 16-AUG-10
2 NOT ACTIVE 1006793 16-AUG-10
3 NOT ACTIVE 1006729 16-AUG-10
4 ACTIVE 1006852 16-AUG-10
5 NOT ACTIVE 1006717 16-AUG-10
--备份时发生断电或意外故障的恢复
--假定users表空间目前置于begin bakup模式,系统断电
SQL> alter tablespace users begin backup;
Tablespace altered.
--在另一个会话中强制关闭数据库
SQL> shutdown abort;
ORACLE instance shut down.
--启动后收到错误提示
SQL> startup
ORACLE instance started.
Total System Global Area 469762048 bytes
Fixed Size 1220048 bytes
Variable Size 92275248 bytes
Database Buffers 373293056 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-01113: file 4 needs media recovery
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
--查看备份视图,文件此时处于活动状态
SQL> select * from v$backup;
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ---------
1 NOT ACTIVE 1006958 16-AUG-10
2 NOT ACTIVE 1006983 16-AUG-10
3 NOT ACTIVE 1006943 16-AUG-10
4 ACTIVE 1007072 16-AUG-10
5 NOT ACTIVE 1006931 16-AUG-10
--使用end backup来终止备份
SQL> alter database datafile 4 end backup; --此处也可以使用recover datafile 4来完成恢复
Database altered.
SQL> alter database open;
Database altered.
SQL> select * from dual;
D
-
X
有关Oracle的冷备份,请参考:Oracle 冷备份
九、更多参考
Oracle 冷备份
SPFILE错误导致数据库无法启动
Oracle 用户、对象权限、系统权限
Oracle 角色、配置文件
Oracle 联机重做日志文件(ONLINE LOG FILE)
Oracle 控制文件(CONTROLFILE)
Oracle 表空间与数据文件
Oracle 归档日志