原 【DB宝15】生产环境中,如何利用DG的备库来异机还原一个新库?
在部署完ADG(Active Data Guard)后,不但可以将只读的查询交给备库执行,还可以把日常的数据库备份工作放在备库上执行,从而减轻主库的压力,充分的发挥服务器资源。
本文演示的是利用Oracle DG环境的备库执行备份,然后异机还原恢复成一个新的主库的过程。
DG环境介绍
项目 | primary db | physical standby db | 新库 |
---|---|---|---|
数据库类型(rac或单实例) | 单实例 | 单实例 | 单实例 |
数据库版本 | 11.2.0.3.0 | 11.2.0.3.0 | 11.2.0.3.0 |
platform_name | Linux x86 64-bit | Linux x86 64-bit | Linux x86 64-bit |
ORACLE_SID | oradg11g | oradgphy | LHRDB |
db_name/GLOBAL_DBNAME | oradg11g | oradg11g | oradg11g |
db_unique_name | oradg11g | oradgphy | LHRDB |
ORACLE_HOME | /u01/app/oracle/product/11.2.0/dbhome_1 | /u01/app/oracle/product/11.2.0/dbhome_1 | /u01/app/oracle/product/11.2.0/dbhome_1 |
一、备库执行备份
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | cat > /rman/rman_backup_oradgphy_full.sh <<"EOF0" #!/bin/ksh export ORACLE_SID=oradgphy export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 export PATH=$ORACLE_HOME/bin:$PATH export NLS_DATE_FORMAT="yyyy-mm-dd hh24:mi:ss" MYDATE=`date +'%Y%m%d%H%M%S'` rman target / log /rman/backup_oradgphy_full_$MYDATE.log append <<EOF run { sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"'; sql 'alter session set NLS_LANGUAGE="AMERICAN"'; allocate channel c1 type disk; allocate channel c2 type disk; allocate channel c3 type disk; allocate channel c4 type disk; allocate channel c5 type disk; allocate channel c6 type disk; allocate channel c7 type disk; allocate channel c8 type disk; allocate channel c9 type disk; allocate channel c10 type disk; allocate channel c11 type disk; allocate channel c12 type disk; backup as compressed backupset FILESPERSET 10 database format '/rman/FULL_%d_%U.full' section size 100G; backup as compressed backupset archivelog from time 'sysdate-1' format '/rman/ARC_%d_%U.arc' section size 100G; backup current controlfile format '/rman/standby_%U.ctl'; backup spfile format '/rman/spfile_%d_%U.ora'; release channel c1; release channel c2; release channel c3; release channel c4; release channel c5; release channel c6; release channel c7; release channel c8; release channel c9; release channel c10; release channel c11; release channel c12; } EOF EOF0 |
赋予可执行权限:
1 | chmod +x /rman/rman_backup_oradgphy_full.sh |
执行备份,或添加定时任务:
1 | nohup sh /rman/rman_backup_oradgphy_full.sh & |
备份结果:数据库790G(非分配大小),压缩备份后140G,用时30分钟。
接下来就是把/rman备份目录下的内容都拷贝到新主机上,方法很多,例如scp、磁盘卸载重新挂载等。
二、在新主机执行恢复操作
2.1、恢复spfile
1 2 3 4 5 6 7 | export ORACLE_SID=LHRDB rman target / startup nomount; restore spfile to pfile '?/dbs/initLHRDB.ora' from '/rman/spfile_ORADG11G_3lv6cd9m_1_1.ora'; -- 修改pfile,去除dg相关参数 vi $ORACLE_HOME/dbs/initLHRDB.ora |
需要根据情况对pfile做相关的修改,最终的参数文件内容:
12345678910111213141516171819*.audit_file_dest='/u01/app/oracle/admin/LHRDB/adump'*.audit_trail='db'*.compatible='11.2.0.0.0'*.control_files='/u01/app/oracle/oradata/LHRDB/crontal01.ctl','/u01/app/oracle/oradata/LHRDB/control02.ctl'*.db_block_size=8192*.db_domain=''*.db_name='oradg11g'*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'*.db_recovery_file_dest_size=4322230272*.db_unique_name='LHRDB'*.diagnostic_dest='/u01/app/oracle'*.dispatchers='(PROTOCOL=TCP) (SERVICE=oradg11gXDB)'*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST'*.memory_max_target=209715200*.memory_target=209715200*.open_cursors=300*.processes=3000*.remote_login_passwordfile='EXCLUSIVE'*.undo_tablespace='UNDOTBS1'根据pfile文件内容创建相关目录
12mkdir -p /u01/app/oracle/admin/LHRDB/adumpmkdir -p /u01/app/oracle/oradata/LHRDB/根据pfile创建spfile,并启动到nomout
12create spfile from pfile;startup force nomount
2.2、恢复控制文件
1 2 | -- 因为要恢复为主库,所以需要加上primary关键字 restore primary controlfile from '/rman/standby_3kv6cd9k_1_1.ctl'; |
超赞,找了很久!!!