RMAN冷备全库
rman target /
list backup
shutdown immediate
startup mount
#不要自动备份control file
set nocfau;
#注意要先备份数据库,然后备份控制文件,因为数据库的备份位置记录在控制文件中。
#备份数据库
backup database format '/mnt/disk01/rman_backup_dir2/db_%d_%T_%U.bak';#备份控制文件
backup current controlfile format '/mnt/disk01/rman_backup_dir2/ctl_%d_%T_%U.bak';
恢复12c的时候,要先给12c建一个库(如果12c没有库或库已经升级为19c,用dbca),再用rman恢复,否则不行。建库参考:12c DBCA建库
恢复之前的备份
(在12c的环境下,ORACLE_HOME等)
注意,只能还原相同版本Oracle的备份,即使是小版本不同,都不行。
rman target /
startup force nomount;
restore controlfile from '/mnt/disk01/rman_backup_dir2/ctl_PAAS_20221019_051am6dk_1_1.bak';#还原控制文件后,不必指定数据库备份的位置,因为这个信息已经在备份文件中
startup force mount;
restore database;
alter database open resetlogs;
RMAN连接server process来工作。
备份策略:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
CONFIGURE RETENTION POLICY TO recovery window of 7 days;
通过设置备份策略,决定哪些备份是obsolete,obsolete的备份并不会自动删除,需要手工删除:list backup
report obsolete
delete obsolete
使用RMAN既可以做单独的tablespace备份,datafile备份,也可以做全库备份:
backup database format '/u01/app/oracle/backup-rman/db_%d_%T_%U.bak';
或直接
backup database;
会备份到db_recovery_file_dest设置的目录。
或压缩备份
backup as compressed backupset database;
$ORACLE_HOME下的dbs中的c-2191530773-20210705-00,这样的文件是控制文件的备份。
RMAN备份的目录:
db_recovery_file_dest 也是闪回恢复区
alter system set db_recovery_file_dest_size = 10G scope=spfile;
alter system set db_recovery_file_dest='/u01/app/oracle/backup-rman' scope=both;
show parameter db_recovery_file_dest
如果手工删除了归档文件,RMAN中删除就会出错。如果要操作系统的文件和RMAN元文件中的记录相同步,在RMAN中使用
crosscheck backup;
然后执行
report obsolete
或
delete obsolete
delete expired backup
crosscheck archivelog all;
delete expired archivelog all;
list backup;
report need backup;
删除备份集:
对一个数据库的备份包括许多备份文件,这就是一个备份集:
delete backupset 备份集号;
delete backup; --- 删除所有备份集;
delete archivelog from time 'sysdate-7'; 删除7天前到现在的归档
catalog start with '/u01/backup/prod/hot/';
change backuppiece 17 uncatalog;
backup cumulative incremental level 1 database;
backup incremental level 1 database format '/u01/app/oracle/backup-rman/db_%d_%T_%U.bak';
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup database filesperset 4 format '/u01/app/oracle/backup/rman/full_%d_%T_%s_%p';
sql 'alter system archive log current';
sql 'alter system archive log current';
sql 'alter system archive log current';
backup archivelog all format '/u01/app/oracle/backup/rman/arch_%d_%T_%s_%p' delete input;
backup current controlfile format '/u01/app/oracle/backup/rman/ctl_%d_%T_%s_%p';
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt expired backup;
delete noprompt expired archivelog all;
}
恢复
run {
startup force nomount;
restore controlfile from '/u01/app/oracle/backup/rman/ctl_CDB_20210707_85_1';
startup force mount;
restore database;
recover database until available redo;
alter database open resetlogs;
}
run {
startup force nomount;
restore controlfile from '/u01/app/oracle/backup/rman/ctl_CDB_20210707_85_1';
startup force mount;
set until scn 3707239;
restore database;
recover database;
alter database open resetlogs;
}
场景2:
完全恢复,使用D的controlfile(使用A的controlfile只能恢复到C)
run {
startup force nomount;
restore controlfile from '/u01/app/oracle/backup/rman/ctl_CDB_20210707_89_1';
startup force mount;
restore database;
recover database until available redo;
alter database open resetlogs;
}
run {
startup force nomount;
restore controlfile from '/u01/app/oracle/backup/rman/ctl_CDB_20210707_85_1';
startup force mount;
set until scn 3707239;
restore database;
recover database;
alter database open resetlogs;
}
run {
startup force nomount;
restore controlfile from '/u01/app/oracle/backup/rman/ctl_CDB_20210707_87_1';
startup force mount;
set until scn 3707239;
restore database;
recover database;
alter database open resetlogs;
}
startup force mount;
allocate channel c1 type disk;
allocate channel c2 type disk;
sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';
set until time '2021-07-06 11:08:16';
restore database;
recover database;
alter database open resetlogs;
}
从全备恢复spfile和controlfile
没有使用catalog时,rman所有的配置信息,都存储在controlfile中。