linux下进行oracle的热备份shell脚本

来源:互联网 发布:理正深基坑支护软件 编辑:程序博客网 时间:2024/05/19 18:11

1.在执行热备份必须保证处于归档模式下

2.在主目录下编写hot_backup.sh,代码如下:

#!/bin/bash
backup_dir=/oracle/bakup
log_file=$ORACLE_BASE/admin/$ORACLE_SID/hot_backup_$ORACLE_SID.log
echo "Beginning backup...">$log_file
date>>$log_file


sqlplus -s / as sysdba<<EOF>>$log_file
alter database backup controlfile to '/$backup_dir/backup_controlfile.ctl';
set pagesize 0
set linesize 1000
set set feedback off
col tablespace_name noprin
col sortorder noprin
col textout format a120


spool hot_backup_$ORACLE_SID.sql
select tablespace_name,'1' sortorder,'alter tablespace ' || tablespace_name || 'begin backup;' textout from dba_data_files
union
select tablespace_name,'2' sortorder,
'host cp ' || file_name || ' ' || '$backup_dir' textout
from dba_data_files
union
select tablespace_name, '3' sortorder,
'alter tablespace ' || tablespace_name || ' end backup; ' textout
from dba_data_files
order by tablespace_name, sortorder, textout;
select 'alter system archive log current;' from dual;
spool off
@hot_backup_$ORACLE_SID.sql
exit
EOF
rm -f hot_backup_$ORACLE_SID.sql
echo "Hot backup finished.">>$log_file

热备份简单的就是对表空间的备份,因此需要在归档模式下操作。


原创粉丝点击