1. 程式人生 > >oracle11gRAC環境使用RMAN備份方案

oracle11gRAC環境使用RMAN備份方案

初始:
[[email protected] ~]$ rman target /


Recovery Manager: Release 11.2.0.1.0 - Production on Thu Oct 16 18:20:57 2014


Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


connected to target database: zx (DBID=2731354802)


RMAN> show all;


using target database control file instead of recovery catalog

RMAN configuration parameters for database with db_unique_name zx are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default

CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default

CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_zx1.f'; # default


開始設定備份策略
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
RMAN> CONFIGURE BACKUP OPTIMIZATION ON;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/rman/controlfile/%F';


修改後的
RMAN> show all;


RMAN configuration parameters for database with db_unique_name zx are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/rman/controlfile/%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_zx1.f'; # default


開啟塊跟蹤
[[email protected] ~]$ sqlplus / as sysdba
SQL> alter database enable block change tracking using file '+RCY1' ;
檢視
SQL> col filename for a50
SQL> select * from v$block_change_tracking;
STATUS     FILENAME                                         BYTES
---------- -------------------------------------------------- ----------
ENABLED    +RCY1/zx/changetracking/ctf.298.861133721        11599872




*****************************************************************************
增量備份
只備份從上次備份發生變化的塊。
1)增量備份首先做全備:
0,1,2,3,4,5
2)增量備份的好處是加快備份時間。
3)oracle增量備份有兩種:1.差異增量備份 2.累計增量備份
4)0級備份就是全被,做其他級別的備份前必須有0級,否則系統會做0級備份。
5)差異增量備份:backup incremental level 0 format
        只要等於或小於自己的級別,前面的備份就可以作為備份的起點。
日  一  二  三  四  五  六  日
0   2   2   1   2   2    2   0
全  一  一  三  一  一  一  全
週一週二只備份一天就行了,但週三需要把週一二三的都備一遍,因為它級別比前面的備份低,週四就只備一天就行了,週日又要做全備了。
比如週三早晨掛了,需要週日週一週二才能恢復到週三早晨,但如果週四早晨就只需要週日,週三就能恢復。週六掛需要週日,週三,週四,週五四個備份集。
6)累計增量備份:backup incremental level 0 cumulative format
只看備份級別比自己低的。
日  一  二  三  四  五  六  日
0   2   2   1   2   2   2   0
全  一  二  三  一  二  三  全
週日全備,週一備份一天的,週二備份2天的。週三備份週一二三的。
週四只備份一天的,週五備份兩天的,週六備份3天的。週日全備。
假如週三恢復,需要0級別和一個到週二 的備份就行了。恢復更快。
週六掛需要週日,週三,週五三個備份集。
*************************************************************************
zx資料庫使用差異增量備份
日  一  二  三  四  五  六  日
0   2   2   1   2   2   2   0
全  一  一  三  一  一  一  全
週日全備,週一週二只備份一天就行了,但週三需要把週一二三的都備一遍,因為它級別比前面的備份低,週四週五週六就只備一天就行了,週日又要做全備了。
編輯備份指令碼  
指令碼存放位置/home/oracle/scripts/rman/bin/    
日誌存放位置/home/oracle/scripts/rman/log/
備份存放位置+rcy1/backup/hrman_bak/


熱備0級指令碼
[[email protected] bin]$ cat hrman0.sh 
#!/bin/bash
export ORACLE_SID=zx1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export PATH=$ORACLE_HOME/bin
rman target / <<eof< span="" style="word-wrap: break-word;">
run{
sql'alter system switch logfile';
allocate channel c1 type disk;
allocate channel c2 type disk;
crosscheck archivelog all;
backup as compressed backupset incremental level 0 format '+rcy1/backup/hrman_bak/%d_%T_%U_0.bak' database plus archivelog;
delete noprompt obsolete;
}
quit;
EOF
熱備1級指令碼
[[email protected] bin]$ cat hrman1.sh 
#!/bin/bash
export ORACLE_SID=zx1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export PATH=$ORACLE_HOME/bin
rman target / <<eof< span="" style="word-wrap: break-word;">
run{
sql'alter system switch logfile';
allocate channel c1 type disk;
allocate channel c2 type disk;
crosscheck archivelog all;
backup as compressed backupset incremental level 1 format '+rcy1/backup/hrman_bak/%d_%T_%U_1.bak' database plus archivelog;
delete noprompt obsolete;
}
quit;
EOF


熱備2級指令碼
[[email protected] bin]$ cat hrman2.sh 
#!/bin/bash
export ORACLE_SID=zx1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export PATH=$ORACLE_HOME/bin
rman target / <<eof< span="" style="word-wrap: break-word;">
run{
sql'alter system switch logfile';
allocate channel c1 type disk;
allocate channel c2 type disk;
crosscheck archivelog all;
backup as compressed backupset incremental level 2 format '+rcy1/backup/hrman_bak/%d_%T_%U_2.bak' database plus archivelog;
delete noprompt obsolete;
}
quit;
EOF
設定許可權
[[email protected] bin]$ chmod -R 777 hrman0.sh
[[email protected] bin]$ chmod -R 777 hrman1.sh
[[email protected] bin]$ chmod -R 777 hrman2.sh
[[email protected] bin]$ ll
total 12
-rwxrwxrwx 1 oracle oinstall 468 Oct 21 17:03 hrman0.sh
-rwxrwxrwx 1 oracle oinstall 468 Oct 21 17:05 hrman1.sh
-rwxrwxrwx 1 oracle oinstall 468 Oct 21 17:06 hrman2.sh
配置作業
一個crontab檔案中包含有六個欄位: 
分鐘 0-59 
小時 0-23 
月中的第幾天 1-31 
月份 1 - 12 
星期幾 0 - 6, with 0 = Sunday 


配置
[[email protected] ~]$ crontab -e
檢視
[[email protected] ~]$ crontab -l
0 2 * * 0 sh /home/oracle/scripts/rman/bin/hrman0.sh  >> /home/oracle/scripts/rman/log/backup0.log 2>&1  
0 2 * * 3 sh /home/oracle/scripts/rman/bin/hrman1.sh  >>  /home/oracle/scripts/rman/log/backup1.log 2>&1 
0 2 * * 1,2,4,5,6 sh /home/oracle/scripts/rman/bin/hrman2.sh  >>  /home/oracle/scripts/rman/log/backup2.log 2>&1
日誌變大可清空
[[email protected] ~]$ cat /dev/null > /home/oracle/scripts/rman/log/backup0.log 
[[email protected] ~]$ cat /dev/null > /home/oracle/scripts/rman/log/backup1.log 
[[email protected] ~]$ cat /dev/null > /home/oracle/scripts/rman/log/backup2.log
[[email protected] ~]$ ll /home/oracle/scripts/rman/log
total 432
-rwxrwxrwx    1 oracle   dba               0 Jul 15 16:12 backup0.log
-rwxrwxrwx    1 oracle   dba               0 Jul 15 16:12 backup1.log
-rwxrwxrwx    1 oracle   dba               0 Jul 15 16:12 backup2.log
<eof< span="" style="word-wrap: break-word;"><eof< span="" style="word-wrap: break-word;"><eof< span="" style="word-wrap: break-word;">