一致性备份与非一致性备份
一致性备份指数据处于关闭状态下用操作系统命令进行备份的方法,也叫冷备份。一致性既适用于archive log模式与适用于noarchivelog模式;
非一致性备份指数据库处于打开状态进行的备份,仅适用于archivelog模式
数据库:
一致性备份:
1、 shutdown immediate;
2、 拷贝文件:
SQL>ho cp /opt/app/oracle/oradata/orcl/system01.dbf /opt/backup/;
SQL>ho cp /opt/app/oracle/oradata/orcl/undotbs01.dbf /opt/backup/;
SQL>ho cp /opt/app/oracle/oradata/orcl/sysaux01.dbf /opt/backup/;
SQL>ho cp /opt/app/oracle/oradata/orcl/users01.dbf /opt/backup/;
SQL>ho cp /opt/app/oracle/oradata/orcl/example01.dbf /opt/backup/;
SQL>ho cp /opt/app/oracle/oradata/orcl/crmdata_001.dbf /opt/backup/;
3、
Startup;
非一致性备份:
1、开始备份:
SQL> alter database begin backup;
Database altered.
2、拷贝数据文件:
SQL> ho cp /opt/app/oracle/oradata/orcl/system01.dbf /home/oracle/backup/;
ho cp /opt/app/oracle/oradata/orcl/undotbs01.dbf /home/oracle/backup/;
ho cp /opt/app/oracle/oradata/orcl/sysaux01.dbf /home/oracle/backup/;
ho cp /opt/app/oracle/oradata/orcl/users01.dbf /home/oracle/backup/;
ho cp /opt/app/oracle/oradata/orcl/example01.dbf /home/oracle/backup/;
ho cp /opt/app/oracle/oradata/orcl/crmdata_001.dbf /home/oracle/backup/;
3、备份控制文件:
SQL> alter database backup controlfile to '/home/oracle/backup/demo.ctl';
4、结束备份:
SQL> alter database end backup;
5、归档当前日志:
SQL> alter system archive log current ;
System altered.
表空间:
表空间备份仅适用于archivelog模式。可备份表空间的所有数据文件或指定的文件。
1、 脱机备份;
即离线方式备份,优点为产生的UNDO较少,缺点影响业务。因system、UNDO不能离线,此方法不适用于这两种表空间。
备份指定表空间数据文件1:
SQL> alter tablespace crmdata offline;
Tablespace altered.
SQL> ho cp /opt/app/oracle/oradata/orcl/crmdata_001.dbf /home/oracle/backup2;
SQL> ho ls -l /home/oracle/backup2;
total 2099212
-rw-r----- 1 oracle oinstall 2147491840 Aug 20 20:53 crmdata_001.dbf
SQL> alter tablespace crmdata online;
Tablespace altered.
备份指定表空间数据文件2:
SQL> alter tablespace users begin backup;
Tablespace altered.
SQL> ho cp /opt/app/oracle/oradata/orcl/users01.dbf /home/oracle/backup2;
SQL> shutdown immediate;
---此时无法关闭数据库
ORA-01149: cannot shutdown - file 4 has online backup set
ORA-01110: data file 4: '/opt/app/oracle/oradata/orcl/users01.dbf'
SQL> select *from v$backup;
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- --------------
1 NOT ACTIVE 733350 20-8月 -12
2 NOT ACTIVE 733350 20-8月 -12
3 NOT ACTIVE 733350 20-8月 -12
4 ACTIVE 734213 20-8月 -12
---当前active
5 NOT ACTIVE 733350 20-8月 -12
6 NOT ACTIVE 733350 20-8月 -12
SQL> alter tablespace users end backup;
Tablespace altered.
如果在备份过程实例失败,那么启动时会提示ora-01113、ora-01110错误,需要进行介质恢复。
处理办法:
1. startup mount;
2. SQL> select * from v$backup where status='ACTIVE';
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- --------------
4 ACTIVE 734213 20-8月 -12
3. 有以下办法:
a) Alter database end backup; ---针对数据库
Alter database datafile 4 end backup; ---针对数据文件
Alter tablespace user end backup; ---针对表空间
b) Recover datafile 4;
--结束备份状态
2、 只读表空间备份:
SQL> alter tablespace CRMDATA read only;
Tablespace altered.
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_ STATUS
----------- ---------
SYSTEM
ONLINE
UNDOTBS1
ONLINE
SYSAUX
ONLINE
TEMP
ONLINE
USERS
ONLINE
EXAMPLE
ONLINE
CRMDATA
READ ONLY
7 rows selected.
SQL> ho cp /opt/app/oracle/oradata/orcl/crmdata_001.dbf /home/oracle/backup2;
SQL> alter tablespace CRMDATA read write;
Tablespace altered.
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_ STATUS
----------- ---------
SYSTEM
ONLINE
UNDOTBS1
ONLINE
SYSAUX
ONLINE
TEMP
ONLINE
USERS
ONLINE
EXAMPLE
ONLINE
CRMDATA
ONLINE
7 rows selected.
----只读表空间的内容不会变化,因此直接复制即可。
控制文件的备份
1、 以下命令均会造成数据库配置的改变:
Alter database [add|drop] logfile;
Alter database [add|drop] logfile member;
Alter database [add|drop| logfile group;
Alter database [noarchivelog|archivelog]
Alter database rename file;
Creae tablespace;
Alter tabspace [add|rename] datafile;
Alter tablespace [read write|read only];
Drop tablespace;
控制文件记录和维护数据库,这些改变需要从控制文件中读取,控制文件损坏会导致这些信息的丢失。
1、 建立控制文件副本:
Alter database backup controlfile to ‘/home/oracle/backup/demo.ctl’;
---如果此文件存在,会报错。加reuse参数可直接覆盖掉原有备份。
Alter database backup controlfile to ‘/home/oracle/backup/demo.ctl’ reuse;
2、 备份到跟踪文件:
Alter database backup controlfile to trace; ----备份到user_dump_dest指定的位置;
Alter database backup controlfile to trace as ‘/home/oracle/backup’ ---指定位置