此脚本只使用与文件系统上面的数据库,只是简单的脚本,不适合带库上的oracle,那个需要小小的改动。
#!/bin/bash
source ~/.bash_profile
export NLS_LANG=AMERICAN_AMERICA.UTF8
#定义时间
TIME=`date +%Y-%m-%d[%R]`
#清空SQL语句
>/tmp/hotbak.sql
#热备目录
dir =/tmp/hotback
#备份目录
dir_bak = /tmp/hot
#登陆sqlplus
sqlplus -S /nolog<>rizhi.log
connect / as sysdba;
set heading off
set verify off
set trimspool off
set pagesize 0
set linesize 200
spool /tmp/hotbak.sql
select ' cp ' ||name|| ' /tmp/hot' from v$datafile;
spool off
alter database begin backup;
start /tmp/hotbak.sql
alter database end backup;
alter database backup controlfile to '/tmp/hot/controlbak.ctl';
create pfile = '/tmp/hot/initorcl.ora' from spfile;
quit
EOF
exit
cd $dir_bak
ls * |while read line
do
cp $line $dir/$line_${TIME}
done
原文转自:http://blog.csdn.net/haoxiaoyan/article/details/16947453