经过大家的帮助,终于写好了这个自动备份数据文件的脚本,脚本特点是自动备份一个数据库中的数据文件,不需要知道数据库有些什么表空间,或者数据文件,脚本编写的还很不美观,先用着,慢慢美化吧,另外archive备份部分也暂时没有备,仓促编程,有什么问题请指正!
注意本脚本是应用于archive log模式下的,另外数据库的用户名密码,自己在脚本里改一下,脚本是带参数的,参数是备份的目标目录,注意要有写权限。#!/bin/sh
mypath=$1
if [ -z $mypath ] ; then
echo 'Please Use This Command Like ./backup /u01/backup'
else
if [ -d $mypath ] ; then
ORACLE_SID=dzzd; export ORACLE_SID
ORAENV_ASK=NO; export ORAENV_ASK
rm -Rf aa.txt
sqlplus -s "system/oracle9i"<
set head off
set feedback off
spool aa.txt
select tablespace_name from dba_tablespaces;
spool off
EXIT
EOF
for spacename in `cat aa.txt`
do
echo $spacename |grep "^TEMP"
if [ "$?" -eq "0" ]
then
echo TEMP no need backup else
else
echo begin backup $spacename
sqlplus -s system/oracle9i< alter tablespace $spacename begin backup;
EXIT
SETSTA
rm -Rf bb.txt
sqlplus -s system/oracle9i< set head off
set feedback off
spool bb.txt
SELECT 'cp '||file_name||' $mypath'||SUBSTR(FILE_NAME,INSTR(FILE_NAME,'/',-1,1))
FROM dba_data_files where tablespace_name=trim('$spacename');
spool off
EXIT
DATAFILE1
sh bb.txt
sqlplus -s system/oracle9i< alter tablespace $spacename end backup;
EXIT
SETSTA
echo end backup $spacename
fi
done
else
echo "Please Input a Right Direction"
fi
fi
【责编:admin】
--------------------next---------------------
阅读(548) | 评论(0) | 转发(0) |