Primary Database:
192.168.8.251 centos10g.oracle.com centos10g
Standby Database:
192.168.8.252 centos10g2.oracle.com centos10g2
1、在 primary database 上啟用 force logging
[oracle@centos10g ~]$ sqlplus / as sysdba
SQL> alter database force logging;
Database altered.
2、在 primary database 上啟用 archivelog 模式
[oracle@centos10g ~]$ mkdir /u01/arch
SQL> alter system set log_archive_dest_1='location=/u01/arch' scope=spfile;
System altered.
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/arch
Oldest online log sequence 10
Next log sequence to archive 12
Current log sequence 12
3、建立 NFS 共用目錄,用來存放 primary 的備份組
[root@centos10g ~]# chown -R oracle:oinstall /backup
[root@centos10g ~]# chmod -R 777 /backup
[root@centos10g ~]# vi /etc/exports
/backup centos10g.oracle.com(rw,sync) centos10g2.oracle.com(rw,sync)
[root@centos10g ~]# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
--------------------------------------------------------------------
-- 在 standby 主機上掛載 primary 主機上的nfs共用
[root@centos10g2 ~]# chown -R oracle:oinstall /backup
[root@centos10g2 ~]# chmod -R 777 /backup
[root@centos10g2 ~]# mount centos10g.oracle.com:/backup /backup
[root@centos10g2 ~]# df -h /backup
Filesystem Size Used Avail Use% Mounted on
centos10g.oracle.com:/backup
2.0G 36M 1.9G 2% /backup
4、備份 primary 資料庫(full backup)到 nfs 共用
RMAN> run{
2> startup mount;
3> allocate channel c1 type disk;
4> allocate channel c2 type disk;
5> backup format='/backup/%d_%s_%t.bak' database plus archivelog;
6> }
5、在 primary 庫上備份 standby 的控制檔案
RMAN> copy current controlfile for standby to '/backup/control01.ctl';
6、配置 primary 和 standby 的監聽和 TNS
[oracle@centos10g2 ~]$ more $ORACLE_HOME/network/admin/tnsnames.ora
BEIJING =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = centos10g)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prod)
)
)
TIANJIN =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = centos10g2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = standby)
)
)
[oracle@centos10g ~]$ more $ORACLE_HOME/network/admin/tnsnames.ora
BEIJING =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = centos10g)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prod)
)
)
TIANJIN =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = centos10g2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = standby)
)
)
7、準備standby庫的pfile
在primary庫建立pfile,然後拷貝至備庫的$ORACLE_HOME/dbs 路徑下,並添加如下參數
*.db_unique_name=tianjin
*.log_archive_config='dg_config=(beijing,tianjin)'
*.log_archive_dest_1='location=/u01/arch valid_for=(online_logfiles,primary_role) db_unique_name=tianjin'
*.log_archive_dest_2='service=beijing valid_for=(online_logfiles,primary_role) db_unique_name=beijing'
*.fal_server=beijing
*.fal_client=tianjin
*.db_file_name_convert='/u01/app/oracle/oradata/prod'.'/u01/app/oracle/oradata/prod'
*.log_file_name_convert='/u01/app/oracle/oradata/prod'.'/u01/app/oracle/oradata/prod'
*.standby_file_management=auto
8、在standby庫主機上建立初始化參數中涉及的目錄
[oracle@centos10g2 dbs]$ mkdir -p /u01/app/oracle/admin/prod/adump
[oracle@centos10g2 dbs]$ mkdir -p /u01/app/oracle/admin/prod/bdump
[oracle@centos10g2 dbs]$ mkdir -p /u01/app/oracle/admin/prod/cdump
[oracle@centos10g2 dbs]$ mkdir -p /u01/app/oracle/admin/prod/udump
[oracle@centos10g2 dbs]$ mksdir -p /u01/app/oracle/oradata/prod/
[oracle@centos10g2 dbs]$ mkdir -p /u01/app/oracle/flash_recovery_area
9、利用 primary 庫的備份組恢複 standby 庫
9.1 在 standby 庫中恢複 primary 庫的 controlfile
[oracle@centos10g2 backup]$ cp control01.ctl /u01/app/oracle/oradata/prod/control01.ctl
[oracle@centos10g2 backup]$ cp control01.ctl /u01/app/oracle/oradata/prod/control02.ctl
[oracle@centos10g2 backup]$ cp control01.ctl /u01/app/oracle/oradata/prod/control03.ctl
[oracle@centos10g2 ~]$ rman target /
RMAN> startup mount
connected to target database (not started)
Oracle instance started
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 100664912 bytes
Database Buffers 180355072 bytes
Redo Buffers 2973696 bytes
9.2 restore database
RMAN> restore database;
Starting restore at 23-SEP-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to .'/u01/app/oracle/oradata/prod'/undotbs01.dbf
restoring datafile 00003 to .'/u01/app/oracle/oradata/prod'/sysaux01.dbf
restoring datafile 00005 to .'/u01/app/oracle/oradata/prod'/example01.dbf
channel ORA_DISK_1: reading from backup piece /backup/PROD_20_794779912.bak
ORA-19870: error reading backup piece /backup/PROD_20_794779912.bak
ORA-19505: failed to identify file "/backup/PROD_20_794779912.bak"
ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
Additional information: 3
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to .'/u01/app/oracle/oradata/prod'/system01.dbf
restoring datafile 00004 to .'/u01/app/oracle/oradata/prod'/users01.dbf
channel ORA_DISK_1: reading from backup piece /backup/PROD_19_794779912.bak
ORA-19870: error reading backup piece /backup/PROD_19_794779912.bak
ORA-19505: failed to identify file "/backup/PROD_19_794779912.bak"
ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
Additional information: 3
造成問題的原因可能是oracle去考慮nfs的問題. 總之需要執行命令。
Alter system set events '10298 trace name context forever,level 32'
或執行如下操作
[root@centos10g2 ~]# mount -t nfs -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600,actimeo=0 centos10g.oracle.com:/backup /backup
轉載請註明作者、出處及原文連結,否則拒絕轉載:
本文來源:http://blog.csdn.net/xiangsir/article/details/8606594