一个简单的逻辑备份策略学习
需求:
每天19:00备份一次业务用户
每个备份最多保留7天
每个备份用日期作为备份文件的名称
[root@localhost opt]# cat /home/autoBackup/ora_env
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/10.2.0
export ORACLE_SID=STAPLES
export ORACLE_TERM=xterm
#export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export PATH=$PATH:$ORACLE_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/jlib
export JAVA_HOME=$ORACLE_HOME/jdk
export ORA_NLS10=$ORACLE_HOME/nls/data
export LC_CTYPE=en_US.UTF-8
[root@localhost opt]# cat /opt/backup_exp.sh
#!/bin/sh
#CREATOR:daimin
#function:backup database with expdp
#usage:crontab on linux
#last modify:tuolei 2007-08-29 create
#set environment variable
. /home/autoBackup/ora_env #设置exp的环境变量
#开始备份,假定目录backupPath已经创建,并且backupPath=/opt/oracle/backup
backupPath='/opt/oracle/backup/'
FILE=`date +%Y%m%d`'.dmp'
LOGFILE=`date +%Y%m%d`'.log'
exp daimin/daimin@STAPLES file=$backupPath$FILE.dmp log=$backupPath$LOGFILE
#删除以前过期的备份
find /opt/oracle/backup/* -name "*.dmp" -mtime +4 -exec rm {} /;
[root@localhost etc]# crontab -e
0 19 * * * /opt/backup_exp.sh > /opt/oracle/backup/logs/backup_exp.log 2>&1
~
"crontab.XXXXmfkudb" 1L, 76C written
crontab: installing new crontab
[root@localhost etc]# crontab -l
0 19 * * * /opt/backup_exp.sh > /opt/oracle/backup/logs/backup_exp.log 2>&1
注意:
1、/opt/backup_exp.sh需要具有可执行权限,才可以被root用户执行
[root@localhost backup]# chmod +x /opt/backup_exp.sh
否则会出现/bin/sh: /opt/backup_exp.sh: Permission denied错误
2、需要在脚本的第一行加#!/bin/sh
否则会出现/bin/sh: /opt/backup_exp.sh: cannot execute binary file错误
3、注意在执行exp命令之前,需要设置环境变量,所以在逻辑备份脚本中执行了. /home/autoBackup/ora_env 命令;
参考网页:
http://blog.csdn.net/wzy0623/archive/2008/10/31/3193150.aspx
http://www.linuxsir.org/main/?q=node/209
需求:
每天19:00备份一次业务用户
每个备份最多保留7天
每个备份用日期作为备份文件的名称
[root@localhost opt]# cat /home/autoBackup/ora_env
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/10.2.0
export ORACLE_SID=STAPLES
export ORACLE_TERM=xterm
#export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export PATH=$PATH:$ORACLE_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/jlib
export JAVA_HOME=$ORACLE_HOME/jdk
export ORA_NLS10=$ORACLE_HOME/nls/data
export LC_CTYPE=en_US.UTF-8
[root@localhost opt]# cat /opt/backup_exp.sh
#!/bin/sh
#CREATOR:daimin
#function:backup database with expdp
#usage:crontab on linux
#last modify:tuolei 2007-08-29 create
#set environment variable
. /home/autoBackup/ora_env #设置exp的环境变量
#开始备份,假定目录backupPath已经创建,并且backupPath=/opt/oracle/backup
backupPath='/opt/oracle/backup/'
FILE=`date +%Y%m%d`'.dmp'
LOGFILE=`date +%Y%m%d`'.log'
exp daimin/daimin@STAPLES file=$backupPath$FILE.dmp log=$backupPath$LOGFILE
#删除以前过期的备份
find /opt/oracle/backup/* -name "*.dmp" -mtime +4 -exec rm {} /;
[root@localhost etc]# crontab -e
0 19 * * * /opt/backup_exp.sh > /opt/oracle/backup/logs/backup_exp.log 2>&1
~
"crontab.XXXXmfkudb" 1L, 76C written
crontab: installing new crontab
[root@localhost etc]# crontab -l
0 19 * * * /opt/backup_exp.sh > /opt/oracle/backup/logs/backup_exp.log 2>&1
注意:
1、/opt/backup_exp.sh需要具有可执行权限,才可以被root用户执行
[root@localhost backup]# chmod +x /opt/backup_exp.sh
否则会出现/bin/sh: /opt/backup_exp.sh: Permission denied错误
2、需要在脚本的第一行加#!/bin/sh
否则会出现/bin/sh: /opt/backup_exp.sh: cannot execute binary file错误
3、注意在执行exp命令之前,需要设置环境变量,所以在逻辑备份脚本中执行了. /home/autoBackup/ora_env 命令;
参考网页:
http://blog.csdn.net/wzy0623/archive/2008/10/31/3193150.aspx
http://www.linuxsir.org/main/?q=node/209