rman配置操作
环境: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.
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; --备份不排除设置的文件
13、配置rman保留策略
RMAN> show retention policy; --查看当前数据库的保留策略 1)恢复时间窗口 将数据库恢复到时间窗口中的某个时间点 在恢复窗口时间内不要的数据文件、归档文件标记为 Obsolete RMAN> configure retention policy to recovery window of 5 days; 2)备份文件冗余的数量 rman保留备份文件的份数 超过冗余的备份文件标记为 Obsolete RMAN> configure retention policy to redundancy 2; 根据保留策略查看RMAN标记为Obsolete状态的备份 RMAN> report obsolete; 删除状态为Obsolete备份文件使用delete obsolete RMAN> delete obsolete; RMAN> delete noprompt obsolete; ---设置无提示信息删除 3)禁用RMAN的保留策略,任何备份都不会被标记为obsolete,无法通过delete obsolete删除文件。 RMAN> configure retention policy to none; 设置保留策略为rman的默认值 rman的默认的保留策略为冗余度为1 RMAN> configure retention policy clear;
14、配置归档日志的保留策略
独立于数据库备份的保留策略而单独设置归档日志的保留策略,可以应用于FRA和FRA之外的归档日志文件。 RMAN> show archivelog deletion policy; 通过RMAN>delete archivelog all; 设置rman的压缩算法 RMAN> show compression algorithm; 查看当前数据库支持的压缩的算法 desc v$rman_compression_algorithm; SELECT * FROM v$rman_compression_algorithm; RMAN> configure compression algorithm 'HIGH'; RMAN> backup as compressed backupset database;
15、配置RMAN的加密功能
启用透明加密的功能 禁用透明加密的功能 RMAN> CONFIGURE ENCRYPTION FOR DATABASE OFF; RMAN> CONFIGURE ENCRYPTION FOR DATABASE ON; RMAN> CONFIGURE ENCRYPTION FOR DATABASE CLEAR; 设置RMAN的加密算法 CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default 查看数据库提供 desc v$rman_encryption_algorithm SELECT name FROM v$fixed_table WHERE name LIKE 'V$RMAN_ENCRYPTION_ALGO%'; desc V$RMAN_ENCRYPTION_ALGORITHMS SELECT * FROM V$RMAN_ENCRYPTION_ALGORITHMS; 1 AES128 AES 128-bit key YES NO 0 2 AES192 AES 192-bit key NO NO 0 3 AES256 AES 256-bit key NO NO 0 在12C可以直接在rman中执行SQL命令 在12C之前的rman执行sql语句 RMAN> sql ''; RMAN> SELECT dbid from v$database; DBID ---------- 1567775293 RMAN> configure encryption algorithm 'AES256';
16、配置BackupSet的最大值
RMAN> show maxsetsize; RMAN configuration parameters for database with db_unique_name ORCL are: CONFIGURE MAXSETSIZE TO UNLIMITED; # default RMAN> configure maxsetsize to 1M; --配置备份集大小1M; RMAN> backup tablespace users; --因为太小所以不能进行备份即报错 Starting backup at 13-JUL-20 using channel ORA_DISK_1 using channel ORA_DISK_2 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of backup command at 07/13/2020 14:46:47 RMAN-06183: datafile or datafile copy /u01/app/oracle/oradata/orcl/users01.dbf (file number 7) larger than MAXSETSIZE RMAN> configure maxsetsize clear; RMAN> backup tablespace users maxsetsize 10m; --在backup命令指定maxsetsize大小
17、配置backup duplexing
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default configure duplex设置只能针对datafile、archived log、control file的backupset,不能是image copies。 RMAN> show datafile backup copies; RMAN configuration parameters for database with db_unique_name ORCL are: CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default RMAN> show archivelog backup copies; RMAN configuration parameters for database with db_unique_name ORCL are: CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default RMAN> backup datafile 7; Starting backup at 13-JUL-20 using channel ORA_DISK_1 using channel ORA_DISK_2 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00007 name=/u01/app/oracle/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 13-JUL-20 channel ORA_DISK_1: finished piece 1 at 13-JUL-20 piece handle=/u02/app/oracle/fast_recovery/ORCL/backupset/2020_07_13/o1_mf_nnndf_TAG20200713T145249_hjr161m0_.bkp tag=TAG20200713T145249 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 Finished backup at 13-JUL-20 Starting Control File and SPFILE Autobackup at 13-JUL-20 piece handle=/u02/app/oracle/fast_recovery/ORCL/autobackup/2020_07_13/o1_mf_s_1045666372_hjr164pk_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 13-JUL-20 RMAN> configure datafile backup copies for device type disk to 2; RMAN> backup datafile 7; --不能是image copies。 Starting backup at 13-JUL-20 using channel ORA_DISK_1 using channel ORA_DISK_2 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00007 name=/u01/app/oracle/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 13-JUL-20 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/13/2020 14:54:01 ORA-19806: cannot make duplex backups in recovery area
18、配置多channe(通道,提高速度)
[oracle@12c oracle]$ mkdir disk{1,2} [oracle@12c oracle]$ ls -l total 0 drwxr-xr-x. 2 oracle oinstall 6 Jul 13 14:55 disk1 drwxr-xr-x. 2 oracle oinstall 6 Jul 13 14:55 disk2 drwxr-xr-x. 3 oracle oinstall 18 Jul 12 14:59 fast_recovery RMAN> configure channel 1 device type disk format '/u02/app/oracle/disk1/%U'; new RMAN configuration parameters: CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT '/u02/app/oracle/disk1/%U'; new RMAN configuration parameters are successfully stored released channel: ORA_DISK_1 released channel: ORA_DISK_2 RMAN> show datafile backup copies; RMAN configuration parameters for database with db_unique_name ORCL are: CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2; RMAN> configure device type disk parallelism 1; RMAN> backup datafile 7; Starting backup at 13-JUL-20 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=66 device type=DISK channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00007 name=/u01/app/oracle/oradata/orcl/users01.dbf channel ORA_DISK_1: starting piece 1 at 13-JUL-20 channel ORA_DISK_1: finished piece 1 at 13-JUL-20 with 2 copies and tag TAG20200713T150039 piece handle=/u02/app/oracle/disk1/17v5770n_1_1 comment=NONE piece handle=/u02/app/oracle/disk1/17v5770n_1_2 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 Finished backup at 13-JUL-20 Starting Control File and SPFILE Autobackup at 13-JUL-20 piece handle=/u02/app/oracle/fast_recovery/ORCL/autobackup/2020_07_13/o1_mf_s_1045666842_hjr1ntlx_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 13-JUL-20 RMAN> run { 2> allocate channel c1 device type disk format '/u02/app/oracle/disk1/%U'; 3> allocate channel c2 device type disk format '/u02/app/oracle/disk2/%U'; 4> backup tablespace users; 5> release channel c1; 6> release channel c2; 7> } Starting backup at 13-JUL-20 channel c1: starting compressed full datafile backup set channel c1: specifying datafile(s) in backup set input datafile file number=00011 name=/u01/app/oracle/oradata/orcl/user0102.dbf input datafile file number=00013 name=/u01/app/oracle/oradata/orcl/user0104.dbf input datafile file number=00007 name=/u01/app/oracle/oradata/orcl/users01.dbf channel c1: starting piece 1 at 13-JUL-20 channel c2: starting compressed full datafile backup set channel c2: specifying datafile(s) in backup set input datafile file number=00012 name=/u01/app/oracle/oradata/orcl/user0103.dbf input datafile file number=00014 name=/u01/app/oracle/oradata/orcl/user0105.dbf channel c2: finished piece 1 at 13-JUL-20 with 2 copies and tag TAG20200713T150642 piece handle=/u02/app/oracle/disk2/1ev577c3_1_1 comment=NONE piece handle=/u02/app/oracle/disk2/1ev577c3_1_2 comment=NONE channel c1: finished piece 1 at 13-JUL-20 with 2 copies and tag TAG20200713T150642 piece handle=/u02/app/oracle/disk1/1dv577c2_1_1 comment=NONE piece handle=/u02/app/oracle/disk1/1dv577c2_1_2 comment=NONE channel c1: backup set complete, elapsed time: 00:00:04 Finished backup at 13-JUL-20
19、常用备份命令
RMAN> backup current controlfile; RMAN> backup spfile; RMAN> backup datafile 7; RMAN> backup tablespace users; RMAN> backup database noexclude; RMAN> backup database plus archivelog; RMAN> backup database plus archivelog delete intput; RMAN> backup archivelog all; RMAN> backup archivelog all delete input;
20、常用查看命令
列出数据文件备份,归档日志备份,控制文件和spfile文件备份列出备份信息。 RMAN> list backup by file; RMAN> list backup of controlfile; RMAN> list backup of spfile; 列出到期的备份 RMAN> list expired backup; RMAN> list expired backup of archivelog all; 按表空间名和数据文件号列出备份 RMAN> list backup of tablespace users; RMAN> list backup of datafile 3; 列出归档日志备份 查看当前存在的归档日志(并不意味着它们已经备份) RMAN> list archivelog all; 列出归档日志备份 RMAN> list backup of archivelog all; 列出备份中过期的归档 RMAN> list expired backup of archivelog all; 设定时间或日志序列号来限制报告中显示的内容,如: RMAN> list expired backup of archivelog until sequence 3; RMAN> list expired backup of archivelog until time "to_date('2013-4-1','yyyy-mm-dd')"; 列出incarnation RMAN> list incarnation;
做一个决定,并不难,难的是付诸行动,并且坚持到底。