oracle课堂随笔----第二十三天
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle课堂随笔----第二十三天相关的知识,希望对你有一定的参考价值。
RMAN配置
$ rman target / 或rman target sys/[email protected]
RMAN> show all; 所有备份相关设置
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP On;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP clear;
RMAN> backup tablespace users; 备份表空间用户
RMAN> list backup; 查看列表
SQL> desc v$backup_set 浏览器中也可以查看
自动通道管理:
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 2;
RMAN> backup tablespace users, example;
$ mkdir /home/oracle/disk1 /home/oracle/disk2
RMAN> configure channel 1 device type disk to destination ‘/home/oracle/disk1‘;
RMAN> configure channel 2 device type disk to destination ‘/home/oracle/disk2‘;
RMAN> backup tablespace users, example;
恢复默认
RMAN> CONFIGURE DEVICE TYPE DISK clear;
RMAN> CONFIGURE CHANNEL 1 device type disk clear;
RMAN> CONFIGURE CHANNEL 2 device type disk clear;
手动通道管理:
RMAN> run {
allocate channel c1 device type disk to destination ‘/home/oracle/disk1‘;
allocate channel c2 device type disk to destination ‘/home/oracle/disk2‘;
backup tablespace users, example;
或
backup (tablespace users channel c1)(tablespace example channel c2);
}
backup section size 500M datafile 1;
指定备份格式:
RMAN> backup tablespace users; 备份集 bs
RMAN> backup as compressed backupset tablespace users;压缩备份集
RMAN> backup as copy tablespace users;镜像备份
RMAN> list backup of tablespace users;
RMAN> list copy of tablespace users;
备份的加密:
RMAN备份
不归档 归档
online offline online offline
完全 部分 完全 部分 完全 部分 完全 部分
shutdown nomount mount open
备份数据文件:
SQL> select file_id, file_name from dba_data_files;
RMAN> backup datafile 4;
RMAN> backup datafile 4, 5;
RMAN> backup datafile ‘/u01/app/oracle/oradata/orcl/users01.dbf‘;
RMAN> backup tablespace users;(逻辑)
RMAN> backup tablespace users, example;
RMAN> backup database;
RMAN> list backup;
desc v$backup_set,浏览器查看备份
增量备份:备份数据的变化
RMAN> backup incremental level 0 tablespace users;
RMAN> list backup of tablespace users;
SQL> create table t1(x int) tablespace users;
SQL> insert into t1 values (1);
SQL> commit;
RMAN> backup incremental level 1 tablespace users;
RMAN> backup incremental level 1 tablespace users;
SQL> create table t2(x int) tablespace users;
SQL> insert into t2 values (1);
SQL> commit;
RMAN> backup incremental level 1 cumulative tablespace users;
RMAN> list backup of tablespace users;
开启块跟踪:
SQL> alter database enable block change tracking using file ‘/home/oracle/blk_trk.chg‘;
需要重新连接会话
SQL> select * from v$block_change_tracking;
SQL> select DATAFILE_BLOCKS, BLOCKS_READ, BLOCKS, USED_CHANGE_TRACKING from v$backup_datafile where INCREMENTAL_LEVEL>0;
SQL> create table t3(x int) tablespace users;
SQL> insert into t3 values (1);
SQL> commit;
RMAN> backup incremental level 1 tablespace users;
SQL> select DATAFILE_BLOCKS, BLOCKS_READ, BLOCKS, USED_CHANGE_TRACKING from v$backup_datafile where INCREMENTAL_LEVEL>0;
SQL> alter database disable block change tracking; 关闭
增量更新:
SQL> create table t1(x int) tablespace users;
SQL> insert into t1 values (1);
SQL> commit;
RMAN> backup incremental level 1 for recover of copy with tag ‘update_copy‘ tablespace users; 第一次创建的是0级备份
RMAN> list copy; 记录time和scn
SQL> insert into t1 values (2);
SQL> commit;
RMAN> backup incremental level 1 for recover of copy with tag ‘update_copy‘ tablespace users; 第2次创建的是1级备份
RMAN> list backup; backupset格式
RMAN> recover copy of tablespace users with tag ‘update_copy‘;
RMAN> list copy; time和scn更新
脚本形式:
RMAN> run {
backup incremental level 1 for recover of copy with tag ‘update_copy‘ tablespace users;
recover copy of tablespace users with tag ‘update_copy‘;
}
备份归档日志:
RMAN> list archivelog all;
RMAN> backup archivelog all delete all input;
RMAN> list archivelog all;
RMAN> list backup;
备份的维护:
查看:
RMAN> list backup;备份集
RMAN> list copy;镜像拷贝
RMAN> list backup of tablespace users;表空间对应数据文件
RMAN> list backup of datafile 4;
RMAN> list archivelog all;归档日志
检查备份:
RMAN> delete backup; 删除备份
RMAN> delete copy;
RMAN> list backup; list copy;
RMAN> report need backup; 根据策略检查
RMAN> backup tablespace users;
RMAN> report need backup;
RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
RMAN> report need backup;
RMAN> CONFIGURE RETENTION POLICY clear;
RMAN> report obsolete; 冗余>1
删除备份:
RMAN> delete backupset of tablespace users;
RMAN> delete backupset 1234;
RMAN> backup tablespace users;
RMAN> backup tablespace users;
RMAN> show all;
RMAN> delete obsolete;
crosscheck: 交叉检查
RMAN> delete backup;
RMAN> backup tablespace users;
RMAN> list backup of tablespace users;
$ mv /u01/app/oracle/fast_recovery_area/ORCL/backupset/… 改名
RMAN> restore datafile 4; 报错
RMAN> crosscheck backup;
RMAN> list backup of tablespace users; 报废状态
RMAN> list expired backup;
$ mv /u01/app/oracle/fast_recovery_area/ORCL/backupset/… 恢复原名
RMAN> crosscheck backup;
RMAN> list backup of tablespace users; 可用状态
RMAN> delete expired backup;删除报废状态
catalog:
$ cp /u01/app/oracle/fast_recovery_area/ORCL/backupset/… 复制
RMAN> delete backup;
RMAN> list backup; backupset消失
$ mv /u01/app/oracle/fast_recovery_area/ORCL/backupset/… 恢复原名
RMAN> catalog recovery area noprompt; 快速恢复区
RMAN> list backup; backupset恢复
以上是关于oracle课堂随笔----第二十三天的主要内容,如果未能解决你的问题,请参考以下文章