Logicalbackup.sh
#!/bin/ksh
# ##################################################################
#
# created by tianlesoftware
# 2010-7-7
# Email: tianlesoftware@vip.qq.com
# ##################################################################
# Oracle Environment settings
PATH=/usr/bin:/usr/ucb:/etc:.:/usr/X/bin:/bin
export PATH
ORACLE_SID=SID; pw=oracle ; export pw ; export ORACLE_SID
ORACLE_BASE=/dba/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data ; export ORA_NLS33
TNS_ADMIN=$ORACLE_HOME/network/admin ; export TNS_ADMIN
LD_LIBRARY_PATH=$ORACLE_HOME/lib ; export LD_LIBRARY_PATH
PATH=$ORACLE_HOME/bin:/usr/local/bin:/usr/ccs/bin:$PATH:/usr/sbin
export PATH
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/product/jlib ; export CLASSPATH
backup_dir=/u03/oradata/dump_backup_dir
#数据泵需要directory,这里指定自己的目录就可以了
#SQL>CREATE DIRECTORY backup as ‘/u03/oradata/dump_backup_dir’;
#SQL>grant read,write on directory backup to SYSTEM;
DMP_FILE=SID_`date +%d%m%Y_%H%M%S`.dmp
LOG_FILE=SID_`date +%d%m%Y_%H%M%S`.log
#
# Let's start with an export of the database
#
expdp user/pwd DIRECTORY=dump_backup_dir DUMPFILE=$DMP_FILE TABLESPACES=TS_NAMEE logfile=$LOG_FILE parallel=3;
# 这里的2个说明,用户名和密码换成自己的,我这里是备份表空间。
# parallel 这个参数是控制并行度的,默认是1,但对于数据库比较大的时候,可以设置parallel,这样可以较少备份的
#时间,但是设置并行会耗CPU 资源,如果CPU 资源比较紧张的话,就不要设了。
#
# Just to be safe (with space), we'll compress the export file
# 压缩dmp 文件,较少对空间的占用
#
cd $backup_dir
compress *.dmp
#
# Let's delete the backups and logs that are more than 1 days old
# 删除超过一天的dmp文件
#
find $backup_dir -name "*.dmp" -mtime +1 -exec rm {} \;
# That's all