一、备份原库,将备份的文件拷贝到单实例的相同目录
backup as compressed backupset database plus archivelog format '/u01/app/oracle/backup_db/full_%d_%s_%p_%u.%T';
run{
allocate channel d1 type disk maxpiecesize=20G;
allocate channel d2 type disk maxpiecesize=20G;
allocate channel d3 type disk maxpiecesize=20G;
allocate channel d4 type disk maxpiecesize=20G;
backup database format '/u01/app/dump/qmcb_bak/db_%U_%T' include current controlfile;
sql 'alter system archive log current';
backup archivelog like '/u01/app/archive_log/%' format '/u01/app/dump/qmcb_bak/arch_%U_%T';
backup spfile format '/u01/app/dump/qmcb_bak/spfile_%U_%T';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
select sid,spid,client_info from v$process p,v$session s where p.addr=s.paddr and client_info like '%rman%';
-- delete input 从 log_archive_Dest_n 位置删除日志
-- delete input 备份后只删除用于备份的归档日志文件的那个复制的输入对象
scp * oracle@192.168.93.222:/u01/app/oracle/backup_db/
二、修改单实例的参数文件
create pfile='/u01/app/oracle/backup_db/initorcl.ora' from spfile;
vi initorcl.ora
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.dbf','/u01/app/oracle/oradata/orcl/control02.dbf'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=1000
*.log_archive_dest_1='location=/u01/app/archive_log'
*.log_archive_format='%t_%s_%r.dbf'
*.max_dump_file_size='200m'
*.open_cursors=300
*.pga_aggregate_target=2147483648
*.processes=1000
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_limit=TRUE
*.sessions=1250
*.sga_target=3221225472
*.timed_statistics=TRUE
*.undo_tablespace='UNDOTBS2'
scp initorcl.ora oracle@192.168.100.199:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
用传过来的pfile生成spfile文件
SQL> create spfile from pfile='/u01/app/oracle/backup_db/initorcl1.ora';
SQL> startup nomount;
三、恢复控制文件
rman target /
restore controlfile from '/u01/app/dump/qmcb_bak/control_c-1365404862-20191226-00.BKU';
alter database mount;
检查并标记控制文件中存在但是实际已经不存在的备份文件。
RMAN>crosscheck backup;
清理控制文件中存在但是实际已经不存在的备份文件。
RMAN>delete noprompt expired backup;
将备份注册到rman,如果备份及路径一致则不需要注册。
RMAN> catalog backuppiece '/u01/app/dump/qmcb_bak/ORCL_125_1_3tt920g8.20180727';
RMAN> catalog backuppiece '/u01/app/dump/qmcb_bak/ORCL_127_1_3vt920i4.20180727';
RMAN> catalog backuppiece '/u01/app/dump/qmcb_bak/db_ORCL_129_1_41t9224q.20180727';
RMAN> catalog backuppiece '/u01/app/dump/qmcb_bak/44t923ek_1_1';
RMAN> catalog backuppiece '/u01/app/dump/qmcb_bak/c-1510034848-20180727-03';
catalog backuppiece '/u01/app/dump/qmcb_bak/arch_q4ukcv45_1_1_20191226';
四、还原数据文件,需要指定scn号,可以list backup查看,需要写到你能恢复到的那个时间点,SCN 为最新的SCN号。
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/ssd/oradata/orcl/system01.dbf
/u01/ssd/oradata/orcl/sysaux01.dbf
/u01/ssd/oradata/orcl/zabbix01.dbf
/u01/ssd/oradata/orcl/users01.dbf
/u01/ssd/oradata/orcl/data01.dbf
/u01/ssd/oradata/orcl/data02.dbf
/u01/photo/oradata/UNDOTBS2.dbf
/u01/ssd/oradata/orcl/RKXX_PHOTO01.dbf
/u01/ssd/oradata/orcl/users11.dbf
/u01/ssd/oradata/orcl/users12.dbf
/u01/ssd/oradata/orcl/users02.dbf
/u01/ssd/oradata/orcl/users03.dbf
/u01/ssd/oradata/orcl/users13.dbf
/u01/ssd/oradata/orcl/users14.dbf
/u01/ssd/oradata/orcl/users15.dbf
/u01/ssd/oradata/orcl/users04.dbf
/u01/ssd/oradata/orcl/users05.dbf
/u01/ssd/oradata/orcl/users16.dbf
/u01/ssd/oradata/orcl/users17.dbf
/u01/ssd/oradata/orcl/users18.dbf
/u01/photo/oradata/data03.dbf
/u01/photo/oradata/data04.dbf
/u01/photo/oradata/data05.dbf
/u01/photo/oradata/data06.dbf
/u01/photo/oradata/data07.dbf
/u01/photo/oradata/data08.dbf
/u01/ssd/oradata/orcl/users06.dbf
/u01/ssd/oradata/orcl/users07dbf
/u01/ssd/oradata/orcl/users08dbf
/u01/ssd/oradata/orcl/users09.dbf
/u01/ssd/oradata/orcl/users10.dbf
RMAN> list backup of archivelog all;
根据备份信息,恢复数据文件及数据库并同步控制文件信息
RUN {
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
set until scn 16708288579293;
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/system01.dbf' to '/u01/app/oracle/oradata/orcl/system01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/sysaux01.dbf' to '/u01/app/oracle/oradata/orcl/sysaux01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/zabbix01.dbf' to '/u01/app/oracle/oradata/orcl/zabbix01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users01.dbf' to '/u01/app/oracle/oradata/orcl/users01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/data01.dbf' to '/u01/app/oracle/oradata/orcl/data01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/data02.dbf' to '/u01/app/oracle/oradata/orcl/data02.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/UNDOTBS2.dbf' to '/u01/app/oracle/oradata/orcl/UNDOTBS2.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/RKXX_PHOTO01.dbf' to '/u01/app/oracle/oradata/orcl/RKXX_PHOTO01.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users11.dbf' to '/u01/app/oracle/oradata/orcl/users11.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users12.dbf' to '/u01/app/oracle/oradata/orcl/users12.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users02.dbf' to '/u01/app/oracle/oradata/orcl/users02.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users03.dbf' to '/u01/app/oracle/oradata/orcl/users03.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users13.dbf' to '/u01/app/oracle/oradata/orcl/users13.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users14.dbf' to '/u01/app/oracle/oradata/orcl/users14.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users15.dbf' to '/u01/app/oracle/oradata/orcl/users15.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users04.dbf' to '/u01/app/oracle/oradata/orcl/users04.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users05.dbf' to '/u01/app/oracle/oradata/orcl/users05.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users16.dbf' to '/u01/app/oracle/oradata/orcl/users16.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users17.dbf' to '/u01/app/oracle/oradata/orcl/users17.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users18.dbf' to '/u01/app/oracle/oradata/orcl/users18.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data03.dbf' to '/u01/app/oracle/oradata/orcl/data03.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data04.dbf' to '/u01/app/oracle/oradata/orcl/data04.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data05.dbf' to '/u01/app/oracle/oradata/orcl/data05.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data06.dbf' to '/u01/app/oracle/oradata/orcl/data06.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data07.dbf' to '/u01/app/oracle/oradata/orcl/data07.dbf';
SET NEWNAME FOR DATAFILE '/u01/photo/oradata/data08.dbf' to '/u01/app/oracle/oradata/orcl/data08.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users06.dbf' to '/u01/app/oracle/oradata/orcl/users06.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users07dbf' to '/u01/app/oracle/oradata/orcl/users07.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users08dbf' to '/u01/app/oracle/oradata/orcl/users08.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users09.dbf' to '/u01/app/oracle/oradata/orcl/users09.dbf';
SET NEWNAME FOR DATAFILE '/u01/ssd/oradata/orcl/users10.dbf' to '/u01/app/oracle/oradata/orcl/users10.dbf';
RESTORE DATABASE;
SWITCH DATAFILE ALL;
recover database;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 110875 and starting SCN of 16708288579684
recover database until scn 16708288579684;
五、查看日志文件修改日志文件的路径
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/ssd/oradata/orcl/redo03.log
/u01/ssd/oradata/orcl/redo02.log
/u01/ssd/oradata/orcl/redo01.log
alter database rename file '/u01/ssd/oradata/orcl/redo03.log' to '/u01/app/oracle/oradata/orcl/redo03.log';
alter database rename file '/u01/ssd/oradata/orcl/redo02.log' to '/u01/app/oracle/oradata/orcl/redo02.log';
alter database rename file '/u01/ssd/oradata/orcl/redo01.log' to '/u01/app/oracle/oradata/orcl/redo01.log';
六、打开数据库,完成续操作
alter database open resetlogs;
查看redo log 信息,并删除无效日志组
select THREAD#, STATUS, ENABLED from v$thread;
THREAD# STATUS ENABLED
---------- ------------------ ------------------------
1 OPEN PUBLIC
2 CLOSED PUBLIC
select group# from v$log where THREAD#=2;
GROUP#
----------
4
5
6
SQL> alter database disable thread 2;
SQL> alter database drop logfile group 4;
SQL> alter database drop logfile group 5;
SQL> alter database drop logfile group 6;
SQL> select THREAD#, STATUS, ENABLED from v$thread;
THREAD# STATUS ENABLED
---------- ------ --------
1 OPEN PUBLIC
查看undo表空间,并删除节点2(在此不使用)的undo表空间
SQL> show parameter undo;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1
SQL> select tablespace_name from dba_tablespaces where contents='UNDO';
TABLESPACE_NAME
------------------------------
UNDOTBS1
UNDOTBS2
SQL> drop tablespace UNDOTBS2 including contents and datafiles;
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/ORCL/datafile/o1_mf_temp_cr602c5z_.tmp
SQL> select tablespace_name from dba_tablespaces where contents='TEMPORARY';
TABLESPACE_NAME
------------------------------
TEMP
SQL> create temporary tablespace TEMP1 tempfile '/u01/app/oracle/oradata/orcl/temp01.dbf' size 10G autoextend on maxsize unlimited;
SQL> alter database default temporary tablespace TEMP1;
SQL> drop tablespace TEMP including contents and datafiles;
查看监听状态并配置,编辑tnsname.ora文件。
创建密码文件,注意密码文件的位置
$ orapwd file=orapworcl password=oracle123456 entries=5 force=y