1.创建备份集
1.创建自定义路径表空间备份
RMAN> backup as backupset format '/opt/oracle/df_%d_%s_%p.bkc' tablespace users;
RMAN> backup tablespace fixf:system;
设置备份集分片大小
RMAN> backup as backupset format '/opt/oracle/df_%d_%s_%p.bkc' tablespace users section size=300M;
2.创建自定义路径数据库备份
RMAN> backup as backupset format '/opt/oracle/df_%d_%s_%p.bkc' database;
3.自定义标识备份
backup tag 'full_db_bkp' format '/u01/backup/db_%U' database;
创建全库备份加归档日志
BACKUP DATABASE PLUS ARCHIVELOG
创建全库备份加归档日志删除已归档日志
BACKUP DATABASE PLUS ARCHIVELOG DELETE INPUT;
必须在发出以下CONFIGURE 命令后,才能按上述方式进行备份:
• CONFIGURE DEFAULT DEVICE TYPE TO disk;
• CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COPY;
• CONFIGURE CONTROLFILE AUTOBACKUP ON;
为数据库中所有数据文件和控制文件的以前的映像副本创建备份
RMAN> BACKUP COPY OF DATABASE;
备份users表空间及控制文件,归档日志
backup tablespace users include current controlfile plus archivelog;
backup datafile 1 plus archivelog;
1.2 备份归档日志
backup archivelog all delete input;
backup archivelog from sequence 353 delete input;
backup archivelog not backed up 3 times;
backup archivelog from time 'sysdate-3';
backup archivelog until time 'sysdate -2' delete all input;
1.3备份备份集
backup backupset all;
backup backupset all format='/opt/oracle/back/backup_%U.BAK' TAG='backup of backupsets' channel 'ora_disk';
backup backupset completed before 'sysdate-2';
backup backupset complete before 'sysdate-2' delete input; 备份最近2天的所有备份集
backup backup set complet after 'sysdate-2' delete input;备份2天前的所有备份集,并删除已经备份的备份集
1.4备份归档数据库和归档重做日志
backup database plus archivelog;
2.设置备份运行指定的持续时间
此时间段过后数据库取消备份
backup duration 00:30 database;
3.设置备份期间i/o平均分布,持续时间的的各个时间点上
backup duration 00:30 minimize load database;平均性能
backup duration 00:30 minimize time database;全速备份(默认值)
4.备份时指定保留日期
backup database keep forever;永久保留 ----需要恢复目录------永久保存不能放在控制文件
backup database format '/opt/oracle/back/%U' keep until time='sysdate+180' tag keep_backup;
backup database format '/opt/oracle/back/%U' keep until time='sysdate+180' restore point gold_copy;
5.备份被configure参数指定排除之外的数据
RMAN> backup database noexclude keep forever tag='test_backup';
6.备份时跳过脱机,不可访问,只读的数据文件
backup database skip readonly;
backup database skip offline;
backup database skip inaccessible;
backup database skip readonly skip offline skip inaccessible;
7.强制备份,备份所有数据文件
backup database fore;
8.只备份新添加的数据文件
backup database not backup up;
9.备份指定时间周期内没有被备份的数据文件
backup database not backed up since time='sysdate -2';
10.备份至少备份2次的归档日志,删除已经备份2次的归档日志
RMAN> backup as compressed backupset database plus archivelog not backed up 2
times delete input;
11.检查逻辑损坏块
backup check logical database;检查坏块同时备份数据
backup avlidate check logical database;检查坏块不备份数据
12.备份控制文件
RMAN> backup current controlfile; 备份控制文件
spfile和控制文件自动备份:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
设置自动备份的存储位置:
configure controlfile autobackup format for device type disk to '/u01/backup/ctl_%F';
configure controlfile autobackup format for device type disk clear;
13.备份映像副本
backup as copy database;
list copy;还可以显示归档日志文件
backup as copy datafile 4;
backup as copy datafile 4 format '/u01/backup/user01.bak'
12.
2.管理备份:报告
LIST:显示资料档案库中记录的有关备份集、代理副本和映像副本的信息
REPORT:生成资料档案库的详细分析信息
REPORT NEED BACKUP:列出需要备份的所有数据文件
REPORT OBSOLETE:标识按照备份保留策略不再需要的文件
管理备份:动态性能视图
• V$BACKUP_SET:创建的备份集
• V$BACKUP_PIECE:存在的备份片段
• V$DATAFILE_COPY:磁盘上的数据文件副本
• V$BACKUP_FILES:有关创建备份时所创建的所有
文件的信息
管理备份:交叉检查和删除
CROSSCHECK:针对介质(如磁盘或磁带)验证在RMAN 资料档案库中记录的备份和副本的状态
• DELETE EXPIRED:只删除资料档案库中状态为EXPIRED 的文件
• DELETE OBSOLETE:删除不再需要的备份