新博客http://www.cnblogs.com/zhjh256 欢迎访问
分类: Oracle
2008-01-06 21:55:28
10.2.0.1 SE下'TSPITR'
DBA不能出错的最重要的任务是备份和恢复。
问题描述:
终端用户通过GUI不小心删除了300条记录,并且CASCADE DELETE的存在导致了多个表的损坏,但是这些表包含在一个表空间中,因此并没有损坏整个数据库。删除时间在6:00AM之后,并且希望将数据恢复到6:00AM。
解决办法:
此时我们必须执行时间点表空间恢复,但是问题是Standard Edition,不能使用'RECOVER TABLESPACE USERS UNTIL TIME...',自动TSPITR是EE的特征。在这种情况下必须执行手工的恢复操作。
高层次的步骤如下:
·列出需要恢复的表空间;
·找出将被删除的对象;
·拷贝生产表空间SYSTEM, SYSAUX, UNDOTBS1,和受影响的表空间;全部增量备份,最近的控制文件备份,所有归档日志备份,pfile/spfile到新的服务器上;
·在新的服务器上,更改PFILE,启动数据库到NOMOUNT模式;
·转储备份的控制文件,装载数据库;
·CATALOG拷贝的备份;
·运行RMAN restore/recover…UNTIL TIME跳过不需要的表空间;
·以resetlogs打开数据库;
·使用export/import将数据传输回生产库。
详细的步骤如下:
1.首先,隔离表空间:
SELECT *
FROM SYS.TS_PITR_CHECK
WHERE (TS1_NAME IN ('tbs1', 'tbs2') AND
TS2_NAME NOT IN ('tbs1', 'tbs2'))
OR (TS1_NAME NOT IN ('tbs1', 'tbs2') AND
TS2_NAME IN ('tbs1', 'tbs2'));
确保不会返回任何行,否则解决依赖性。
2.找出在执行表空间时间点恢复后将会被删除的对象:
SELECT OWNER,
NAME,
TABLESPACE_NAME,
TO_CHAR(CREATION_TIME, 'YYYY-MM-DD:HH24:MI:SS')
FROM SYS.TS_PITR_OBJECTS_TO_BE_DROPPED
WHERE TABLESPACE_NAME IN ('SYSTEM', 'USERS')
AND CREATION_TIME >
TO_DATE('3-1月-2008 11:00:00', 'DD-MON-YYYY HH24:MI:SS')
ORDER BY TABLESPACE_NAME, CREATION_TIME;
如果有对象返回,则考虑转储到另外的位置,或者抛弃;
3.在企业版中,可以执行如下操作:
RECOVER TABLESPACE tbs1, tbs2 UNTIL TIME "TO_DATE('3-1月-2008 11:00:00','DD-MON-YYYY HH24:MI:SS')"
AUXILIARY DESTINATION '/home/oracle/tspitr';
但是,如果使用标准版,那么将要更多的时间处理,最好是有一个拷贝的生产环境配置。
4.从生产服务器拷贝SYSTEM, SYSAUX, UNDOTBS1, tbs1, tbs2备份,以及全部增量备份,最近的控制文件备份,所有归档日志备份到新的服务器;
如下:
$ scp /oracle/flash_recovery_area/PROD/datafile/system.dbf
newserver:/home/oracle/backup/.
$ scp /oracle/flash_recovery_area/PROD/datafile/sysaux.dbf
newserver:/home/oracle/backup/.
$ scp /oracle/flash_recovery_area/PROD/datafile/undotbs1.dbf
newserver:/home/oracle/backup/.
$ scp /oracle/flash_recovery_area/PROD/datafile/users.dbf
newserver:/home/oracle/backup/.
$ scp /oracle/flash_recovery_area/PROD/datafile/tools.dbf
newserver:/home/oracle/backup/.
$ scp /oracle/flash_recovery_area/PROD/backupset/2007_09_08/*.bkp
newserver:/home/oracle/backup/.
$ scp /oracle/flash_recovery_area/PROD/archivelog/2007_09_08/*.arc
newserver:/home/oracle/backup/.
$ scp /oracle/flash_recovery_area/PROD/autobackup/2007_09_08/*.bkp
newserver:/home/oracle/backup/.
$ scp $ORACLE_HOME/dbs/spfilePROD.ora
newserver:/u01/app/oracle/product/10.2.0/db_1/dbs/.
5.在新的服务器上,执行export ORACLE_SID=prod
6.改变恰当的初始化参数
COMPATIBLE=10.2.0.1.0
DB_NAME=proddb
SGA_TARGET=400M
PGA_AGGREGATE_TARGET=100M
BACKGROUND_DUMP_DEST=/u01/app/oracle/admin/prodb/bdump
USER_DUMP_DEST=/u01/app/oracle/admin/proddb/udump
AUDIT_FILE_DEST=/u01/app/oracle/admin/proddb/adump
CORE_DUMP_DEST=/u01/app/oracle/admin/proddb/cdump
DB_CREATE_FILE_DEST=/u02/oradata
DB_RECOVERY_FILE_DEST_SIZE=50G
DB_RECOVERY_FILE_DEST=/u02/flash_recovery_area
UNDO_MANAGEMENT=AUTO
UNDO_RETENTION=900
UNDO_TABLESPACE=UNDOTBS1
7.创建恰当的目录
$ cd $ORACLE_ADMIN
$ mkdir proddb; cd proddb; mkdir bdump cdump adump udump
8.启动数据库
RMAN> STARTUP NOMOUNT PFILE='/home/oracle/backup/pfile.ora';
9.从备份转储第四步拷贝的控制文件:
RMAN> RESTORE CONTROLFILE FROM ‘/home/oracle/backup/
该操作应该会创建两个控制文件,一个在/u02/oradata/PRODDB/controlfile,另一个在/u02/flash_recovery_area/PRODDB/controlfile;
10.Catalog备份:
RMAN> CATALOG START WITH ‘/home/oracle/backup/’;
11.重命名REDO和临时文件:
SQL> ALTER DATABASE RENAME FILE ‘
SQL> ALTER DATABASE RENAME FILE ‘
SQL> ALTER DATABASE RENAME FILE ‘
SQL> ALTER DATABASE RENAME FILE ‘
确保指向了正确的目录;
12.运行转储和恢复:
RUN
{
ALLOCATE CHANNEL CH1 DEVICE TYPE DISK;
ALLOCATE CHANNEL CH2 DEVICE TYPE DISK;
# SET UNTIL the date just before you want to recover to.
SET UNTIL TIME "TO_DATE('09-OCT-2007
# Set newname for SYSTEM, SYSAUX, UNDOTBS1, USERS and TOOLS datafiles.
SET NEWNAME FOR DATAFILE 1 TO NEW;
SET NEWNAME FOR DATAFILE 2 TO NEW;
SET NEWNAME FOR DATAFILE 3 TO NEW;
SET NEWNAME FOR DATAFILE 64 TO NEW;
SET NEWNAME FOR DATAFILE 65 TO NEW;
# Restore database and skip all the tablespaces that you DON'T want restored.
RESTORE DATABASE SKIP FOREVER TABLESPACE TBS1, TBS2, TBS3;
SWITCH DATAFILE ALL;
# Recover database and skip all the tablespaces that you DON'T want recovered. This SKIP list
# should be same as the one for RESTORE above.
RECOVER DATABASE SKIP FOREVER TABLESPACE TBS1, TBS2, TBS3;
ALTER DATABASE OPEN RESESTLOGS;
}
注意:上面的FOREVER选项在RMAN OFFLINE不需要的文件后将会使用DROP子
句,对于需要以resetlogs打开数据库这是必须的。
13.如果遇到错误,可以在SQL*Plus下执行以下:
SQL> RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL;
CANCEL
SQL> ALTER DATABASE OPEN RESETLOGS;
14.然后可以删除并重建temp表空间:
SQL> CREATE TEMPORARY TABLESPACE TEMP2 TEMPFILE SIZE 500M;
SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP2;
SQL> DROP TABLESPACE TEMP;
此时,应该任何事情都可以可以正常运作了。
15.执行导入导出:
# Do the export of the tablespaces from the new database.
$ expdp directory=DATA_PUMP_DIR schemas=(USERS,TOOLS) dumpfile=export.dmp
# scp/ftp the dumpfile to the production server.
# Do the import into the production database.
$ impdp directory=DATA_PUMP_DIR schemas=(USERS,TOOLS) dumpfile=export.dmp \
table_exists_action=REPLACE transform=STORAGE:N