|
set newname for指导restore和 duplicate,set newname之后如果跟着switch,就是为了把restore出来的镜像拷贝变为数据文件,switch实际上就是alter database rename file '' to '':
- run{
- set newname for datafile 5 to '/home/oracle/examplettio.dbf';
- restore datafile 5;
- delete datafilecopy '/home/oracle/examplettio.dbf';
- }
复制代码
set newname语法可以在克隆时与 set db_file_name_convert/set log_file_name_convert互相替换。
关于克隆的backup location的语法:
1. 在源头数据库上做:
- --源头把备份优化关掉,或用force语法
- run {
- allocate channel c1 device type disk format '/home/oracle/backup/%U';
- allocate channel c2 device type disk format '/home/oracle/backup/%U';
- allocate channel c3 device type disk format '/home/oracle/backup/%U';
- allocate channel c4 device type disk format '/home/oracle/backup/%U';
- allocate channel c5 device type disk format '/home/oracle/backup/%U';
- allocate channel c6 device type disk format '/home/oracle/backup/%U';
- allocate channel c7 device type disk format '/home/oracle/backup/%U';
- allocate channel c8 device type disk format '/home/oracle/backup/%U';
- backup database plus archivelog force;
- backup spfile;
- backup current controlfile;
- }
复制代码 把源头库上的/home/oracle/backup/完整scp -rp 到目的地机器相同的位置:
在目的机器上写一个只有一行或两行的init.ora:db_name=... db_domain=...
db_name和db_doamin必须在目的地机器上做静态注册。
开启克隆命令:
- run{
- duplicate target database to mydb
- backup location '/home/oracle/backup'
- nofilenamecheck
- skip tablespace 'TBS1','TBS2'
- spfile
- set
- control_files='/u01/app/oracle/oradata/mydb/control01.ctl','/u01/app/oracle/oradata/mydb/control02.ctl','/u01/app/oracle/oradata/mydb/control03.ctl'
- set
- db_file_name_convert='+DATA/orcl/datafile/example.258.880451611','/u01/app/oracle/oradata/mydb/example01.dbf','+DATA/orcl/datafile/users.259.880451615','/u01/app/oracle/oradata/mydb/users01.dbf','+DATA/orcl/datafile/undotbs1.256.880451607','/u01/app/oracle/oradata/mydb/undotbs01.dbf','+DATA/orcl/datafile/sysaux.257.880451605','/u01/app/oracle/oradata/mydb/sysaux01.dbf','+DATA/orcl/datafile/system.265.880451605','/u01/app/oracle/oradata/mydb/system01.dbf'
- set
- log_file_name_convert='+DATA/orcl/onlinelog/group_1.270.880453135','/u01/app/oracle/oradata/mydb/redo01a.log','+FRA/orcl/onlinelog/group_1.276.880453137','/u01/app/oracle/oradata/mydb/redo01b.log','+DATA/orcl/onlinelog/group_3.272.880453141','/u01/app/oracle/oradata/mydb/redo03a.log','+FRA/orcl/onlinelog/group_3.274.880453141','/u01/app/oracle/oradata/mydb/redo03b.log','+DATA/orcl/onlinelog/group_2.271.880453137','/u01/app/oracle/oradata/mydb/redo02a.log','+FRA/orcl/onlinelog/group_2.275.880453139','/u01/app/oracle/oradata/mydb/redo02b.log'
- set
- audit_file_dest='/u01/app/oracle/admin/mydb/adump'
- set
- db_create_file_dest=''
- set
- db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
- }
复制代码 如果做dataguard的主备库的口令文件一定要写ignorecase=y
主库改了4个对应的参数:
- SQL> alter system set log_archive_config='dg_config=(PROD1,STDBY)';
- System altered.
- SQL> alter system set log_archive_dest_1='location=use_db_recovery_file_dest';
- System altered.
- SQL> alter system set log_archive_dest_2='service=STDBY valid_for=(online_logfiles, primary_role) db_unique_name=STDBY';
- System altered.
- SQL> show parameter standby
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- standby_archive_dest string ?/dbs/arch
- standby_file_management string MANUAL
- SQL> alter system set standby_file_management=auto;
- System altered.
复制代码- SQL> conn / as sysdba
- Connected.
- SQL> alter database enable force logging;
复制代码
备库的克隆脚本:
- run{
- duplicate target database
- for standby
- from active database
- nofilenamecheck
- spfile
- set
- control_files='/u01/app/oracle/oradata/STDBY/control01.ctl','/u01/app/oracle/fast_recovery_area/STDBY/control02.ctl'
- set
- db_file_name_convert='/u01/app/oracle/oradata/PROD1','/u01/app/oracle/oradata/STDBY'
- set
- log_file_name_convert='/u01/app/oracle/oradata/PROD1','/u01/app/oracle/oradata/STDBY'
- set
- audit_file_dest='/u01/app/oracle/admin/STDBY/adump'
- set
- log_archive_dest_2='service=PROD1 valid_for=(online_logfiles, primary_role) db_unique_name=PROD1'
- set
- db_unique_name='STDBY';
- }
复制代码 备库RMAN命令:
- rman target sys/oracle_4U@PROD1 auxiliary sys/oracle_4U@STDBY cmdfile=STDBY.rcv
复制代码
在备库上执行以下命令:
- SQL> alter database recover managed standby database disconnect from session;
复制代码
关掉日志应用的命令:
- SQL> alter database recover managed standby database cancel ;
- Database altered.
- SQL> !ps aux | grep mrp
- oracle 18755 0.0 0.0 4732 996 pts/2 S+ 02:41 0:00 /bin/bash -c ps aux | grep mrp
- oracle 18757 0.0 0.0 4124 628 pts/2 S+ 02:41 0:00 grep mrp
- SQL>
复制代码 ADG化:
- SQL> alter database open read only;
- Database altered.
- SQL> alter database recover managed standby database disconnect from session;
- Database altered.
- SQL>
复制代码 Dmon进程两边打开:
- [oracle@station37 ~]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.3.0 Production on Sun Jul 22 05:58:43 2018
- Copyright (c) 1982, 2011, Oracle. All rights reserved.
- SQL> conn / as sysdba
- Connected.
- SQL> show parameter dg
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- dg_broker_config_file1 string /u01/app/oracle/product/11.2.0
- /dbhome_1/dbs/dr1PROD1.dat
- dg_broker_config_file2 string /u01/app/oracle/product/11.2.0
- /dbhome_1/dbs/dr2PROD1.dat
- dg_broker_start boolean FALSE
- SQL> !ps aux | grep dmon
- oracle 27892 0.0 0.0 4732 1000 pts/1 S+ 05:59 0:00 /bin/bash -c ps aux | grep dmon
- oracle 27894 0.0 0.0 4124 620 pts/1 S+ 05:59 0:00 grep dmon
- SQL> alter system set dg_broker_start=true;
- System altered.
- SQL> !ps aux | grep dmon
- oracle 27897 0.1 0.1 696232 14600 ? Ss 05:59 0:00 ora_dmon_PROD1
- oracle 27898 0.0 0.0 4732 1000 pts/1 S+ 05:59 0:00 /bin/bash -c ps aux | grep dmon
- oracle 27900 0.0 0.0 4124 640 pts/1 S+ 05:59 0:00 grep dmon
复制代码- SQL> show parameter dg
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- dg_broker_config_file1 string /u01/app/oracle/product/11.2.0
- /dbhome_1/dbs/dr1STDBY.dat
- dg_broker_config_file2 string /u01/app/oracle/product/11.2.0
- /dbhome_1/dbs/dr2STDBY.dat
- dg_broker_start boolean FALSE
- SQL> !ps aux | grep dmon
- oracle 22939 0.0 0.0 4732 1000 pts/2 S+ 05:59 0:00 /bin/bash -c ps aux | grep dmon
- oracle 22941 0.0 0.0 4124 632 pts/2 S+ 05:59 0:00 grep dmon
- SQL> alter system set dg_broker_start=true;
- System altered.
- SQL> !ps aux | grep dmon
- oracle 22955 0.3 0.1 696232 14512 ? Ss 05:59 0:00 ora_dmon_STDBY
- oracle 22956 0.0 0.0 4732 1000 pts/2 S+ 05:59 0:00 /bin/bash -c ps aux | grep dmon
- oracle 22958 0.0 0.0 4124 636 pts/2 S+ 05:59 0:00 grep dmon
- SQL>
复制代码
Dataguard构造:
- [oracle@station37 ~]$ dgmgrl
- DGMGRL for Linux: Version 11.2.0.3.0 - Production
- Copyright (c) 2000, 2009, Oracle. All rights reserved.
- Welcome to DGMGRL, type "help" for information.
- DGMGRL> connect sys/oracle_4U@PROD1
- Connected.
- DGMGRL> help
- The following commands are available:
- add Adds a standby database to the broker configuration
- connect Connects to an Oracle database instance
- convert Converts a database from one type to another
- create Creates a broker configuration
- disable Disables a configuration, a database, or fast-start failover
- edit Edits a configuration, database, or instance
- enable Enables a configuration, a database, or fast-start failover
- exit Exits the program
- failover Changes a standby database to be the primary database
- help Displays description and syntax for a command
- quit Exits the program
- reinstate Changes a database marked for reinstatement into a viable standby
- rem Comment to be ignored by DGMGRL
- remove Removes a configuration, database, or instance
- show Displays information about a configuration, database, or instance
- shutdown Shuts down a currently running Oracle database instance
- sql Executes a SQL statement
- start Starts the fast-start failover observer
- startup Starts an Oracle database instance
- stop Stops the fast-start failover observer
- switchover Switches roles between a primary and standby database
- Use "help <command>" to see syntax for individual commands
复制代码 ----------------------------------------
- [oracle@station37 ~]$ dgmgrl
- DGMGRL for Linux: Version 11.2.0.3.0 - Production
- Copyright (c) 2000, 2009, Oracle. All rights reserved.
- Welcome to DGMGRL, type "help" for information.
- DGMGRL> connect sys/oracle_4U@PROD1
- Connected.
- DGMGRL> help create
- Creates a broker configuration
- Syntax:
- CREATE CONFIGURATION <configuration name> AS
- PRIMARY DATABASE IS <database name>
- CONNECT IDENTIFIER IS <connect identifier>;
- DGMGRL> CREATE CONFIGURATION PROD1 as
- > PRIMARY DATABASE IS 'PROD1'
- > CONNECT IDENTIFIER IS PROD1;
- Configuration "prod1" created with primary database "PROD1"
- DGMGRL> help add
- Adds a standby database to the broker configuration
- Syntax:
- ADD DATABASE <database name>
- [AS CONNECT IDENTIFIER IS <connect identifier>]
- [MAINTAINED AS {PHYSICAL|LOGICAL}];
- DGMGRL> ADD DATABASE 'STDBY'
- > AS CONNECT IDENTIFIER IS STDBY
- > MAINTAINED AS PHYSICAL;
- Database "STDBY" added
- DGMGRL> enable configuration;
- Enabled.
- DGMGRL> show configuration verbose;
- Configuration - prod1
- Protection Mode: MaxPerformance
- Databases:
- PROD1 - Primary database
- STDBY - Physical standby database
- Properties:
- FastStartFailoverThreshold = '30'
- OperationTimeout = '30'
- FastStartFailoverLagLimit = '30'
- CommunicationTimeout = '180'
- FastStartFailoverAutoReinstate = 'TRUE'
- FastStartFailoverPmyShutdown = 'TRUE'
- BystandersFollowRoleChange = 'ALL'
- Fast-Start Failover: DISABLED
- Configuration Status:
- SUCCESS
- DGMGRL> DGMGRL> [oracle@station37 ~]$
复制代码- DGMGRL> show database verbose'PROD1';
- Database - PROD1
- Role: PRIMARY
- Intended State: TRANSPORT-ON
- Instance(s):
- PROD1
- Properties:
- DGConnectIdentifier = 'prod1'
- ObserverConnectIdentifier = ''
- LogXptMode = 'ASYNC'
- DelayMins = '0'
- Binding = 'optional'
- MaxFailure = '0'
- MaxConnections = '1'
- ReopenSecs = '300'
- NetTimeout = '30'
- RedoCompression = 'DISABLE'
- LogShipping = 'ON'
- PreferredApplyInstance = ''
- ApplyInstanceTimeout = '0'
- ApplyParallel = 'AUTO'
- StandbyFileManagement = 'AUTO'
- ArchiveLagTarget = '0'
- LogArchiveMaxProcesses = '4'
- LogArchiveMinSucceedDest = '1'
- DbFileNameConvert = ''
- LogFileNameConvert = ''
- FastStartFailoverTarget = ''
- InconsistentProperties = '(monitor)'
- InconsistentLogXptProps = '(monitor)'
- SendQEntries = '(monitor)'
- LogXptStatus = '(monitor)'
- RecvQEntries = '(monitor)'
- SidName = 'PROD1'
- StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=station37.example.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=PROD1_DGMGRL)(INSTANCE_NAME=PROD1)(SERVER=DEDICATED)))'
- StandbyArchiveLocation = 'USE_DB_RECOVERY_FILE_DEST'
- AlternateLocation = ''
- LogArchiveTrace = '0'
- LogArchiveFormat = '%t_%s_%r.dbf'
- TopWaitEvents = '(monitor)'
- Database Status:
- SUCCESS
- DGMGRL> show database verbose 'STDBY';
- Database - STDBY
- Role: PHYSICAL STANDBY
- Intended State: APPLY-ON
- Transport Lag: 0 seconds
- Apply Lag: 0 seconds
- Real Time Query: ON
- Instance(s):
- STDBY
- Properties:
- DGConnectIdentifier = 'stdby'
- ObserverConnectIdentifier = ''
- LogXptMode = 'ASYNC'
- DelayMins = '0'
- Binding = 'OPTIONAL'
- MaxFailure = '0'
- MaxConnections = '1'
- ReopenSecs = '300'
- NetTimeout = '30'
- RedoCompression = 'DISABLE'
- LogShipping = 'ON'
- PreferredApplyInstance = ''
- ApplyInstanceTimeout = '0'
- ApplyParallel = 'AUTO'
- StandbyFileManagement = 'AUTO'
- ArchiveLagTarget = '0'
- LogArchiveMaxProcesses = '4'
- LogArchiveMinSucceedDest = '1'
- DbFileNameConvert = '/u01/app/oracle/oradata/PROD1, /u01/app/oracle/oradata/STDBY'
- LogFileNameConvert = '/u01/app/oracle/oradata/PROD1, /u01/app/oracle/oradata/STDBY'
- FastStartFailoverTarget = ''
- InconsistentProperties = '(monitor)'
- InconsistentLogXptProps = '(monitor)'
- SendQEntries = '(monitor)'
- LogXptStatus = '(monitor)'
- RecvQEntries = '(monitor)'
- SidName = 'STDBY'
- StaticConnectIdentifier = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=station38.example.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=STDBY_DGMGRL)(INSTANCE_NAME=STDBY)(SERVER=DEDICATED)))'
- StandbyArchiveLocation = 'USE_DB_RECOVERY_FILE_DEST'
- AlternateLocation = ''
- LogArchiveTrace = '0'
- LogArchiveFormat = '%t_%s_%r.dbf'
- TopWaitEvents = '(monitor)'
- Database Status:
- SUCCESS
- DGMGRL>
复制代码
如果改保护模式时,报告:
- DGMGRL> EDIT CONFIGURATION SET PROTECTION MODE AS MaxAvailability;
- Error: ORA-16627: operation disallowed since no standby databases would remain to support protection mode
- Failed.
- DGMGRL>
复制代码 说明没有改LOGXPTMODE:
备库的broker属性是主库的参数文件参数;主库的broker属性是备库的参数文件参数:
两头改闪回,并且打开Real Time Apply:
- SQL> select flashback_on from v$database;
- FLASHBACK_ON
- ------------------
- NO
- SQL> alter database flashback on ;
- alter database flashback on
- *
- ERROR at line 1:
- ORA-01153: an incompatible media recovery is active
- SQL> alter database recover managed standby database cancel ;
- Database altered.
- SQL> alter database flashback on ;
- Database altered.
- SQL> alter database recover managed standby database using current logfile disconnect;
- Database altered.
- SQL>
复制代码 快照物理备库,实际上就是过去1. 手工创建保障闪回还原点;2.激活物理备库。
- DGMGRL> CONVERT DATABASE 'STDBY' to SNAPSHOT STANDBY;
- Converting database "STDBY" to a Snapshot Standby database, please wait...
- Database "STDBY" converted successfully
复制代码- SQL> select * from v$restore_point;
- SCN DATABASE_INCARNATION# GUA STORAGE_SIZE TIME RESTORE_POINT_TIME PRE NAME
- ---------- --------------------- --- ------------ --------------------------------------------------------------------------- --------------------------------------------------------------------------- --- --------------------------------------------------------------------------------------------------------------------------------
- 1002609 2 YES 52428800 22-JUL-15 06.38.53.000000000 AM YES SNAPSHOT_STANDBY_REQUIRED_07/22/2015 06:38:53
复制代码 在物理备库上打开块跟踪:
- SQL> alter database enable block change tracking using file '/u01/app/oracle/fast_recovery_area/STDBY/ctwr.f';
- Database altered.
- SQL> !ps aux | grep ora_ctwr
- oracle 24736 0.1 0.1 695884 14452 ? Ss 07:04 0:00 ora_ctwr_STDBY
- oracle 24739 0.0 0.0 4732 996 pts/2 S+ 07:05 0:00 /bin/bash -c ps aux | grep ora_ctwr
- oracle 24741 0.0 0.0 4124 632 pts/2 S+ 07:05 0:00 grep ora_ctwr
- SQL>
复制代码 下面最后一道题:快速启动故障转移。
----------------------------------------------------------------------------
归档性备份:9i的时候是事后做,而11g同时做:
9i:
- RMAN> change backupset 2 keep until time 'sysdate+60';
- allocated channel: ORA_DISK_1
- channel ORA_DISK_1: SID=11 device type=DISK
- RMAN-00571: ===========================================================
- RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
- RMAN-00571: ===========================================================
- RMAN-03009: failure of KEEP command on ORA_DISK_1 channel at 07/22/2018 17:03:49
- ORA-19811: cannot have files in DB_RECOVERY_FILE_DEST with keep attributes
- RMAN> run {
- 2> allocate channel c1 device type disk format '/home/oracle/%U';
- 3> backup backupset 2 force delete input;
- 4> change backupset 2 keep until time 'sysdate+60';
- 5> }
- released channel: ORA_DISK_1
- allocated channel: c1
- channel c1: SID=11 device type=DISK
- Starting backup at 22-JUL-18
- channel c1: input backup set: count=2, stamp=981994123, piece=1
- channel c1: starting piece 1 at 22-JUL-18
- channel c1: backup piece +FRA/orcl/backupset/2018_07_20/nnndf0_tag20180720t160842_0.262.981994123
- piece handle=/home/oracle/02t8g2kb_1_2 comment=NONE
- channel c1: finished piece 1 at 22-JUL-18
- channel c1: backup piece complete, elapsed time: 00:00:36
- deleted backup piece
- backup piece handle=+FRA/orcl/backupset/2018_07_20/nnndf0_tag20180720t160842_0.262.981994123 RECID=2 STAMP=981994123
- Finished backup at 22-JUL-18
- keep attributes for the backup are changed
- backup will be obsolete on date 20-SEP-18
- backup set key=2 RECID=2 STAMP=981994142
- released channel: c1
复制代码- RMAN> run {
- 2> allocate channel c1 device type disk format '/home/oracle/example_%U.bkp';
- 3> backup tag 'TAG3' tablespace example keep forever;
- 4> }
- allocated channel: c1
- channel c1: SID=11 device type=DISK
- Starting backup at 22-JUL-18
- current log archived
- released channel: c1
- RMAN-00571: ===========================================================
- RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
- RMAN-00571: ===========================================================
- RMAN-03002: failure of backup command at 07/22/2018 17:10:07
- RMAN-06522: KEEP FOREVER option is not supported without the recovery catalog
复制代码- [oracle@station36 admin]$ rman target / catalog u36/oracle_4U@rcat
- Recovery Manager: Release 11.2.0.1.0 - Production on Sun Jul 22 17:14:13 2018
- Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
- connected to target database: ORCL (DBID=1507385682)
- connected to recovery catalog database
- RMAN> run {
- 2> allocate channel c1 device type disk format '/home/oracle/example_%U.bkp';
- 3> backup tag 'TAG3' tablespace example keep forever restore point tag3;
- 4> }
- allocated channel: c1
- channel c1: SID=75 device type=DISK
- Starting backup at 22-JUL-18
- current log archived
- backup will never be obsolete
- archived logs required to recover from this backup will be backed up
- channel c1: starting full datafile backup set
- channel c1: specifying datafile(s) in backup set
- input datafile file number=00005 name=+DATA/orcl/datafile/example.265.979605007
- channel c1: starting piece 1 at 22-JUL-18
- channel c1: finished piece 1 at 22-JUL-18
- piece handle=/home/oracle/example_0et8lf86_1_1.bkp tag=TAG3 comment=NONE
- channel c1: backup set complete, elapsed time: 00:00:01
- backup will never be obsolete
- archived logs required to recover from this backup will be backed up
- channel c1: starting full datafile backup set
- channel c1: specifying datafile(s) in backup set
- including current SPFILE in backup set
- channel c1: starting piece 1 at 22-JUL-18
- channel c1: finished piece 1 at 22-JUL-18
- piece handle=/home/oracle/example_0ft8lf87_1_1.bkp tag=TAG3 comment=NONE
- channel c1: backup set complete, elapsed time: 00:00:01
- current log archived
- backup will never be obsolete
- archived logs required to recover from this backup will be backed up
- channel c1: starting archived log backup set
- channel c1: specifying archived log(s) in backup set
- input archived log thread=1 sequence=8 RECID=19 STAMP=982170890
- channel c1: starting piece 1 at 22-JUL-18
- channel c1: finished piece 1 at 22-JUL-18
- piece handle=/home/oracle/example_0gt8lf8b_1_1.bkp tag=TAG3 comment=NONE
- channel c1: backup set complete, elapsed time: 00:00:01
- backup will never be obsolete
- archived logs required to recover from this backup will be backed up
- channel c1: starting full datafile backup set
- channel c1: specifying datafile(s) in backup set
- including current control file in backup set
- channel c1: starting piece 1 at 22-JUL-18
- channel c1: finished piece 1 at 22-JUL-18
- piece handle=/home/oracle/example_0ht8lf8c_1_1.bkp tag=TAG3 comment=NONE
- channel c1: backup set complete, elapsed time: 00:00:01
- Finished backup at 22-JUL-18
- released channel: c1
- RMAN>
复制代码- [oracle@station36 admin]$ sqlplus /nolog
- SQL*Plus: Release 11.2.0.1.0 Production on Sun Jul 22 17:15:22 2018
- Copyright (c) 1982, 2009, Oracle. All rights reserved.
- SQL> conn / as sysdba
- Connected.
- SQL> set linesize 1000
- SQL> select * from v$restore_point;
- SCN DATABASE_INCARNATION# GUA STORAGE_SIZE TIME RESTORE_POINT_TIME PRE NAME
- ---------- --------------------- --- ------------ --------------------------------------------------------------------------- --------------------------------------------------------------------------- --- --------------------------------------------------------------------------------------------------------------------------------
- 958398 4 NO 0 22-JUL-18 05.14.48.000000000 PM NO TAG3
- SQL>
复制代码
如果agent死活上传失败,考虑在EMREP上执行:
- execute mgmt_admin.cleanup_agent('station37.example.com:3872');
复制代码 再装-b -y
|
|