DDL语句的备份脚本

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:29

!/bin/sh
#
# 2013-04-09 14:29
# Copyright (c) 2013 C.X All rights reserved.
#
set -x

###################################
#
# usage: BAKDDL
#
###################################

[ -f $HOME/.bash_profile ] && . $HOME/.bash_profile
[ -f $HOME/.profile ] && . $HOME/.profile
wdir=/u01/app/oracle/dba_scripts
dtime=`date +'%Y%m%d'`
day=`date +'%Y%m%d'`
hour=`date +'%Y%m%d%H'`
[ -d ${wdir}/spool ] || mkdir -p ${wdir}/spool
[ -d ${wdir}/conf ] || mkdir -p ${wdir}/conf
BakPath=/backup/ddl/28
BakFile=${BakPath}/${day}
conffile=${wdir}/conf/Backup_DDL.local.${dtime}.sql
spoolfile=${wdir}/spool/local.Backup_DDL.${dtime}.sql
SQLPLUS_CMD="$ORACLE_HOME/bin/sqlplus / as sysdba @${conffile}"

cat << EOF >${conffile}
set verify off feedback off
set wrap on
set head on
set trimspool on
set linesize 200
set long 1000000
set longchunksize 1000000
SET linesize 161;
set pages 0;

spool ${spoolfile}
select username from dba_users where account_status = 'OPEN' and username not like '%SYS%';
spool off
quit;
EOF

${SQLPLUS_CMD}

for username in `cat ${spoolfile}`
do
${wdir}/SCHDDL ${username}
done

tar -cvf ${BakFile}.tar ${BakPath}/*${day}*
gzip ${BakFile}.tar
if [ ! -z ${BakFile}.tar.gz ]; then
rm -f ${BakPath}/*${day}.sql
fi

本文标签:
本文标题:DDL语句的备份脚本
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】