Rman備份恢復
啟用歸檔
--檢查是否為歸檔
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1423
Current log sequence 1425
No Archive Mode 表示非歸檔模式
開歸檔:
alter database archivelog;
關歸檔:
alter database noarchivelog;
★ 開啟歸檔步驟
--關庫
shutdown immediate;
startup mount;
--配置歸檔路徑
alter system set log_archive_dest_1='location=/home/oracle/arch';
--開啟歸檔
alter database archivelog;
-- 確認開啟了歸檔
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/arch
Oldest online log sequence 1423
Next log sequence to archive 1425
Current log sequence 1425
Rman備份
前置條件
開啟控制檔案自動備份,否則在做全量備份時,rman也會生成控制檔案快照,只是這個控制檔案快照生於備份集產生,不包含最後一次的備份資訊,因而不能用於最後一次備份集恢復,所以一定要開啟控制檔案自動備份。
相關指令碼
[[email protected] rmans]$ cat startrmans.sh #!/bin/bash bak_dir=/home/oracle/rmans # mkdir -p $bak_dir/{logs,data} day=`date +%Y%m%d` echo "$day begin backup." rman target / @$bak_dir/fullbak.sql log=$bak_dir/logs/fullbak`date +%Y%m%d`.log echo "$day end backup." [[email protected] rmans]$ cat fullbak.sql run{ backup full database include current controlfile format '/home/oracle/rmans/data/fullback_%d_%T_%s'; }
rman備份集清理
手工刪除了備份集磁碟檔案後,使用crosscheck backupset 檢查會提示EXPIRED.
RMAN> crosscheck backupset ;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=776 device type=DISK
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/rmans/data/fullback_ORCL_20181217_2 RECID=1 STAMP=995105790
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/rmans/data/fullback_ORCL_20181217_3 RECID=2 STAMP=995107713
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/home/oracle/rmans/data/fullback_ORCL_20181217_4 RECID=3 STAMP=995107750
Crosschecked 3 objects
RMAN> delete expired backupset;
using channel ORA_DISK_1
List of Backup Pieces
BP Key BS Key Pc# Cp# Status Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
1 1 1 1 EXPIRED DISK /home/oracle/rmans/data/fullback_ORCL_20181217_2
2 2 1 1 EXPIRED DISK /home/oracle/rmans/data/fullback_ORCL_20181217_3
3 3 1 1 EXPIRED DISK /home/oracle/rmans/data/fullback_ORCL_20181217_4
Do you really want to delete the above objects (enter YES or NO)? YES
deleted backup piece
backup piece handle=/home/oracle/rmans/data/fullback_ORCL_20181217_2 RECID=1 STAMP=995105790
deleted backup piece
backup piece handle=/home/oracle/rmans/data/fullback_ORCL_20181217_3 RECID=2 STAMP=995107713
deleted backup piece
backup piece handle=/home/oracle/rmans/data/fullback_ORCL_20181217_4 RECID=3 STAMP=995107750
Deleted 3 EXPIRED objects