写LINUX脚本 备份ORACLE用户下的表 保留30天数据
写如下代码back.sh
#取得当天日期
RUNDATE
=
`
date
+
%Y%m%d`
#放入指定文件夹
SNDDIR =/ usr / local / webapps / bak
SNDDIR =/ usr / local / webapps / bak
#逻辑备份
expuserid = user /user owner =user file =$ SNDDIR / backup .$ RUNDATE . dmp
#压缩文件
expuserid = user /user owner =user file =$ SNDDIR / backup .$ RUNDATE . dmp
#压缩文件
gzip-f
$
SNDDIR
/
backup
.$
RUNDATE
.
dmp
#删除30天后文件###
find $ SNDDIR / backup . * . dmp . gz-atime + 29 -execrm-f{} ;
find $ SNDDIR / backup . * . dmp . gz-atime + 29 -execrm-f{} ;
按照如下代码写一个cron_bak脚本
TERM
=
vt220
;
exportTERM
EDITOR = vi ; exportEDITOR
TEMP =/ tmp ; exportTEMP
TMPDIR =/ tmp ; exportTMPDIR
### SETUPORACLEENVIRONMENT ###
ORACLE_SID = ora10 ; exportORACLE_SID
ORACLE_BASE =/ home / oracle ; exportORACLE_BASE
ORACLE_HOME =/ home / oracle / product / 10.1 . 0 ; exportORACLE_HOME
ORACLE_TERM = ansi ; exportORACLE_TERM
JAVA_FONTS =/ usr / share / fonts / zh_CN / TrueType /; exportJAVA_FONTS
NLS_LANG = AMERICAN_AMERICA . ZHS16GBK ; exportNLS_LANG
LD_LIBRARY_PATH =$ ORACLE_HOME / lib: / lib: / usr / lib
LD_LIBRARY_PATH =$ LD_LIBRARY_PATH: / usr / local / lib
exportLD_LIBRARY_PATH
PATH =. : / usr / local / ant / bin: $ ORACLE_HOME / bin: / usr / local / mysql / bin: $ PATH
export PATH
### FOR ORACLEINSTALL ###
# exportLC_ALL = " en_US "
# exportLC = " en_US "
### TOMCAT ###
CATALINA_HOME =/ usr / local / tomcat5 ; exportCATALINA_HOME
CATALINA_BASE =/ usr / local / tomcat5 ; exportCATALINA_BASE
suweb-c " /usr/local/webapps/bak/back.sh "
EDITOR = vi ; exportEDITOR
TEMP =/ tmp ; exportTEMP
TMPDIR =/ tmp ; exportTMPDIR
### SETUPORACLEENVIRONMENT ###
ORACLE_SID = ora10 ; exportORACLE_SID
ORACLE_BASE =/ home / oracle ; exportORACLE_BASE
ORACLE_HOME =/ home / oracle / product / 10.1 . 0 ; exportORACLE_HOME
ORACLE_TERM = ansi ; exportORACLE_TERM
JAVA_FONTS =/ usr / share / fonts / zh_CN / TrueType /; exportJAVA_FONTS
NLS_LANG = AMERICAN_AMERICA . ZHS16GBK ; exportNLS_LANG
LD_LIBRARY_PATH =$ ORACLE_HOME / lib: / lib: / usr / lib
LD_LIBRARY_PATH =$ LD_LIBRARY_PATH: / usr / local / lib
exportLD_LIBRARY_PATH
PATH =. : / usr / local / ant / bin: $ ORACLE_HOME / bin: / usr / local / mysql / bin: $ PATH
export PATH
### FOR ORACLEINSTALL ###
# exportLC_ALL = " en_US "
# exportLC = " en_US "
### TOMCAT ###
CATALINA_HOME =/ usr / local / tomcat5 ; exportCATALINA_HOME
CATALINA_BASE =/ usr / local / tomcat5 ; exportCATALINA_BASE
suweb-c " /usr/local/webapps/bak/back.sh "
在切换到ROOT用户下 CRONTAB -E 编辑特定时间运行脚本
任意一天的凌晨3.01分运行下面的脚本
1
3
***
/
usr
/
local
/
webapps
/
bak
/
cron_bak
>
/
usr
/
local
/
webapps
/
bak
/
baklog
.
log