☰
rman恢复常用命令完整
2026/10/14 8:00:33 网站建设 项目流程

一、恢复前查看
# 查看源数据库的DBID:
select dbid from v$database;

# 查看控制文件:
select name from v$controlfile;

# 查看数据文件:
select status,name from v$datafile;

# 查看日志文件:
select * from v$logfile;

rman查看方式
list backup of spfile;
list backup of controlfile;
list backup of database;
list backup of archivelog all;


二、rman还原
1、创建恢复目录
mkdir -p /data/oracle
mkdir -p /data/oracle/admin/jwell/adump
mkdir -p /data/oracle/oradata/jwell
mkdir -p /data/oracle/fast_recovery_area/jwell
mkdir -p /data/oracle/archivelog1/jwell

chown -R oracle:oinstall /data/backup/ora_backup
chown -R oracle:oinstall /data/oracle

2、启动数据库,非归档模式
shutdown immediate;
shutdown abort;

select DBID from v$database;
set dbid=781653821

3、还原spfile
(1)方式一
create pfile='/home/oracle/dqpfile.ora' from spfile;

startup nomount pfile='/home/oracle/dqpfile.ora'

create spfile from pfile='/home/oracle/dqpfile.ora';

(2)方式二
startup nomount
startup force nomount;

restore spfile to '/data/oracle/product/11.2.0/dbs/spfilejwell.ora' from '/data/backup/ora_backup/20260618/ke4qumj5_1_1_lvl_2.dbf';

4、还原controlfile
restore controlfile to '/data/oracle/oradata/jwell/control01.ctl' from '/data/backup/ora_backup/20260618/kd4qumj1_1_1_lvl_2.dbf';

restore controlfile to '/data/oracle/fast_recovery_area/jwell/control02.ctl' from '/data/backup/ora_backup/20260618/kd4qumj1_1_1_lvl_2.dbf';

5、还原数据库
startup mount;
alter database mount;

# 将备份集信息重新导入到当前控制文件中(一定要用“/”结尾,不然可能会找不到真实的路径)
catalog start with '/data/backup/ora_backup/' NOPROMPT;

run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
allocate channel c5 device type disk;
allocate channel c6 device type disk;
allocate channel c7 device type disk;
allocate channel c8 device type disk;
set newname for database to '/data/oracle/oradata/jwell/%b'; #修改目录执行,原来的数据文件目录在/u01/admin/oradata下面,我们将数据文件恢复到/bre1/oradata下面,%b的意思是只获取文件名 #
restore database until time "to_date('2026-06-24 10:00:00','yyyy-mm-dd hh24:mi:ss')";
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
}

select name from v$datafile;
select name from v$tempfile;
select member from v$logfile;


#修改目录执行
select 'alter database rename file '''||name||''' to ''/data/oracle/oradata/jwell'||substr(name,length(name)-INSTR(reverse(name),'/')+1,INSTR(reverse(name),'/'))||''';' from v$datafile
union all
select 'alter database rename file '''||name||''' to ''/data/oracle/oradata/jwell'||substr(name,length(name)-INSTR(reverse(name),'/')+1,INSTR(reverse(name),'/'))||''';' from v$tempfile
union all
select 'alter database rename file '''||member||''' to ''/data/oracle/oradata/jwell'||substr(member,length(member)-INSTR(reverse(member),'/')+1,INSTR(reverse(member),'/'))||''';' from v$logfile;

如果开了block_change_track
alter database rename file '/oracle/home/oradata/jwell/block_change_track/block_track.dbf' to '/data/oracle/oradata/jwell/block_track.dbf';

如果有归档文件
catalog start with '/home/oracle/jwell/' NOPROMPT;
或
catalog archivelog '/xxx/arc_123.arc','/xxx/arc_124.arc';
或
alter system set log_archive_dest_1='/data/oracle/archivelog1/jwell' scope=both;

run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
allocate channel c5 device type disk;
allocate channel c6 device type disk;
allocate channel c7 device type disk;
allocate channel c8 device type disk;
recover database until time "to_date('2026-06-24 10:00:00','yyyy-mm-dd hh24:mi:ss')";
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
}

alter database open read only;

alter database open resetlogs;

select name,OPEN_MODE from v$database;

alter session set current_schema = JWWL;

select count(*) from auth_user;


需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询