-- 设置归档日志路径 alter system set log_archive_dest_1='LOCATION=/archivelog'; -- 关闭数据库,重启至mount模式 shutdown immediate startup mount -- 开启归档模式 alter database archivelog; -- 打开数据库 alter database open; -- 检查归档模式是否打开 archive log list
如上图,数据库打开归档模式之后,接下来就可以开始部署 RMAN 脚本进行在线备份了。
由于打开归档模式后会源源不断的产生归档日志,所以建议部署一个定期删除归档的任务:
## oracle 用户下执行 SCRIPTSDIR=/home/oracle/scripts mkdir -p ${SCRIPTSDIR} { echo '#!/bin/bash' echo 'source ~/.bash_profile' echo 'deltime=`date +"20%y%m%d%H%M%S"`' echo "rman target / nocatalog msglog ${SCRIPTSDIR}/del_arch_\${deltime}.log<<EOF" echo 'crosscheck archivelog all;' echo "delete noprompt archivelog until time 'sysdate-7';" echo "delete noprompt force archivelog until time 'SYSDATE-10';" echo 'EOF' } >>${SCRIPTSDIR}/del_arch.sh
set line222 set pagesize1000 col status for a10 col input_type for a20 col INPUT_BYTES_DISPLAY for a10 col OUTPUT_BYTES_DISPLAY for a10 col TIME_TAKEN_DISPLAY for a10 select input_type, status, to_char(start_time, 'yyyy-mm-dd hh24:mi:ss'), to_char(end_time, 'yyyy-mm-dd hh24:mi:ss'), input_bytes_display, output_bytes_display, time_taken_display, COMPRESSION_RATIO from v$rman_backup_job_details order by 3 desc;
# 关闭数据库,将报错 shutdown immediate # 强制关闭 shutdown abort # startup 启动时会报错ORA-00205: error in identifying control file, check alert log for more info startup
# 显示not mount rman target / # 进行恢复,不过中间过程比较痛苦,要一个个实验过来 restore controlfile from '/backup/data_SPECTRA_20240115_1158330783_96_1';
# 关闭数据库 shutdown immediate #将报错ORA-01116: error in opening database file 2 #ORA-01110: data file 2: '/oradata/SPECTRA/datafile/o1_mf_testdb1_lt9nc80o_.dbf' #ORA-27041: unable to open file #Linux-x86_64 Error: 2: No such file or directory
# 强制关闭 shutdown abort # startup 启动时会报错ORA-00205: error in identifying control file, check alert log for more info startup
# 显示 mount rman target / # 恢复被删除的数据文件 restore database;
-- 会列出坏块 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 8 FAILED 01293341310723685503 File Name: /oradata/SPECTRA/testDB.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 01398 Index 0166 Other 3174
validate found oneor more corrupt blocks See trace file /u01/app/oracle/diag/rdbms/spectra/spectra/trace/spectra_ora_22937.trc for details Finished backup at22-JAN-24
su - oracle rman target / ## 执行全库备份 run { allocate channel c1 device type disk; allocate channel c2 device type disk; crosscheck backup; crosscheck archivelog all; sql"alter system switch logfile"; delete noprompt expired backup; delete noprompt obsolete device type disk; backup database include current controlfile format '/backup/data_%d_%T_%t_%s_%p'; backup archivelog all DELETE INPUT format '/backup/arch_%d_%T_%t_%s_%p'; release channel c1; release channel c2; }
## 查询rman备份结果 set line222 set pagesize1000 col status for a10 col input_type for a20 col INPUT_BYTES_DISPLAY for a10 col OUTPUT_BYTES_DISPLAY for a10 col TIME_TAKEN_DISPLAY for a10 select input_type, status, to_char(start_time, 'yyyy-mm-dd hh24:mi:ss'), to_char(end_time, 'yyyy-mm-dd hh24:mi:ss'), input_bytes_display, output_bytes_display, time_taken_display, COMPRESSION_RATIO from v$rman_backup_job_details order by 3 desc;