window下实现oracle数据库简单(异机)【rman备份】+【rman恢复】

环境准备

两台虚拟机:win10 + Oracle11.2.0.4.0

备份机

开启自动归档

(cmd) sqlplus / as sysdba (cmd 下输入此命令)
(sql) archive log list; (查看是否开启存档模式)

(sql) shutdown immediate; (立即关闭数据库)
(sql) startup mount; (启动实例并加载数据库,但不打开)
(sql) alter database archivelog; (更改数据库为归档模式)
(sql) alter database open; (打开数据库)
(sql) alter system archive log start; (启用自动归档)

(sql) archive log list; (再次查看是否开启存档模式)

![[image/Pasted image 20240515225124.png]]
![[image/Pasted image 20240515225059.png]]


创建目录:C:\backup(待会会用到)


查看现存数据

(cmd) sqlplus / as sysdba;
(sql) select * from table1;
(sql) insert into table1 (id,name) values(3,'name3');
(sql) commit;
(sql) select * from table1;
(sql) exit

![[image/Pasted image 20240515214031.png]]


备份
进行一次完整的数据库备份(增量0级别备份),包括数据库、控制文件、归档日志和spfile,并且使用两个磁盘通道以并行的方式进行备份操作。

(cmd) rman target /
(rman) run{
	allocate channel c1 type disk;
	allocate channel c2 type disk;
	backup incremental level 0 database
	include current controlfile format 'C:\backup2\db_%T_%s_%p.lv0'
	plus archivelog delete all input format 'C:\backup2\arc%T_%s_%p.arc';
	backup spfile format='C:\backup2\spfile_tpy100_%T_%s_%p.bak';
	release channel c1;
	release channel c2;
}
(rman) exit

![[image/Pasted image 20240515214449.png]]
![[image/Pasted image 20240515214733.png]]


导出的备份:

![[image/Pasted image 20240515214850.png]]



恢复机

创建目录:C:\backup ,将上述备份出的文件放入到恢复机中

![[image/Pasted image 20240515214938.png]]


备份原数据库

-- 查询数据库文件在哪里
(cmd) sqlplus / as sysdba
(sql) select name from v$datafile

![[image/Pasted image 20240515203644.png]]

-- 关闭数据库,为了方便备份 备份机 自己的原数据库
(sql) shut immediate

![[image/Pasted image 20240515211438.png]]


找到上述datafile显示的路径:存储数据的地方

![[image/Pasted image 20240515203312.png]]
![[image/Pasted image 20240515204000.png]]
![[image/Pasted image 20240515204103.png]]


恢复

-- 启动数据库
(sql) startup nomount
(sql) exit

![[image/Pasted image 20240515211338.png]]

-- 进入rman
(cmd) rman target /

-- 恢复控制文件
(rman) restore controlfile from 'C:\backup\DB_20240515_64_1.LV0';

![[image/Pasted image 20240515211924.png]]

-- 在rman中执行sql语句,挂载数据库
(rman) sql 'alter database mount';

-- 将新的备份信息导入到控制文件中,noprompt表示不进行确认提示
catalog start with 'C:\backup\' noprompt;

![[image/Pasted image 20240515212516.png]]

-- 恢复
(rman) run{
	allocate channel c1 type disk;
	allocate channel c2 type disk;
	restore database;
	switch datafile all;
	recover database;
	release channel c1;
	release channel c2;
}
(rman) exit

![[image/Pasted image 20240515212909.png]]![[image/Pasted image 20240515213013.png]]

-- 打开数据库,并退出方便重新连接
(cmd) sqlplus / as sysdba
(sql) alter database open resetlogs;
(sql) exit

![[image/Pasted image 20240515213210.png]]


检验

-- 检验
(cmd) sqlplus / as sysdba
(sql) select * from table1;

![[image/Pasted image 20240515213338.png]]

在恢复机上恢复成功!

猜你喜欢

转载自blog.csdn.net/luohaojia123/article/details/139066812