啓動數據庫:
從root切換到oracle用戶進入:
su - oracle
進入sqlplus環境,nolong參數表示不登陸: sqlplus /nolog
以管理員模式登陸: sqlplus / as sysdba
啓動數據庫: startup
關閉數據庫: shutdown immediate
遠程鏈接數據庫:
sqlplus /nolog conn sys/sys@ip:1521/orainstance as sysdba
開啓監聽: lsnrctl start
查看監聽: lsnrctl status
中止監聽: lsnrctl stop
注意事項:node
1 此處實驗環境爲同平臺,同字節序,同版本,源機器和目標機器相同的目錄結構。sql
2 目標機器只須要安裝oracle數據庫軟件便可。數據庫
3 第一次利用備份恢復測試環境,以後從源機器拷貝備份到目標機器並在控制文件中註冊,再見行恢復測試。oracle
[oracle@hear ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Jun 11 01:52:52 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: HEARDB (DBID=3039837723)
RMAN>
2 分別列出參數文件備份,控制文件備份,數據文件備份,以及歸檔備份的名字app
# 參數文件備份:
RMAN> list backup of spfile;
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
19 Full 9.36M DISK 00:00:00 10-JUN-19
BP Key: 19 Status: AVAILABLE Compressed: NO Tag: TAG20190610T231216
Piece Name: /home/oracle/test/db1/c-3039837723-20190610-00
SPFILE Included: Modification time: 10-JUN-19
SPFILE db_unique_name: HEARDB
# 控制文件備份以下:
RMAN> list backup of controlfile;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
17 Full 9.33M DISK 00:00:01 10-JUN-19
BP Key: 17 Status: AVAILABLE Compressed: NO Tag: TAG20190610T230946
Piece Name: /home/oracle/test/db1/full_0nu3pjic_HEARDB_20190610
Control File Included: Ckp SCN: 1167815 Ckp time: 10-JUN-19
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
19 Full 9.36M DISK 00:00:00 10-JUN-19
BP Key: 19 Status: AVAILABLE Compressed: NO Tag: TAG20190610T231216
Piece Name: /home/oracle/test/db1/c-3039837723-20190610-00
Control File Included: Ckp SCN: 1167832 Ckp time: 10-JUN-19
# 數據文件備份以下:
RMAN> list backup of database;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
16 Full 1.09G DISK 00:02:20 10-JUN-19
BP Key: 16 Status: AVAILABLE Compressed: NO Tag: TAG20190610T230946
Piece Name: /home/oracle/test/db1/full_0mu3pjdq_HEARDB_20190610
List of Datafiles in backup set 16
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1167758 10-JUN-19 /home/oracle/app/oradata/heardb/system01.dbf
2 Full 1167758 10-JUN-19 /home/oracle/app/oradata/heardb/sysaux01.dbf
3 Full 1167758 10-JUN-19 /home/oracle/app/oradata/heardb/undotbs01.dbf
4 Full 1167758 10-JUN-19 /home/oracle/app/oradata/heardb/users01.dbf
5 Full 1167758 10-JUN-19 /home/oracle/app/oradata/heardb/example01.dbf
# 數據文件備份以下:
RMAN> list backup of database;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
16 Full 1.09G DISK 00:02:20 10-JUN-19
BP Key: 16 Status: AVAILABLE Compressed: NO Tag: TAG20190610T230946
Piece Name: /home/oracle/test/db1/full_0mu3pjdq_HEARDB_20190610
List of Datafiles in backup set 16
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1167758 10-JUN-19 /home/oracle/app/oradata/heardb/system01.dbf
2 Full 1167758 10-JUN-19 /home/oracle/app/oradata/heardb/sysaux01.dbf
3 Full 1167758 10-JUN-19 /home/oracle/app/oradata/heardb/undotbs01.dbf
4 Full 1167758 10-JUN-19 /home/oracle/app/oradata/heardb/users01.dbf
5 Full 1167758 10-JUN-19 /home/oracle/app/oradata/heardb/example01.dbf
# 列出歸檔備份以下:
RMAN> list backup of archivelog all;
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
15 48.19M DISK 00:00:11 10-JUN-19
BP Key: 15 Status: AVAILABLE Compressed: NO Tag: TAG20190610T230930
Piece Name: /home/oracle/test/db1/arch_0lu3pjda_HEARDB_20190610
List of Archived Logs in backup set 15
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 3 1060303 05-JUN-19 1086202 09-JUN-19
1 4 1086202 09-JUN-19 1118538 10-JUN-19
1 5 1118538 10-JUN-19 1139060 10-JUN-19
1 6 1139060 10-JUN-19 1160512 10-JUN-19
1 7 1160512 10-JUN-19 1167743 10-JUN-19
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
18 7.50K DISK 00:00:00 10-JUN-19
BP Key: 18 Status: AVAILABLE Compressed: NO Tag: TAG20190610T231215
Piece Name: /home/oracle/test/db1/arch_0ou3pjif_HEARDB_20190610
List of Archived Logs in backup set 18
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 8 1167743 10-JUN-19 1167821 10-JUN-19
RMAN>
xxxxxxxxxx
export ORACLE_SID=CRM
[oracle@hear oradata]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Jun 11 02:54:56 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> set dbid 3039837723
executing command: SET DBID
RMAN> startup nomount
Oracle instance started
Total System Global Area 2137886720 bytes
Fixed Size 2254952 bytes
Variable Size 1744832408 bytes
Database Buffers 385875968 bytes
Redo Buffers 4923392 bytes
restore spfile to '/oracle/app/db1/dbs/spfileCRM.ora' from '/oracle/app/db1/dbs/0dnsd96i_1_1';
restore spfile to '/home/oracle/test/db1/spfileCRM.ora' from '/home/oracle/test/db1/c-3039837723-20190610-00';
# 操做
RMAN> restore spfile to '/home/oracle/test/db1/spfileCRM.ora' from '/home/oracle/test/db1/c-3039837723-20190610-00';
Starting restore at 11-JUN-19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1135 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /home/oracle/test/db1/c-3039837723-20190610-00
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 11-JUN-19
RMAN> startup force nomount;
Oracle instance started
Total System Global Area 2137886720 bytes
Fixed Size 2254952 bytes
Variable Size 1744832408 bytes
Database Buffers 385875968 bytes
Redo Buffers 4923392 bytes
restore controlfile to '/oracle/CRM2/CRM/control01.ctl' from '/oracle/app/db1/dbs/0dnsd96i_1_1';
restore controlfile to '/home/oracle/app/oradata/crm/control01.ctl' from '/home/oracle/test/db1/c-3039837723-20190610-00';
# 操做
RMAN> restore controlfile to '/home/oracle/app/oradata/crm/control01.ctl' from '/home/oracle/test/db1/c-3039837723-20190610-00';
Starting restore at 11-JUN-19
using channel ORA_DISK_1
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 11-JUN-19
alter database mount;
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
x
# 新備份文件/home/oracle/backup
catalog start with '/home/oracle/backup/';
# 備份文件 /home/oracle/test/db1
catalog start with '/home/oracle/db1/';
備份文件測試
xxxxxxxxxx
RMAN> catalog start with '/home/oracle/db1/';
searching for all files that match the pattern /home/oracle/db1/
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/db1/full_0mu3pjdq_HEARDB_20190610
File Name: /home/oracle/db1/arch_0lu3pjda_HEARDB_20190610
File Name: /home/oracle/db1/arch_0ou3pjif_HEARDB_20190610
File Name: /home/oracle/db1/full_0nu3pjic_HEARDB_20190610
File Name: /home/oracle/db1/c-3039837723-20190610-00
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /home/oracle/db1/full_0mu3pjdq_HEARDB_20190610
File Name: /home/oracle/db1/arch_0lu3pjda_HEARDB_20190610
File Name: /home/oracle/db1/arch_0ou3pjif_HEARDB_20190610
File Name: /home/oracle/db1/full_0nu3pjic_HEARDB_20190610
File Name: /home/oracle/db1/c-3039837723-20190610-00
xxxxxxxxxx
RMAN> restore database;
Starting restore at 11-JUN-19
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1135 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /home/oracle/app/oradata/heardb/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /home/oracle/app/oradata/heardb/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /home/oracle/app/oradata/heardb/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /home/oracle/app/oradata/heardb/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /home/oracle/app/oradata/heardb/example01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/test/db1/full_0mu3pjdq_HEARDB_20190610
channel ORA_DISK_1: piece handle=/home/oracle/test/db1/full_0mu3pjdq_HEARDB_20190610 tag=TAG20190610T230946
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:46
Finished restore at 11-JUN-19
xxxxxxxxxx
RMAN> recover database;
Starting recover at 11-JUN-19
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:06
Finished recover at 11-JUN-19
xxxxxxxxxx
SQL> alter database open resetlogs;