一次磁碟空間緊缺的RMAN備份策略

dbqs8710發表於2014-12-09
使用者有兩套Oracle9i雙節點叢集資料庫,現在分別升級到Oracle10g和Oracle11g。由於新的儲存還沒到位,臨時決定將大多數的儲存都分配給了新系統。 原有生產系統只有300G的備份空間。而這兩套生產系統資料庫需要備份的檔案大約60GB,可用的備份空間卻只有300GB。在新儲存到位之前需要修改一下備份策略,否則這區區300GB用著真是不放心。

現有生產資料庫1:redundancy 2,資料庫2:redundancy 3。

我的思路是:暫時將冗餘全部修改為1,在每次備份結束後再強制刪除obsolete檔案。

下面看看我的環境

可用的備份空間
#df -g /databackup
Filesystem    GB blocks      Free %Used    Iused %Iused Mounted on
/databackup    309.00    190.74   39%       43     1% /databackup

資料庫1
要備份的檔案大小為:23.54GB
SQL> select sum(bytes)/1024/1024/1024 from dba_segments;

SUM(BYTES)/1024/1024/1024
-------------------------
               23.5430984

資料庫2
要備份的檔案大小為:37.07GB
SQL> select sum(bytes)/1024/1024/1024 from dba_segments;

SUM(BYTES)/1024/1024/1024
-------------------------
               37.0738831

每天晚上22:00執行一次全備
crontab
0 22 * * * su - oracledb -c "/home/oracledb/backup.sh”

backup.sh指令碼內容
rman target / nocatalog cmdfile=/home/oraprod/backup.cmd log=/databackup/db1_backup-`date +%Y%m%d`.log

backup.cmd指令碼內容
1,冗餘策略為1
2,分配維護通道 channel for maintenance, 介質為磁碟
3,刪除被廢棄的備份

run {
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
crosscheck backup;
crosscheck archivelog all;
delete force noprompt expired backup;
delete force noprompt expired archivelog all;
allocate channel ch01 device type disk connect sys/wrf496hgkgh@d7i.dtps_prod1;
allocate channel ch02 device type disk connect sys/wrf496hgkgh@DTPS_PROD;
backup
  filesperset 5 format "/databackup/eam_full_%d_%s_%t_%p"
  database include current controlfile;
sql 'alter system archive log current';
backup
  archivelog all delete input filesperset 20 format "/databackup/eam_arch_%d_%s_%t_%p";
release channel ch02;
release channel ch01;
}
report obsolete device type disk;
crosscheck backup;
crosscheck archivelog all;
allocate channel for maintenance type disk;
delete force noprompt obsolete device type disk;


前面為執行全過程的螢幕輸出節選

RMAN> @backup.cmd

RMAN> run {
2> CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
3> crosscheck backup;
4> crosscheck archivelog all;
5> delete force noprompt expired backup;
6> delete force noprompt expired archivelog all;
7> delete force noprompt obsolete;
8> allocate channel ch01 device type disk  connect sys/dskh296fkjdh@prod1;
9> allocate channel ch02 device type disk  connect sys/dskh296fkjdh@prod2;
10> backup
11>   filesperset 15 format "/databackup/fmis_full_%d_%s_%t_%p"
12>   database include current controlfile;
13> sql 'alter system archive log current';
14> backup
15>   archivelog all delete input filesperset 30 format "/databackup/fmis_arch_%d_%s_%t_%p";
16> release channel ch02;
17> release channel ch01;
18> }
old RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
new RMAN configuration parameters are successfully stored

allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=144 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Veritas NetBackup for Oracle - Release 6.5 (2007072323)
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=51 devtype=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/databackup/bk_22893_857568521_1 recid=21765 stamp=857568523
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/databackup/bk_22894_857568546_1 recid=21766 stamp=857568551
…..略
Crosschecked 17 objects

released channel: ORA_SBT_TAPE_1
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=144 devtype=DISK
validation succeeded for archived log
archive log filename=/ora_arch/arch1/1_51948.dbf recid=68949 stamp=857585448
validation succeeded for archived log
archive log filename=/ora_arch/arch1/1_51949.dbf recid=68950 stamp=857585602
…..略
Crosschecked 68 objects

allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=51 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Veritas NetBackup for Oracle - Release 6.5 (2007072323)
using channel ORA_DISK_1

released channel: ORA_SBT_TAPE_1
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=144 devtype=DISK
deleted archive log
archive log filename=/ora_arch/arch1/2_35622.dbf recid=68952 stamp=857585721
deleted archive log
archive log filename=/ora_arch/arch1/2_35623.dbf recid=68956 stamp=857590513
deleted archive log
…..略
Deleted 17 EXPIRED objects

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=51 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Veritas NetBackup for Oracle - Release 6.5 (2007072323)
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           21611  06-SEP-14
  Backup Piece       21765  06-SEP-14          /databackup/bk_22893_857568521_1
Backup Set           21612  06-SEP-14
  Backup Piece       21766  06-SEP-14          /databackup/bk_22894_857568546_1
Backup Set           21613  06-SEP-14
  Backup Piece       21767  06-SEP-14          /databackup/bk_22895_857569000_1
Backup Set           21614  06-SEP-14
  Backup Piece       21768  06-SEP-14          /databackup/bk_22896_857569061_1
Backup Set           21615  06-SEP-14
  Backup Piece       21769  06-SEP-14          /u01/prod/proddb/9.2.0/dbs/c-30397193-20140906-00
Backup Set           21616  06-SEP-14
  Backup Piece       21770  06-SEP-14          /databackup/fmis_al_22899_857569568_1
Backup Set           21633  06-SEP-14
  Backup Piece       21787  06-SEP-14          /databackup/fmis_al_22915_857569742_1
Backup Set           21634  06-SEP-14
  Backup Piece       21788  06-SEP-14          /u01/prod/proddb/9.2.0/dbs/c-30397193-20140906-01
Backup Set           21639  06-SEP-14
  Backup Piece       21793  06-SEP-14          /u01/prod/proddb/9.2.0/dbs/c-30397193-20140906-02
deleted backup piece
backup piece handle=/databackup/bk_22893_857568521_1 recid=21765 stamp=857568523
deleted backup piece
backup piece handle=/databackup/bk_22894_857568546_1 recid=21766 stamp=857568551
…..略
Deleted 9 objects

released channel: ORA_SBT_TAPE_1
released channel: ORA_DISK_1
allocated channel: ch01
channel ch01: sid=75 devtype=DISK

allocated channel: ch02
channel ch02: sid=36 devtype=DISK

Starting backup at 07-SEP-14
channel ch01: starting full datafile backupset
channel ch01: specifying datafile(s) in backupset
input datafile fno=00006 name=/dev/rrbs01.prd
input datafile fno=00014 name=/dev/rMEDIA04.prd
…..略
Finished backup at 07-SEP-14

Starting Control File Autobackup at 07-SEP-14
piece handle=/u01/prod/proddb/9.2.0/dbs/c-30397193-20140907-00 comment=NONE
Finished Control File Autobackup at 07-SEP-14

sql statement: alter system archive log current

Starting backup at 07-SEP-14
current log archived
channel ch01: starting archive log backupset
channel ch01: specifying archive log(s) in backup set
input archive log thread=1 sequence=51948 recid=68949 stamp=857585448
…..略
Finished backup at 07-SEP-14

Starting Control File Autobackup at 07-SEP-14
piece handle=/u01/prod/proddb/9.2.0/dbs/c-30397193-20140907-01 comment=NONE
Finished Control File Autobackup at 07-SEP-14

released channel: ch02

released channel: ch01

此處列出了可以刪除的廢棄備份
RMAN> report obsolete device type disk;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of obsolete backups and copies
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           21635  06-SEP-14
  Backup Piece       21789  06-SEP-14          /databackup/bk_22917_857572554_1
Backup Set           21636  06-SEP-14
  Backup Piece       21790  06-SEP-14          /databackup/bk_22918_857572579_1
Backup Set           21637  06-SEP-14
  Backup Piece       21791  06-SEP-14          /databackup/bk_22919_857573044_1
Backup Set           21638  06-SEP-14
  Backup Piece       21792  06-SEP-14          /databackup/bk_22920_857573095_1
Backup Set           21640  06-SEP-14
  Backup Piece       21794  06-SEP-14          /databackup/al_22923_857584842_1
Backup Set           21641  06-SEP-14
  Backup Piece       21795  06-SEP-14          /databackup/al_22922_857584817_1
Backup Set           21642  06-SEP-14
  Backup Piece       21796  06-SEP-14          /databackup/al_22924_857584821_1
Backup Set           21643  06-SEP-14
  Backup Piece       21797  06-SEP-14          /u01/prod/proddb/9.2.0/dbs/c-30397193-20140906-03
Backup Set           21648  07-SEP-14
  Backup Piece       21802  07-SEP-14          /u01/prod/proddb/9.2.0/dbs/c-30397193-20140907-00
Backup Set           21650  07-SEP-14
  Backup Piece       21804  07-SEP-14          /databackup/fmis_arch_PROD_22931_857657475_1

RMAN> crosscheck backup;
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=144 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Veritas NetBackup for Oracle - Release 6.5 (2007072323)
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=51 devtype=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/databackup/bk_22917_857572554_1 recid=21789 stamp=857572555
crosschecked backup piece: found to be 'AVAILABLE'
…..略
Crosschecked 17 objects

RMAN> crosscheck archivelog all;
released channel: ORA_SBT_TAPE_1
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=144 devtype=DISK
specification does not match any archive log in the recovery catalog

RMAN> allocate channel for maintenance type disk;
released channel: ORA_DISK_1
allocated channel: ORA_MAINT_DISK_1
channel ORA_MAINT_DISK_1: sid=144 devtype=DISK

開始刪除廢棄的備份
RMAN> delete force noprompt obsolete device type disk;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           21635  06-SEP-14
  Backup Piece       21789  06-SEP-14          /databackup/bk_22917_857572554_1
Backup Set           21636  06-SEP-14
  Backup Piece       21790  06-SEP-14          /databackup/bk_22918_857572579_1
Backup Set           21637  06-SEP-14
  Backup Piece       21791  06-SEP-14          /databackup/bk_22919_857573044_1
Backup Set           21638  06-SEP-14
  Backup Piece       21792  06-SEP-14          /databackup/bk_22920_857573095_1
Backup Set           21640  06-SEP-14
  Backup Piece       21794  06-SEP-14          /databackup/al_22923_857584842_1
Backup Set           21641  06-SEP-14
  Backup Piece       21795  06-SEP-14          /databackup/al_22922_857584817_1
Backup Set           21642  06-SEP-14
  Backup Piece       21796  06-SEP-14          /databackup/al_22924_857584821_1
Backup Set           21643  06-SEP-14
  Backup Piece       21797  06-SEP-14          /u01/prod/proddb/9.2.0/dbs/c-30397193-20140906-03
Backup Set           21648  07-SEP-14
  Backup Piece       21802  07-SEP-14          /u01/prod/proddb/9.2.0/dbs/c-30397193-20140907-00
Backup Set           21650  07-SEP-14
  Backup Piece       21804  07-SEP-14          /databackup/fmis_arch_PROD_22931_857657475_1
deleted backup piece
backup piece handle=/databackup/bk_22917_857572554_1 recid=21789 stamp=857572555
deleted backup piece
backup piece handle=/databackup/bk_22918_857572579_1 recid=21790 stamp=857572584
deleted backup piece
backup piece handle=/databackup/bk_22919_857573044_1 recid=21791 stamp=857573051
deleted backup piece
backup piece handle=/databackup/bk_22920_857573095_1 recid=21792 stamp=857573101
deleted backup piece
backup piece handle=/databackup/al_22923_857584842_1 recid=21794 stamp=857584843
deleted backup piece
backup piece handle=/databackup/al_22922_857584817_1 recid=21795 stamp=857584818
deleted backup piece
backup piece handle=/databackup/al_22924_857584821_1 recid=21796 stamp=857584822
deleted backup piece
backup piece handle=/u01/prod/proddb/9.2.0/dbs/c-30397193-20140906-03 recid=21797 stamp=857584827
deleted backup piece
backup piece handle=/u01/prod/proddb/9.2.0/dbs/c-30397193-20140907-00 recid=21802 stamp=857657450
deleted backup piece
backup piece handle=/databackup/fmis_arch_PROD_22931_857657475_1 recid=21804 stamp=857657476
Deleted 10 objects

RMAN> **end-of-file**

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29762980/viewspace-1362004/,如需轉載,請註明出處,否則將追究法律責任。

相關文章