概述
一、设置数据库处于归档模式
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 4
Current log sequence 6
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open ;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 4
Next log sequence to archive 6
Current log sequence 6
二、rman备份数据库
[oracle@even202 ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Jan 27 19:06:22 2023
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=539013444)
RMAN> backup database include current controlfile plus archivelog delete input;
Starting backup at 27-JAN-23
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=31 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=1 STAMP=1127243425
channel ORA_DISK_1: starting piece 1 at 27-JAN-23
channel ORA_DISK_1: finished piece 1 at 27-JAN-23
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/011j0nl1_1_1 tag=TAG20230127T191025 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_6_1127175109.dbf RECID=1 STAMP=1127243425
Finished backup at 27-JAN-23
Starting backup at 27-JAN-23
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/users01.dbf
channel ORA_DISK_1: starting piece 1 at 27-JAN-23
channel ORA_DISK_1: finished piece 1 at 27-JAN-23
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/021j0nl2_1_1 tag=TAG20230127T191026 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:26
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 27-JAN-23
channel ORA_DISK_1: finished piece 1 at 27-JAN-23
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/031j0nls_1_1 tag=TAG20230127T191026 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 27-JAN-23
Starting backup at 27-JAN-23
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=7 RECID=2 STAMP=1127243454
channel ORA_DISK_1: starting piece 1 at 27-JAN-23
channel ORA_DISK_1: finished piece 1 at 27-JAN-23
piece handle=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/041j0nlu_1_1 tag=TAG20230127T191054 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_1127175109.dbf RECID=2 STAMP=1127243454
Finished backup at 27-JAN-23
三、查看数据文件备份位置,加粗的地方为备份的文件位置,如果改变位置,可以在备份时指定format参数,确定文件备份位置
RMAN> list backup of database;
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2 Full 1021.24M DISK 00:00:23 27-JAN-23
BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20230127T191026
Piece Name: /u01/app/oracle/product/11.2.0/dbhome_1/dbs/021j0nl2_1_1
List of Datafiles in backup set 2
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1040470 27-JAN-23 /u01/app/oracle/oradata/PROD/system01.dbf
2 Full 1040470 27-JAN-23 /u01/app/oracle/oradata/PROD/sysaux01.dbf
3 Full 1040470 27-JAN-23 /u01/app/oracle/oradata/PROD/undotbs01.dbf
4 Full 1040470 27-JAN-23 /u01/app/oracle/oradata/PROD/users01.dbf
5 Full 1040470 27-JAN-23 /u01/app/oracle/oradata/PROD/example01.dbf
RMAN> list backup of controlfile;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 9.36M DISK 00:00:01 27-JAN-23
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20230127T191026
Piece Name: /u01/app/oracle/product/11.2.0/dbhome_1/dbs/031j0nls_1_1
Control File Included: Ckp SCN: 1040522 Ckp time: 27-JAN-23
RMAN> list backup of archivelog all;
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
1 1.49M DISK 00:00:00 27-JAN-23
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20230127T191025
Piece Name: /u01/app/oracle/product/11.2.0/dbhome_1/dbs/011j0nl1_1_1
List of Archived Logs in backup set 1
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 6 1038404 27-JAN-23 1040455 27-JAN-23
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
4 34.50K DISK 00:00:00 27-JAN-23
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: TAG20230127T191054
Piece Name: /u01/app/oracle/product/11.2.0/dbhome_1/dbs/041j0nlu_1_1
List of Archived Logs in backup set 4
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 7 1040455 27-JAN-23 1040531 27-JAN-23
[oracle@even202 dbs]$ ll
总计 1069088
-rw-r----- 1 oracle oinstall 1559040 01-27 19:10 011j0nl1_1_1
-rw-r----- 1 oracle oinstall 1070858240 01-27 19:10 021j0nl2_1_1
-rw-r----- 1 oracle oinstall 9830400 01-27 19:10 031j0nls_1_1
-rw-r----- 1 oracle oinstall 35840 01-27 19:10 041j0nlu_1_1
四、将备份文件传输到另外一台服务器,可以使用rman,备份到nfs上
[root@odd201 ~]# scp root@192.168.101.202:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/011j0nl1_1_1 /home/oracle/bak
root@192.168.101.202's password:
011j0nl1_1_1 100% 1523KB 1.5MB/s 00:00
[root@odd201 ~]# scp root@192.168.101.202:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/021j0nl2_1_1 /home/oracle/bak
root@192.168.101.202's password:
021j0nl2_1_1 100% 1021MB 4.8MB/s 03:34
[root@odd201 ~]# scp root@192.168.101.202:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/031j0nls_1_1 /home/oracle/bak
root@192.168.101.202's password:
031j0nls_1_1 100% 9600KB 4.7MB/s 00:02
[root@odd201 ~]# scp root@192.168.101.202:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/041j0nlu_1_1 /home/oracle/bak
root@192.168.101.202's password:
041j0nlu_1_1 100% 35KB 35.0KB/s 00:00
五、建立密码文件
[oracle@odd201 dbs]$ orapwd file=orapwTESTPROD password=oracle entries=10 force=y ignorecase=y
六、建立启动参数文件和目录结构
[oracle@odd201 dbs]$ cp initPROD3.ora initTESTPROD.ora
[oracle@odd201 dbs]$ vi initTESTPROD.ora
db_name='TESTPROD'
instance_name='TESTPROD'
memory_target=1G
processes = 150
audit_file_dest='/u01/app/oracle/admin/TESTPROD/adump'
audit_trail ='db'
db_block_size=8192
deferred_segment_creation=false
db_domain='PROD3.oracle.com'
db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app/oracle'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
# You may want to ensure that control files are created on separate physical
# devices
control_files = ('/u01/app/oracle/oradata/TESTPROD/control01.ctl','/u01/app/oracle/oradata/TESTPROD/control02.ctl')
compatible =11.2.0.0.0
[oracle@odd201 ~]$ mkdir -p /u01/app/oracle/admin/TESTPROD/adump
[oracle@odd201 ~]$ mkdir -p /u01/app/oracle/oradata/TESTPROD/
[oracle@odd201 ~]$
七、开始恢复
[oracle@odd201 ~]$ export ORACLE_SID=TESTPROD
[oracle@odd201 ~]$ rman auxiliary /
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Jan 27 19:54:20 2023
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to auxiliary database: TESTPROD (not mounted)
[oracle@odd201 ~]$ rman auxiliary /
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Jan 27 20:57:48 2023
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to auxiliary database: TESTPROD (not mounted)
RMAN> duplicate target database to TESTPROD spfile
2> backup location '/home/oracle/bak'
3> nofilenamecheck;
Starting Duplicate Db at 27-JAN-23
contents of Memory Script:
{
restore clone spfile to '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileTESTPROD.ora' from
'/home/oracle/bak/031j0nls_1_1';
sql clone "alter system set spfile= ''/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileTESTPROD.ora''";
}
executing Memory Script
Starting restore at 27-JAN-23
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK
channel ORA_AUX_DISK_1: restoring spfile from AUTOBACKUP /home/oracle/bak/031j0nls_1_1
channel ORA_AUX_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 27-JAN-23
sql statement: alter system set spfile= ''/u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileTESTPROD.ora''
contents of Memory Script:
{
sql clone "alter system set db_name =
''TESTPROD'' comment=
''duplicate'' scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
sql statement: alter system set db_name = ''TESTPROD'' comment= ''duplicate'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''PROD'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''TESTPROD'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone primary controlfile from '/home/oracle/bak/031j0nls_1_1';
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''PROD'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''TESTPROD'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
Starting restore at 27-JAN-23
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=18 device type=DISK
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/PROD/control01.ctl
output file name=/u01/app/oracle/oradata/PROD/control02.ctl
Finished restore at 27-JAN-23
database mounted
released channel: ORA_AUX_DISK_1
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=18 device type=DISK
RMAN-05538: WARNING: implicitly using DB_FILE_NAME_CONVERT
contents of Memory Script:
{
set until scn 1040531;
set newname for datafile 1 to
"/u01/app/oracle/oradata/PROD/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/PROD/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/PROD/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/PROD/users01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/PROD/example01.dbf";
restore
clone database
;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 27-JAN-23
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/PROD/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/PROD/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/PROD/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/PROD/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/PROD/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/bak/021j0nl2_1_1
channel ORA_AUX_DISK_1: piece handle=/home/oracle/bak/021j0nl2_1_1 tag=TAG20230127T191026
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 27-JAN-23
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=1127250045 file name=/u01/app/oracle/oradata/PROD/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=1127250045 file name=/u01/app/oracle/oradata/PROD/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=1127250045 file name=/u01/app/oracle/oradata/PROD/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=1127250045 file name=/u01/app/oracle/oradata/PROD/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=5 STAMP=1127250045 file name=/u01/app/oracle/oradata/PROD/example01.dbf
contents of Memory Script:
{
set until scn 1040531;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 27-JAN-23
using channel ORA_AUX_DISK_1
starting media recovery
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=7
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/bak/041j0nlu_1_1
channel ORA_AUX_DISK_1: piece handle=/home/oracle/bak/041j0nlu_1_1 tag=TAG20230127T191054
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_1127175109.dbf thread=1 sequence=7
channel clone_default: deleting archived log(s)
archived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_1127175109.dbf RECID=1 STAMP=1127250045
media recovery complete, elapsed time: 00:00:01
Finished recover at 27-JAN-23
contents of Memory Script:
{
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set db_name =
''TESTPROD'' comment=
''Reset to original value by RMAN'' scope=spfile";
sql clone "alter system reset db_unique_name scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
sql statement: alter system set db_name = ''TESTPROD'' comment= ''Reset to original value by RMAN'' scope=spfile
sql statement: alter system reset db_unique_name scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TESTPROD" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/app/oracle/oradata/PROD/redo01.log' ) SIZE 50 M REUSE,
GROUP 2 ( '/u01/app/oracle/oradata/PROD/redo02.log' ) SIZE 50 M REUSE,
GROUP 3 ( '/u01/app/oracle/oradata/PROD/redo03.log' ) SIZE 50 M REUSE
DATAFILE
'/u01/app/oracle/oradata/PROD/system01.dbf'
CHARACTER SET ZHS16GBK
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/PROD/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u01/app/oracle/oradata/PROD/sysaux01.dbf",
"/u01/app/oracle/oradata/PROD/undotbs01.dbf",
"/u01/app/oracle/oradata/PROD/users01.dbf",
"/u01/app/oracle/oradata/PROD/example01.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/PROD/temp01.dbf in control file
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/PROD/sysaux01.dbf RECID=1 STAMP=1127250158
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/PROD/undotbs01.dbf RECID=2 STAMP=1127250158
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/PROD/users01.dbf RECID=3 STAMP=1127250158
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/PROD/example01.dbf RECID=4 STAMP=1127250158
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=1127250158 file name=/u01/app/oracle/oradata/PROD/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=1127250158 file name=/u01/app/oracle/oradata/PROD/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=1127250158 file name=/u01/app/oracle/oradata/PROD/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=1127250158 file name=/u01/app/oracle/oradata/PROD/example01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 27-JAN-23
注意问题:后台报错,提示没有目录权限
Could not open audit file: /u01/app/oracle/admin/PROD/adump/testprod_ora_19486_2.aud
Retry Iteration No: 1 OS Error: 0
Retry Iteration No: 2 OS Error: 2
Retry Iteration No: 3 OS Error: 2
Retry Iteration No: 4 OS Error: 2
Retry Iteration No: 5 OS Error: 2
OS Audit file could not be created; failing after 5 retries
Fri Jan 27 20:32:44 2023
Could not open audit file: /u01/app/oracle/admin/PROD/adump/testprod_ora_19680_1.aud
Retry Iteration No: 1 OS Error: 2
Retry Iteration No: 2 OS Error: 2
Retry Iteration No: 3 OS Error: 2
Retry Iteration No: 4 OS Error: 2
Retry Iteration No: 5 OS Error: 2
OS Audit file could not be created; failing after 5 retries
Could not open audit file: /u01/app/oracle/admin/PROD/adump/testprod_ora_19680_1.aud
Retry Iteration No: 1 OS Error: 2
Retry Iteration No: 2 OS Error: 2
Retry Iteration No: 3 OS Error: 2
Retry Iteration No: 4 OS Error: 2
Retry Iteration No: 5 OS Error: 2
解决办法:
创建以下两个目录权限
[oracle@odd201 TESTPROD]$ mkdir -p /u01/app/oracle/admin/PROD/adump/
[oracle@odd201 TESTPROD]$ mkdir -p /u01/app/oracle/oradata/PROD/
最后
以上就是爱笑保温杯为你收集整理的rman异地恢复oracle数据库的全部内容,希望文章能够帮你解决rman异地恢复oracle数据库所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复