溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ORACLE使用數(shù)據(jù)泵定時(shí)執(zhí)行備份與問題總結(jié)

發(fā)布時(shí)間:2020-07-24 17:54:30 來源:網(wǎng)絡(luò) 閱讀:17871 作者:secdata 欄目:數(shù)據(jù)庫

前言:隨著多個(gè)系統(tǒng)的逐步上線,作為運(yùn)維人員,數(shù)據(jù)庫備份顯得尤為重要,考慮到當(dāng)前系統(tǒng)資源有限,數(shù)據(jù)庫處于非歸檔模式,使用數(shù)據(jù)泵每天進(jìn)行全備,網(wǎng)上備份腳本很多,本人也是參考網(wǎng)上一些腳本分享并根據(jù)現(xiàn)有環(huán)境適當(dāng)修改。

原文參考鏈接:http://www.osyunwei.com/archives/5960.html

操作系統(tǒng)環(huán)境:AIX 7.1.0.0

數(shù)據(jù)庫版本:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

1.準(zhǔn)備工作

數(shù)據(jù)庫創(chuàng)建directory

CREATE [OR REPLACE] DIRECTORY res_productdump AS '/ogg/productbackup';

創(chuàng)建備份路徑/ogg/productbackup 修改所屬用戶和用戶組為oracle.oinstall

2.備份腳本

首先確認(rèn)本機(jī)shell類型:

$echo $SHELL

/usr/bin/ksh

腳本內(nèi)容,以省份浙江為例:

cat res_zhejiang_bk.sh

######################################################################################

#!/usr/bin/ksh

export ORACLE_BASE=/app/oracle   

export ORACLE_SID=resdb1

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1

export ORACLE_TERM=xterm

export PATH=$PATH:$ORACLE_HOME/bin

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

#以上代碼為oracle用戶的系統(tǒng)環(huán)境變量設(shè)置

#獲取系統(tǒng)當(dāng)前日期時(shí)間

export BAKUPTIME=`date +%Y%m%d%H%M`

#設(shè)置刪除7天之前的備份文件

export DELETE_DAYS=7

#指定directory路徑

export BAK_DIR=/ogg/productbackup 

#備份省份用戶

export BAK_USER=res_zhejiang

#指定directory名字

export DIRECTORE_NAME=res_productdump

# 執(zhí)行浙江存量備份

expdp system/systemres directory=${DIRECTORE_NAME} schemas=${BAK_USER} dumpfile=${BAK_USER}_%U_${BAKUPTIME}.dmp logfile=${BAK_USER}_${BAKUPTIME}.log parallel=4 cluster=no

#壓縮備份文件和日志文件

zip -r ${BAK_DIR}/${BAK_USER}_${BAKUPTIME}.dmp.zip ${BAK_DIR}/${BAK_USER}_*.dmp ${BAK_DIR}/${BAK_USER}_*.log

#備份完成之后,刪除當(dāng)天備份文件和日志文件

find ${BAK_DIR}/*  -type f -name "${BAK_USER}*.dmp" -exec rm {} \;    #刪除備份文件

find ${BAK_DIR}/*  -type f -name "${BAK_USER}*.log" -exec rm {} \;    #刪除日志文件

#刪除7天前的備份文件

find ${BAK_DIR}/* -type f -name "${BAK_USER}*.zip" -mtime +${DELETE_DAYS} -exec rm -rf {} \;

######################################################################################

3.腳本賦予執(zhí)行權(quán)限

$chmod a+x res_zhejiang_bk.sh

4.添加執(zhí)行計(jì)劃

打開執(zhí)行計(jì)劃

crontab -e

crontab: you are not authorized to use cron.  Sorry.

處理:

root用戶操作,添加oracle

vi /var/adm/cron/cron.allow   

root

unionmon

oracle

使用crontab -e指定執(zhí)行計(jì)劃

00 00 * * * /home/oracle/scripts/res_zhejiang_bk.sh

#查看執(zhí)行計(jì)劃

crontab -l

5.驗(yàn)證備份,查看備份日志

驗(yàn)證過程中若定時(shí)任務(wù)未執(zhí)行,查看郵件提示信息:

郵件查看:more /usr/spool/mail/oracle

補(bǔ)充1:對(duì)于AIX系統(tǒng)而言,默認(rèn)是沒有unzip解壓命令的,如下處理

首先下載unzip解壓縮包,個(gè)人網(wǎng)盤鏈接:http://pan.baidu.com/s/1qXEDtQO

或者官網(wǎng)FTP下載地址:ftp://ftp.software.ibm.com/aix/freeSoftware/aixtoolbox/RPMS/ppc/unzip/

然后將/app/soft/路徑下的unzip包拷貝到/usr/bin路徑下,并賦權(quán)限,如下:

# cp /app/soft/unzip /usr/bin  

# chmod 755 /usr/bin/unzip

# chown -R grid:oinstall /app/soft/

這樣AIX系統(tǒng)unzip解壓命令就可以正常使用了

補(bǔ)充2:unzip常使用的幾個(gè)命令小計(jì)

-j參數(shù):不處理壓縮文件中原有的目錄路徑

-d參數(shù):指定解壓縮路徑

-t參數(shù):檢查壓縮文件是否正確

-v參數(shù):執(zhí)行是時(shí)顯示詳細(xì)的信息

-o參數(shù):不必先詢問用戶,unzip執(zhí)行后覆蓋原有文件

-l參數(shù):顯示壓縮文件內(nèi)所包含的文件

-x參數(shù):指定不要處理.zip壓縮文件中的哪些文件

示例如下:

$unzip -j res_zhejiang_201612080000.dmp.zip -d /ogg/dumpfile  --如果不指定-j參數(shù),會(huì)將原有備份路徑一起解壓

$unzip -t res_zhejiang_201612080000.dmp.zip

Archive:  res_zhejiang_201612080000.dmp.zip

    testing: ogg/productbackup/res_zhejiang_01_201612080000.dmp   OK

    testing: ogg/productbackup/res_zhejiang_02_201612080000.dmp   OK

    testing: ogg/productbackup/res_zhejiang_03_201612080000.dmp   OK

    testing: ogg/productbackup/res_zhejiang_04_201612080000.dmp   OK

    testing: ogg/productbackup/res_zhejiang_201612080000.log   OK

No errors detected in compressed data of res_zhejiang_201612080000.dmp.zip

$unzip -j res_zhejiang_201612080000.dmp.zip -x *.dmp -d /ogg/dumpfile   --只解壓log日志文件

補(bǔ)充3.1:AIX7.1系統(tǒng)上數(shù)據(jù)庫dmp備份.zip壓縮文件大于2G處理辦法

示例如下:

$du -sg res_jiangsu_201612080115.dmp.zip

4.89    res_jiangsu_201612080115.dmp.zip

$unzip -l res_jiangsu_201612080115.dmp.zip

unzip:  can't find res_jiangsu_201612080115.dmp.zip, res_jiangsu_201612080115.dmp.zip.zip or res_jiangsu_201612080115.dmp.zip.ZIP, so there.

原因是這個(gè)unzip是32位版本。解決方法如下:

到IBM網(wǎng)站下載bzip2

http://www-03.ibm.com/systems/power/software/aix/linux/toolbox/date.html

當(dāng)前可用的是bzip2-1.0.6-2.aix6.1.ppc.rpm

到PERZL網(wǎng)站下載64位unzip

http://www.perzl.org/aix/index.php?n=Main.Unzip

當(dāng)前可用的是unzip-64bit-6.0-3.aix5.1.ppc.rpm

上傳上面的兩個(gè)包到AIX7.1服務(wù)器,安裝后問題解決。

# rpm -ivh bzip2-1.0.6-2.aix6.1.ppc.rpm

bzip2                       ##################################################

# rpm -ivh unzip-64bit-6.0-3.aix5.1.ppc.rpm

unzip-64bit                 ##################################################

$unzip -l res_jiangsu_201612080115.dmp.zip

Archive:  res_jiangsu_201612080115.dmp.zip

  Length      Date    Time    Name

---------  ---------- -----   ----

4905238528  12-08-2016 01:21   ogg/productbackup/res_jiangsu_01_201612080115.dmp

11686117376  12-08-2016 01:21   ogg/productbackup/res_jiangsu_02_201612080115.dmp

21065035776  12-08-2016 01:21   ogg/productbackup/res_jiangsu_03_201612080115.dmp

10216099840  12-08-2016 01:21   ogg/productbackup/res_jiangsu_04_201612080115.dmp

   140789  12-08-2016 01:21   ogg/productbackup/res_jiangsu_201612080115.log

---------                     -------

47872632309                     5 files

補(bǔ)充3.2:AIX7.1系統(tǒng)上使用unzip命令解壓縮文件中單個(gè)文件大于2G的情況

如果unzip解壓縮的文件中單個(gè)文件大于2G解壓時(shí)會(huì)報(bào)錯(cuò),即使強(qiáng)制解壓,文件也是不完整的,示例如下:

$unzip -t res_shanghai_201612110045.dmp.zip   --備份文件檢查

Archive:  res_shanghai_201612110045.dmp.zip

    testing: oracle/productbackup/res_shanghai_01_201612110045.dmp   OK

    testing: oracle/productbackup/res_shanghai_02_201612110045.dmp   OK

    testing: oracle/productbackup/res_shanghai_03_201612110045.dmp   OK

    testing: oracle/productbackup/res_shanghai_04_201612110045.dmp   OK

    testing: oracle/productbackup/res_shanghai_201612110045.log   OK

No errors detected in compressed data of res_shanghai_201612110045.dmp.zip.

$unzip -j res_shanghai_201612110045.dmp.zip -d /oracle/productbackup/  --解壓縮

Archive:  res_shanghai_201612110045.dmp.zip

  inflating: /oracle/productbackup/res_shanghai_01_201612110045.dmp  

/oracle/productbackup/res_shanghai_01_201612110045.dmp:  write error (disk full?).  Continue? (y/n/^C) 

$du -sg res_shanghai_01_201612110045.dmp   --查看已經(jīng)解壓出來的dmp文件已經(jīng)為2G

2.00    res_shanghai_01_201612110045.dmp

如示補(bǔ)充3.1的方法解決,安裝所需的兩個(gè)軟件包。

$du -sg res_shanghai*.dmp

2.85    res_shanghai_01_201612110045.dmp

2.50    res_shanghai_02_201612110045.dmp

0.76    res_shanghai_03_201612110045.dmp

0.02    res_shanghai_04_201612110045.dmp

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI