table of contents
常用命令
使用rman客户端登录数据库
rman target / rman target / nocatalog
查看rman配置
rman> show all;
使用rman启停数据库
rman> shutdown immediate; rman> startup;
运行操作系统命令
run {host "ls -l /backup";}
批处理模式
# 静默执行脚本里的备份rman语句,结果输出到log文件中
cat >> /tmp/rman_show.sql <show all;
report schema;
!
rman target / cmdfile=/tmp/rman_show.sql log=/tmp/rman_show.log append
skip
跳过offline的数据文件
backup database skip offline;
跳过不能访问的数据文件
backup database skip inaccessible;
跳过只读表空间
backup database skip readonly;
跳过多种文件
backup database skip offline skip readonly skip inaccessible;
list 命令
概述可用的备份
rman> list backup summary;
按备份类型列出备份
rman>list backup by file;
列出详细备份
rman>list backup;
列出过期备份
rman> list expired backup;
列出表空间和数据文件备份
rman> list backup of tablespace system;
rman> list backup of datafile 3;
列出归档日志备份
rman> list archivelog all; 简要信息
rman> list backup of archivelog all; 详细信息
rman> list backup of archivelog from time=’sysdate-2’;
列出控制文件和服务器参数文件
rman>list backup of controlfile;
rman>list backup of spfile;
report 命令
报告数据库模式
rman> report schema;
报告丢弃的备份。如果使用了保存策略,备份会标记为丢弃状态
rman> report obsolete;
删除丢弃状态备份
rman> delete noprompt obsolete;
报告最近没有被备份的数据文件
rman> report need backup days=1;
报告备份冗余或恢复窗口
rman> report need backup redundancy 2;
rman> report need backup recovery window of 2 days;
报告数据文件的不可恢复操作
rman> report unrecoverable;
crosscheck 命令
概述
- 备份集有两种状态:
a (available,rman认为该项存在于备份介质上)
x (expired,备份存在于控制文件或恢复目录中,但是并没有物理存在于备份介质上) - crosscheck 的目的是检查rman的目录以及物理文件:
如果物理文件不存在于介质上,将标记为expired。
如果物理文件存在,将维持available。
如果原先标记为expired的备份集再次存在于备份介质上(如恢复了损坏的磁盘驱动器后),crosscheck将把状态重新从expired标记回available。 - crosscheck 输出分两部分
第一部分列出确定存在于备份介质上的所有备份集片
第二部分列出不存在于备份介质上的备份集片,并将其标记为expired
核对所有备份集
rman> crosscheck backup;
核对所有数据文件的备份集
rman> crosscheck backup of database;
核对特定表空间的备份集
rman> crosscheck backup of tablespace users;
核对特定数据文件的备份集
rman> crosscheck backup of datafile 4;
核对控制文件的备份集
rman> crosscheck backup of controlfile;
核对spfile的备份集
rman> crosscheck backup of spfile;
核对归档日志的备份集
rman> crosscheck backup of archivelog;
核对所有映像副本
rman> crosscheck copy;
核对所有数据文件的映像副本
rman> crosscheck copy of database;
核对特定表空间的映像副本
rman> crosscheck copy of tablespace users;
核对特定数据文件的映像副本
rman> crosscheck copy of datafile 6;
核对归档日志的映像副本
rman> crosscheck copy of archivelog sequence 4;
核对控制文件的映像副本
rman> crosscheck copy of controlfile;
备份
完全备份
run{
# 删除丢弃状态备份
delete noprompt obsolete;
delete noprompt expired backup;
delete noprompt expired archivelog all;
# 设置两个备份通道, 每个备份片最大100m
allocate channel c1 type disk maxpiecesize=100m;
allocate channel c2 type disk maxpiecesize=100m;
# 完全备份, 每个文件的备份片不超过4个
backup database filesperset 4 format '/backup/oracle/ora_l0_%d_%t_%s_%p';
# 备份归档
alter system archive log current;
alter system archive log current;
alter system archive log current;
backup archivelog all format '/backup/oracle/arch_l0_%d_%t_%s_%p' delete input;
# 备份控制文件
backup current controlfile format '/backup/oracle/ctl_l0_%d_%t_%s_%p';
# 核对所有备份集
crosscheck backup;
# 核对所有归档日志备份集
crosscheck archivelog all;
}
增量备份
0级备份
像完整备份一样复制所有的数据库
run{
delete noprompt obsolete;
delete noprompt expired backup;
delete noprompt expired archivelog all;
allocate channel c1 type disk maxpiecesize=100m;
allocate channel c2 type disk maxpiecesize=100m;
backup incremental level=0 database format '/backup/oracle/ora_l0_%d_%t_%s_%p' filesperset 4;
alter system archive log current;
alter system archive log current;
alter system archive log current;
crosscheck archivelog all;
backup archivelog all format '/backup/oracle/arch_%d_%t_%s_%p' delete all input;
backup current controlfile format='/backup/oracle/ctl_%d_%t_%s_%p';
backup spfile format='/backup/oracle/spfile_%d_%t_%s_%p';
crosscheck backup;
crosscheck archivelog all;
release channel c1;
release channel c2;
}
1级备份
首先有一个基本的级别为0的备份,然后在0级备份的基础上备份更新的数据块
run{
delete noprompt obsolete;
delete noprompt expired backup;
delete noprompt expired archivelog all;
allocate channel c1 type disk maxpiecesize=100m;
allocate channel c2 type disk maxpiecesize=100m;
backup incremental level=1 database format '/backup/oracle/ora_l1_%d_%t_%s_%p' filesperset 4;
alter system archive log current;
alter system archive log current;
alter system archive log current;
crosscheck archivelog all;
backup archivelog all format '/backup/oracle/arch_%d_%t_%s_%p' delete all input;
backup current controlfile format='/backup/oracle/ctl_%d_%t_%s_%p';
backup spfile format='/backup/oracle/spfile_%d_%t_%s_%p';
crosscheck backup;
crosscheck archivelog all;
release channel c1;
release channel c2; }
差异增量备份:备份最近级别为1或级别为0的增量备份后更改的所有块
累计增量备份:备份最近级别为0的增量备份后更改的所有块
恢复
所有数据文件丢失
- 查看数据文件位置
select file_name,tablespace_name from dba_data_files; - 启动数据库到nomount状态
shutdown abort
startup nomount; - 查找控制文件备份及恢复
rman target /
restore controlfile from ‘/backup/oracle/ctl_l0_oracle_20220929_16_1’; - 启动数据库到mount状态
alter database mount; - 找到最新的归档集并注册
list backup of archivelog all;
catalog backuppiece ‘/backup/oracle/arch_oracle_20220929_22_1’;
catalog backuppiece ‘/backup/oracle/arch_oracle_20220929_23_1’;
catalog backuppiece ‘/backup/oracle/arch_oracle_20220929_24_1’; - 恢复数据
restore database; - 恢复归档
recover database; - 重置redo
alter database open resetlogs;
spfile 丢失
- 查看spfile备份文件
list backup of spfile; - 恢复spfile
rman> restore spfile from ‘spfile_oracle_20220929_26_1’;
单个数据文件丢失
-
根据报错确定丢失的数据文件
-
关闭数据库
shutdown abort -
进入rman
rman target / -
启动数据库到mount
startup mount -
恢复数据文件
rman> restore datafile 7;
rman> recover datafile 7; -
启动数据库
rman> alter database open;
数据文件和日志文件丢失, 控制文件和spfile文件存在
- 控制文件还在启动到mount状态
rman> startup mount; - 恢复数据
rman> restore database; - 恢复归档日志
rman> recover database; - 启动数据库
rman> alter database open;
脚本
rman备份脚本:
运行命令:./backup_dbname_ora.sh dbname
运行条件:系统挂载有nfs网络磁盘于/backup文件夹
导出
1.创建导出文件夹
create [or replace] directory directory as 'pathname';
create directory dump_dir as '/u01/app/dump';
# 查看:
select * from all_directories;
2.给相应用户赋权
grant read,write on directory dump_dir to scott;
3.导出
表
expdp scott/tiger directory=dump_dir dumpfile=tab.dmp tables=dept,emp logfile=tab.log
方案
expdp scott/tiger directory=dump_dir dumpfile=schema.dmp schemas=system,scott
表空间
expdp scott/tiger directory=dump_dir dumpfile=users.dmp tablespaces=users
数据库
# 管理员用户
expdp system/oracle123 directory=dump_dir dumpfile=full.dmp full=y
导入
1. 创建设置dump_dir,传输dum文件
创建
mkdir /u01/app/dump chown -r oracle:oinstall /u01/app/dump
sqlplus设置
create directory dump_dir as '/u01/app/dump';
create [or replace] directory directory as 'pathname';
# 查看:
select * from all_directories;
2. 设置用户权限
grant read,write on directory dump_dir to scott;
3. 导入
impdp scott/tiger directory=dump_dir dumpfile=table.dmp tables=dept,emp,im impdp scott/tiger directory=dump_dir dumpfile=schema.dmp tablespace=user
最后修改时间:2022-10-18 10:33:35
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。