数据库备份做恢复演练--验证备份数据的有效性和正确性

2020-08-15 00:00:00 数据库 文件 备份 生产 恢复

做数据库备份的恢复演练,就是从备份中恢复出一套完整的数据库,首先保证数据恢复正常,然后让业务人员确认数据的正确性。我们DBA负责的就是将数据库恢复出来,供业务去验证。

下面是模拟这个过程。

准备一个测试库,安装好软件

将生产库的 密码文件,备份文件(某一天的备份) 全部拷贝到备库 /home/oracle/backup2018

scp -r 2018_11_20/ oracle@dg2:/home/oracle/backup2018

拷贝密码文件(也可以自己创建)

scp orapworcl oracle@dg2:/home/oracle/backup2018

好创建一个生产库的pfile.这样可以在测试库创建对应目录,否则RMAN恢复spfile后,无法启动到nomount状态。

在测试库

修改环境变量

export ORACLE_SID=orcl;


恢复参数文件(之前必须创建好相关目录)

rman target /

startup 

RMAN> restore spfile from ‘/home/oracle/backup2018/2018_11_20/o1_mf_ncsnf_TAG20181120T203351_fz7ztmf8_.bkp’;

恢复控制文件

RMAN> restore controlfile from ‘/home/oracle/backup2018/2018_11_20/o1_mf_ncsnf_TAG20181120T203351_fz7ztmf8_.bkp’;


启动数据库到mount状态

alter database mount 

恢复数据库,这里需要先注册备份文件,将整个备份目录下的文件注册的RMAN

RMAN> catalog start with '/home/oracle/backup2018/2018_11_20/';


Starting implicit crosscheck backup at 20-NOV-18

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=20 device type=DISK

Crosschecked 2 objects

Finished implicit crosscheck backup at 20-NOV-18


Starting implicit crosscheck copy at 20-NOV-18

using channel ORA_DISK_1

Finished implicit crosscheck copy at 20-NOV-18


searching for all files in the recovery area

cataloging files...

no files cataloged


searching for all files that match the pattern /home/oracle/backup2018/2018_11_20/


List of Files Unknown to the Database

=====================================

File Name: /home/oracle/backup2018/2018_11_20/o1_mf_ncsnf_TAG20181120T203351_fz7ztmf8_.bkp

File Name: /home/oracle/backup2018/2018_11_20/o1_mf_annnn_TAG20181120T203428_fz7ztnkl_.bkp

File Name: /home/oracle/backup2018/2018_11_20/o1_mf_nnndf_TAG20181120T203351_fz7zshcr_.bkp

File Name: /home/oracle/backup2018/2018_11_20/o1_mf_annnn_TAG20181120T203350_fz7zsg3h_.bkp


Do you really want to catalog the above files (enter YES or NO)? yes

cataloging files...

cataloging done


List of Cataloged Files

=======================

File Name: /home/oracle/backup2018/2018_11_20/o1_mf_ncsnf_TAG20181120T203351_fz7ztmf8_.bkp

File Name: /home/oracle/backup2018/2018_11_20/o1_mf_annnn_TAG20181120T203428_fz7ztnkl_.bkp

File Name: /home/oracle/backup2018/2018_11_20/o1_mf_nnndf_TAG20181120T203351_fz7zshcr_.bkp

File Name: /home/oracle/backup2018/2018_11_20/o1_mf_annnn_TAG20181120T203350_fz7zsg3h_.bkp

实施恢复

RMAN> restore database;

Starting restore at 20-NOV-18

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf

channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl/sysaux01.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl/undotbs01.dbf

channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf

channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/test.dbf

channel ORA_DISK_1: reading from backup piece /home/oracle/backup2018/2018_11_20/o1_mf_nnndf_TAG20181120T203351_fz7zshcr_.bkp

channel ORA_DISK_1: piece handle=/home/oracle/backup2018/2018_11_20/o1_mf_nnndf_TAG20181120T203351_fz7zshcr_.bkp tag=TAG20181120T203351

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:45

Finished restore at 20-NOV-18


recover部分

RMAN> recover database;


Starting recover at 20-NOV-18

using channel ORA_DISK_1


starting media recovery


channel ORA_DISK_1: starting archived log restore to default destination

channel ORA_DISK_1: restoring archived log

archived log thread=1 sequence=6

channel ORA_DISK_1: reading from backup piece /home/oracle/backup2018/2018_11_20/o1_mf_annnn_TAG20181120T203428_fz7ztnkl_.bkp

channel ORA_DISK_1: piece handle=/home/oracle/backup2018/2018_11_20/o1_mf_annnn_TAG20181120T203428_fz7ztnkl_.bkp tag=TAG20181120T203428

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

archived log file name=/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2018_11_20/o1_mf_1_6_fz82korn_.arc thread=1 sequence=6

channel default: deleting archived log(s)

archived log file name=/u01/app/oracle/fast_recovery_area/ORCL/archivelog/2018_11_20/o1_mf_1_6_fz82korn_.arc RECID=2 STAMP=992726453

unable to find archived log

archived log thread=1 sequence=7

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 11/20/2018 21:20:54

RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 7 and starting SCN of 994377

这里提示缺少sequence7的日志,因为这个是当前日志,直接指定不完全恢复(这里是为了验证备份文件是否可以有效恢复,不必在意是否完全恢复)


RMAN> recover database until sequence 7;


Starting recover at 20-NOV-18

using channel ORA_DISK_1


starting media recovery

media recovery complete, elapsed time: 00:00:00


Finished recover at 20-NOV-18


打开数据库


RMAN> alter database open resetlogs;


database opened


下面可以验证恢复后的数据库,数据是否完整等

备注:我们必须理解数据库是指三个文件:控制文件、重做日志文件和数据文件。至于密码文件、参数文件完全可以自己创建,一般参数文件可以从备份恢复,但是恢复环境的相关目录需要具备

这个就看具体情况灵活设置了。


相关文章