}
#删除已经存在数据库相关文件
function delfile {
del_file="${backup_dir}/del_files.sh"
echo "Please delete controlfile,datafiles,redo."
echo "$del_file"
sqlplus -S / as sysdba <<EOF
SET HEADING OFF
SET PAGESIZE 0
SET FEEDBACK OFF
SET ECHO OFF
SET TERMOUT OFF
SET TIMING OFF
SPOOL ${del_file}
SELECT 'rm -rf '||name FROM v\$controlfile;
SELECT 'rm -rf '||file_name FROM dba_data_files;
SELECT 'rm -rf '||file_name from dba_temp_files;
select 'rm -rf '||member from v\$logfile;
SPOOL off
EXIT;
EOF
}
#判断数据库状态
function dbchk {
if ps -ef | grep pmon | grep -i ${ORACLE_SID} >/dev/null; then
echo -e 'set timing off \nselect INSTANCE_NAME,status from v$instance;'| sqlplus -S / as sysdba
echo "Oracle database is running. Shutdown the db and drop the files"
# 执行操作
delfile
else
echo "Oracle database is not running."
# 执行操作
recoverscript
restorescript
restore
opendb
fi
}
if [ -z "$1" ]; then
#请输入变量。
echo "$0 bak:backup the controlfile and redo rename sql."
echo "$0 res:restore db ."
exit 1
fi
input_variable="$1"
if [ "$input_variable" == "bak" ]; then
# 如果变量为 "bak",执行备份操作
echo "执行备份操作"
renameredo
backcon
echo "move the file to target!"
echo ${backup_file} ${output_file}
elif [ "$input_variable" == "res" ]; then
echo "执行恢复操作"
dbchk
else
echo "input bak or res."
exit 1
fi