Linux 平臺下 RMAN 全備 和 增量備份 shell 指令碼
原文地址:http://blog.csdn/tianlesoftware/article/details/5740630
全備指令碼
以 nocatalog 模式為例:
Shell 指令碼:
########################################################################
## hot_database_backup.sh ##
## created by Tianlesoftware ##
## 2010-7-16 ##
#########################################################################
#!/bin/sh
# ---------------------------------------------------------------------------
# Determine the user which is executing this script.
# ---------------------------------------------------------------------------
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
# ---------------------------------------------------------------------------
# Put output in <this file name>.out. Change as desired.
# Note: output directory requires write permission.
# ---------------------------------------------------------------------------
RMAN_LOG_FILE=${0}.out
# ---------------------------------------------------------------------------
# You may want to delete the output file so that backup information does
# not accumulate. If not, delete the following lines.
# ---------------------------------------------------------------------------
if [ -f "$RMAN_LOG_FILE" ]
then
rm -f "$RMAN_LOG_FILE"
fi
# -----------------------------------------------------------------
# Initialize the log file.
# -----------------------------------------------------------------
echo >> $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Log the start of this script.
# ---------------------------------------------------------------------------
echo Script $0 >> $RMAN_LOG_FILE
echo ==== started on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# home path.
# ---------------------------------------------------------------------------
ORACLE_HOME=/u01/app//product/10.2.0/db_1
export ORACLE_HOME
# ---------------------------------------------------------------------------
# the Oracle SID of the target database.
# ---------------------------------------------------------------------------
ORACLE_SID=orcl
export ORACLE_SID
# ---------------------------------------------------------------------------
# The Oracle DBA user id (account).
# ---------------------------------------------------------------------------
ORACLE_USER=oracle
export ORACLE_USER
# ---------------------------------------------------------------------------
# Set the Oracle Recovery Manager name.
# ---------------------------------------------------------------------------
RMAN=$ORACLE_HOME/bin/rman
# ---------------------------------------------------------------------------
# Print out the value of the variables set by this script.
# ---------------------------------------------------------------------------
echo >> $RMAN_LOG_FILE
echo "RMAN: $RMAN" >> $RMAN_LOG_FILE
echo "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE
echo "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE
echo "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Print out the value of the variables set by bphdb.
# ---------------------------------------------------------------------------
#echo >> $RMAN_LOG_FILE
#echo "NB_ORA_FULL: $NB_ORA_FULL" >> $RMAN_LOG_FILE
#echo "NB_ORA_INCR: $NB_ORA_INCR" >> $RMAN_LOG_FILE
#echo "NB_ORA_CINC: $NB_ORA_CINC" >> $RMAN_LOG_FILE
#echo "NB_ORA_SERV: $NB_ORA_SERV" >> $RMAN_LOG_FILE
#echo "NB_ORA_POLICY: $NB_ORA_POLICY" >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# NOTE: This script assumes that the database is properly opened. If desired,
# this would be the place to verify that.
# ---------------------------------------------------------------------------
echo >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Call Recovery Manager to initiate the backup.
# ---------------------------------------------------------------------------
CMD_STR="
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN nocatalog target sys/admin msglog $RMAN_LOG_FILE append << EOF
RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;
BACKUP FORMAT '/u01/backup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE TAG orcl_hot_db_bk;
sql 'alter system archive log current';
BACKUP FORMAT '/u01/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;
backup current controlfile tag='bak_ctlfile' format='/u01/backup/ctl_file_%U_%T';
backup spfile tag='spfile' format='/u01/backup/ORCL_spfile_%U_%T';
release channel c2;
release channel c1;
}
report obsolete;
delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
list backup summary;
#EOF
"
# Initiate the command string
if [ "$CUSER" = "root" ]
then
echo "Root Command String: $CMD_STR" >> $RMAN_LOG_FILE
su - $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE
RSTAT=$?
else
echo "User Command String: $CMD_STR" >> $RMAN_LOG_FILE
/bin/sh -c "$CMD_STR" >> $RMAN_LOG_FILE
RSTAT=$?
fi
# ---------------------------------------------------------------------------
# Log the completion of this script.
# ---------------------------------------------------------------------------
if [ "$RSTAT" = "0" ]
then
LOGMSG="ended successfully"
else
LOGMSG="ended in error"
fi
echo >> $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
/bin/mailx -s "RMAN Backup SID " daimm@sf-express.com < $RMAN_LOG_FILE
exit $RSTAT
三. 增量備份
以catalog模式為例:
在存放catalog的例項上建立catalog 目錄:
1.建立Catalog所需要的表空間
SQL>create tablespace catalog_ts datafile 'D:/APP/ADMINISTRATOR/ORADATA/ORCL/catalog_ts1.dbf' size 20M;
2.建立RMAN使用者並授權
SQL>create user catalog identified by catalog default tablespace catalog_ts;
SQL>grant recovery_catalog_owner to catalog;
檢視角色所擁有的許可權:
select * from dba_sys_privs where grantee='RECOVERY_CATALOG_OWNER';
3.建立恢復目錄
[oracle@db1 scripts]$ rman target / catalog catalog/catalog@catalog1;
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Jul 15 12:03:16 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1248423599)
connected to recovery catalog database
RMAN> create catalog tablespace catalog_ts;
recovery catalog created
如果此處報錯:
ORACLE error from recovery catalog database: ORA-00955: name is already used by an existing object
可以用命令刪除catalog,在建立:
RMAN> drop catalog;
recovery catalog owner is CATALOG
enter DROP CATALOG command again to confirm catalog removal
RMAN> drop catalog
recovery catalog dropped
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
RMAN>
差異備份有3個級別:
0級:相當於全備,不同的是0級可用於增量備份,全備不行。
1級:備份自上次0級備份以來的資料
2級:備份自上次備份依賴的資料
指令碼的增量備份策略: 週日0級備份,週四1級備份,其他2級備份
Shell 指令碼:
########################################################################
## incremental_hot_database_backup.sh ##
## created by Tianlesoftware ##
## 2010-7-16 ##
#########################################################################
#!/bin/ksh
export LANG=en_US
BACKUP_DATE=`date +%d`
RMAN_LOG_FILE=${0}.out
TODAY=`date`
USER=`id|cut -d "(" -f2|cut -d ")" -f1`
echo "-----------------$TODAY-------------------">$RMAN_LOG_FILE
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_HOME
RMAN=$ORACLE_HOME/bin/rman
export RMAN
ORACLE_SID=orcl
export ORACLE_SID
ORACLE_USER=oracle
export ORACLE_USER
echo "ORACLE_SID: $ORACLE_SID">>$RMAN_LOG_FILE
echo "ORACLE_HOME:$ORACLE_HOME">>$RMAN_LOG_FILE
echo "ORACLE_USER:$ORACLE_USER">>$RMAN_LOG_FILE
echo "==========================================">>$RMAN_LOG_FILE
echo "BACKUP DATABASE BEGIN......">>$RMAN_LOG_FILE
echo " ">>$RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
WEEK_DAILY=`date +%a`
case "$WEEK_DAILY" in
"Mon")
BAK_LEVEL=2
;;
"Tue")
BAK_LEVEL=2
;;
"Wed")
BAK_LEVEL=2
;;
"Thu")
BAK_LEVEL=1
;;
"Fri")
BAK_LEVEL=2
;;
"Sat")
BAK_LEVEL=2
;;
"Sun")
BAK_LEVEL=0
;;
"*")
BAK_LEVEL=error
esac
export BAK_LEVEL=$BAK_LEVEL
echo "Today is : $WEEK_DAILY incremental level= $BAK_LEVEL">>$RMAN_LOG_FILE
RUN_STR="
BAK_LEVEL=$BAK_LEVEL
export BAK_LEVEL
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN TARGET sys/admin CATALOG catalog/catalog@catalog1 msglog $RMAN_LOG_FILE append <<EOF
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level= $BAK_LEVEL skip inaccessible filesperset 5 Database format='/u01/backup/orcl_lev"$BAK_LEVEL"_%U_%T' tag='orcl_lev"$BAK_LEVEL"' ;
sql 'alter system archive log current';
backup archivelog all tag='arc_bak' format='/u01/backup/arch_%U_%T' skip inaccessible filesperset 5 not backed up 1 times delete input;
backup current controlfile tag='bak_ctlfile' format='/u01/backup/ctl_file_%U_%T';
backup spfile tag='spfile' format='/u01/backup/ORCL_spfile_%U_%T';
release channel c2;
release channel c1;
}
report obsolete;
delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
list backup summary;
resync catalog;
EOF
"
# Initiate the command string
if [ "$CUSER" = "root" ]
then
echo "Root Command String: $RUN_STR" >> $RMAN_LOG_FILE
su - $ORACLE_USER -c "$RUN_STR" >> $RMAN_LOG_FILE
RSTAT=$?
else
echo "User Command String: $RUN_STR" >> $RMAN_LOG_FILE
/bin/sh -c "$RUN_STR" >> $RMAN_LOG_FILE
RSTAT=$?
fi
# ---------------------------------------------------------------------------
# Log the completion of this script.
# ---------------------------------------------------------------------------
if [ "$RSTAT" = "0" ]
then
LOGMSG="ended successfully"
else
LOGMSG="ended in error"
fi
echo >> $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
/bin/mailx -s "RMAN Backup SID " daimm@sf-express.com < $RMAN_LOG_FILE
exit $RSTAT
將該備份指令碼新增到crontab, 然後定時執行:
[oracle@db1 u01]$ crontab -l
00 1 * * * /u01/scripts/incremental_hotbackup.sh
Unix crontab 命令詳解
http://blog.csdn.net/tianlesoftware/archive/2010/02/22/5315039.aspx
在的時候,我們可以手工的修改,然後檢視指令碼的執行情況即可:
[root@db1 ~]# date --set "2010-7-16 11:11:11"
------------------------------2010年8月23日補充--------------------------
用這個指令碼的時候發現一個問題,備份集可以透過設定儲存粗略定期刪除,但是備份的歸檔檔案無法刪除。
所以還需要定期的刪除備份的歸檔檔案。 一般儲存15天。 shell 指令碼如下。新增到crontab 裡定時執行就可以了。
del_archive_backup.sh
#!/bin/ksh
# ##################################################################
#
# delete archvivelog backup file.sh
# tianlesoftware
#
# ##################################################################
PATH=/usr/bin:/usr/ucb:/etc:.:/usr/X/bin:/bin
export PATH
find /u01/incremental_hotbackup -mtime +15 -name "arch_*" -exec rm {} /;
說明,這裡的路徑寫你自己的就可以了。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28869493/viewspace-2144289/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- rman備份和增量備份指令碼指令碼
- Nocatalog 下的RMAN 增量備份 shell指令碼指令碼
- linux 下RMAN備份shell指令碼Linux指令碼
- rman增量備份指令碼指令碼
- mysqldump 全量和增量備份指令碼MySql指令碼
- rman 全備份指令碼指令碼
- linux下rman增量備份指令碼以及指令碼自動執行Linux指令碼
- Rman備份的shell指令碼指令碼
- RMAN全庫備份指令碼指令碼
- Linux 平臺下 Oracle 資料泵備份(expdp) SHELL 指令碼LinuxOracle指令碼
- rman備份的shell指令碼(例子)指令碼
- windows 全量+增量備份指令碼batWindows指令碼BAT
- RMAN定時全備份指令碼指令碼
- 【RMAN】RMAN備份恢復3 RMAN增量備份指令碼與crontab計劃任務指令碼
- Windows下RMAN備份指令碼Windows指令碼
- 一個較完整的RMAN增量備份指令碼指令碼
- [Rman]Oracle Rman增量備份Level012指令碼Oracle指令碼
- WINDOWS下 部署 rman 全備指令碼Windows指令碼
- windows和unix平臺下Oracle冷備份指令碼WindowsOracle指令碼
- rman 備份指令碼指令碼
- rman備份指令碼指令碼
- Oracle RMAN 增量備份Oracle
- RAC模式下的備份策略以及RMAN備份指令碼模式指令碼
- windows下rman自動備份指令碼Windows指令碼
- windows rman備份指令碼Windows指令碼
- RMAN常用備份指令碼指令碼
- oracle RMAN備份指令碼Oracle指令碼
- RAC模式下的備份策略以及RMAN備份指令碼(轉)模式指令碼
- RAC模式下的備份策略以及RMAN備份指令碼(ZF)模式指令碼
- RMAN說,我能備份(9)--RMAN增量備份與備份保留策略
- Oracle 11g RMAN備份-增量備份Oracle
- MySQL增量備份的指令碼(innobackupex)MySql指令碼
- linux基於cron的rman自動增量備份指令碼及設定Linux指令碼
- rman的全備份指令碼和控制檔案安全策略指令碼
- 關於WINDOWS平臺下RMAN備份移植Windows
- 【RMAN】RMAN指令碼中使用替換變數--windows 下rman全備指令碼指令碼變數Windows
- linux下rsync和tar增量備份梳理Linux
- RMAN說,我能備份(3)--RMAN全庫備份和表空間備份