原 【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 & |
超赞,找了很久!!!