码迷,mamicode.com
首页 > 其他好文 > 详细

rman基础操作

时间:2020-07-12 12:26:18      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:query   let   gen   设备   pfile   grep   sql   variable   覆盖   

环境:oracle12c

1、链接rman

RMAN
RMAN> connect target /       ---使用sys用户连接
connected to target database: ORCL (DBID=1567775293)
RMAN> connect target "sys/oracle@orcl as sysdba"
connected to target database: ORCL (DBID=1567775293)
[oracle@12c ~]$ rman target /
[oracle@12c ~]$ rman target sys/oracle

2、理论东西

技术图片
配置磁盘设置
1)并行度
2)磁盘备份的位置
3)磁盘备份的类型  Image Copy、Backup Set、Compressed Backup Set
4)设置备份片段文件最大值
5)指定Compressed Backup Set的压缩算法

配置备份的设置
1)开启控制文件和SPFILE文件的自动备份 指定自动备份的文件存储的位置
2)开启备份优化   可以跳过read-only、offline的数据文件,不做备份
3)开启块跟踪功能  针对增量备份 加快的备份数据 指定Block Change Tracking File位置。
desc v$block_change_tracking; V$BLOCK_CHANGE_TRACKING displays the status of block change tracking for the database.
SELECT * FROM v$block_change_tracking;
DISABLED            
4)整个数据库的备份排除某些表空间
5)Retention Policy  a)保留所有备份   b)保留策略为指定的天数   c)保留策略为指定的备份数
使用FRA存储备份,RMAN会通过自动删除备份(保留策略)


将控制文件备份到trace file --生成重新创建控制文件的SQL语句
Specify USING BACKUP CONTROLFILE if you want to use a backup control file instead of the current control file.
Use the BACKUP CONTROLFILE clause to back up the current control file. The database must be open or mounted when you specify this clause.
TO filename
TO TRACE
ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
The trace files are stored in a subdirectory determined by the DIAGNOSTIC_DEST initialization parameter. You can find the name and location of the trace file to which the CREATE CONTROLFILE statements were written by looking in the alert log. You can also find the directory for trace files by querying the NAME and VALUE columns of the V$DIAG_INFO dynamic performance view.

[oracle@12c trace]$ tail -f alert_orcl.log
2020-07-12T20:06:29.593981+08:00
ALTER DATABASE BACKUP CONTROLFILE TO TRACE
2020-07-12T20:06:29.621788+08:00
Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_25012.trc
Completed: ALTER DATABASE BACKUP CONTROLFILE TO TRACE


[oracle@12c ~]$ file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_25012.trc
/u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_25012.trc: ASCII text
[oracle@12c ~]$ more /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_25012.trc


管理备份
1)catalog Additional Files(将其他备份文件列入目录)  将非RMAN备份文件设置为可以通过RMAM找到
2)Crosscheck All (交叉检验)  如果用户可以手动删除RMAN备份,rman的备份的文件和物理的文件进行检查
3)Delete All Obsolete  根据保留策略删除备份
4)Delete All Expired    根据交叉检查未找到的备份删除

目标数据库对RMAN进行修改
desc v$rman_configuration
SELECT * FROM v$rman_configuration;  V$RMAN_CONFIGURATION lists information about RMAN persistent configuration settings.
View Code

3、配置默认的备份的设备的类型

RMAN> show default device type;   --查看默认备份的设备类型
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default

RMAN> configure default device type to sbt;
RMAN> configure default device type to disk;  --配置成磁盘

RMAN> configure default device type CLEAR;   ---恢复到默认配置
old RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
RMAN configuration parameters are successfully reset to default value

4、备份时指定备份设备类型

使用bakup命令 device type 子句覆盖default device type
RMAN>BACKUP DEVICE TYPE sbt TABLESPACE users;
RMAN>BACKUP DEVICE TYPE DISK TABLESPACE users;
RMAN>BACKUP TABLESPACE users;  --使用默认的default device type

5、配置默认的备份的类型

Image Copy、Backup Set、Compressed Backup Set
RMAN> show device type;  --查看默认备份类型
RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY;
RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO BACKUPSET;
RMAN> CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET;

6、使用backup命令 AS 覆盖默认的备份的类型,备份时指定备份类型。

BACKUP AS BACKUPSET ...
BACKUP AS COPY ...
BACKUP AS COMPRESSED BACKUPSET...
BACKUP   --不加就使用默认的

7、三种备份类型的大小比较

RMAN> backup as copy tablespace users;  #copy images拷贝镜像方式
[oracle@12c ~]$ ll -h /u02/app/oracle/fast_recovery/ORCL/datafile/o1_mf_users_hjp3506h_.dbf
-rw-r-----. 1 oracle oinstall 91M Jul 12 21:14 /u02/app/oracle/fast_recovery/ORCL/datafile/o1_mf_users_hjp3506h_.dbf
RMAN> backup as backupset tablespace users;  #备份集方式
[oracle@12c ~]$ ll -h /u02/app/oracle/fast_recovery/ORCL/backupset/2020_07_12/o1_mf_nnndf_TAG20200712T211632_hjp39j3s_.bkp
-rw-r-----. 1 oracle oinstall 85M Jul 12 21:16 /u02/app/oracle/fast_recovery/ORCL/backupset/2020_07_12/o1_mf_nnndf_TAG20200712T211632_hjp39j3s_.bkp
RMAN> list backup of tablespace users;   #默认的是压缩COMPRESSED BACKUPSET;
[oracle@12c ~]$ ll -h /u02/app/oracle/fast_recovery/ORCL/backupset/2020_07_12/o1_mf_nnndf_TAG20200712T211741_hjp3coq2_.bkp
-rw-r-----. 1 oracle oinstall 10M Jul 12 21:17 /u02/app/oracle/fast_recovery/ORCL/backupset/2020_07_12/o1_mf_nnndf_TAG20200712T211741_hjp3coq2_.bkp
RMAN> backup tablespace users;

 8、配置channel (备份文件存放位置)

RMAN> show channel for device type disk;
通过命令设置disk、sbt的channel  CONFIGURE命令
在备份的run块中使用allocate channel设置当前的channel
RMAN> configure channel device  type disk format /tmp/backup_%U;
RMAN> configure channel device type disk maxpiecesize 2G;

配置disk、sbt device的并行度
RMAN> configure device type disk parallelism 2;
RMAN> show device type;

9、设置控制文件、参数文件自动备份

RMAN> show controlfile autobackup;
RMAN> configure controlfile autobackup on;
RMAN> configure controlfile autobackup off;
RMAN> configure controlfile autobackup clear;
RMAN> show controlfile autobackup format;   --查看控制文件、spfile文件自动备份文件的格式   默认存放在FRA中
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO %F; # default(默认格式为%F,下面解析下%F格式)
The %F variable format translates into c-IIIIIIIIII-YYYYMMDD-QQ, with the placeholders defined as follows:
IIIIIIIIII stands for the DBID.   SELECT dbid FROM v$database;
YYYYMMDD is a time stamp of the day the backup is generated.
QQ is the hexadecimal sequence that starts with 00 and has a maximum of FF.

RMAN> configure controlfile autobackup format for device type disk to /home/oracle/autobackup/auto_%F.bak;

RMAN> list backup of controlfile;  --查看RMAN中 目标数据库的备份的控制文件

10、设置备份优化 备份跳过read-only offline的数据文件

RMAN> show backup optimization;
RMAN> configure backup optimization on;       --开启
RMAN> configure backup optimization off;      --关闭
RMAN> configure backup optimization CLEAR;    --还原

11、设置Block Change Tracking(开启块跟踪,增量备份会跳过没有变动的块,速度会加快,块跟踪会启动一个进行跟踪块的写会给数据库增加负载)

SELECT * FROM v$block_change_tracking;  --查看现在是否打开块跟踪
DISABLED            
[oracle@12c blkTrace]$ ps -ef|grep ctwr| grep -v grep   --开启块跟踪会启动进程
oracle    33303      1  0 22:07 ?        00:00:00 ora_ctwr_orcl

Specify USING FILE filename if you want to name the block change tracking file instead of letting Oracle Database generate a name for it. You must specify this clause if you are not using Oracle Managed Files.

ENABLE BLOCK CHANGE TRACKING             --启用块跟踪
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;    --使用OMF方式存储block change tracking file
SELECT * FROM v$block_change_tracking;
ENABLED    /u01/app/oradata/ORCL/changetracking/o1_mf_hjp6096y_.chg    11599872    0
show parameter db_create_file_dest
NAME                TYPE   VALUE            
------------------- ------ ---------------- 
db_create_file_dest string /u01/app/oradata 
[oracle@12c changetracking]$ file o1_mf_hjp6096y_.chg 
o1_mf_hjp6096y_.chg: data
ALTER DATABASE ENABLE BLOCK CHANGE  TRACKING USING FILE /home/oracle/blkTrace/orcl_20200712_blktrace;  --指定块跟踪文件保存位置
SELECT * FROM v$block_change_tracking;


DISABLE BLOCK CHANGE TRACKING    --禁用块跟踪
Specify this clause if you want Oracle Database to stop tracking changes and delete the existing block change tracking file.
ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
SELECT * FROM v$block_change_tracking;
DISABLED            
[oracle@12c changetracking]$ pwd
/u01/app/oradata/ORCL/changetracking
[oracle@12c changetracking]$ ls -l         --禁用后会删除跟踪的块文件
total 0

12、备份排除的表空间

RMAN> show exclude;
RMAN> configure exclude for tablespace users;
RMAN> show exclude;
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE EXCLUDE FOR TABLESPACE USERS;

RMAN> backup database;   --排除users表空间的数据文件
Starting backup at 12-JUL-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=73 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=47 device type=DISK
file 7 is excluded from whole database backup  --排除的文件

RMAN> backup database noexclude;  --备份不排除设置的文件

 

rman基础操作

标签:query   let   gen   设备   pfile   grep   sql   variable   覆盖   

原文地址:https://www.cnblogs.com/wukc/p/13287763.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!