菜鸟求助:linux下oracle数据库自动备份脚本,脚本可实现数据库自动备份功能,并删除三天前的备份
发布网友
发布时间:2022-04-07 18:37
我来回答
共3个回答
热心网友
时间:2022-04-07 20:06
这个好办。 cp 你的数据库`date +'%y%m%d'` 指定目录 这个是以年月日来命名备份 删除的命令是
rm -f 你的数据库名字`date -d "3 days ago" +'%y%m%d'` 这个是删除匹配你数据库的备份名日期前3天的备份文件 他会按照日期-3天匹配3天前的日期来删除备份的追问额,请问您有没有现成的文档方便贴出来?
追答没有文档,这个怎么写的格式我都给你写出来了,你照样搬上就是了 哥们分数呢
热心网友
时间:2022-04-07 21:24
Linux下备份oracle数据库shell脚本 --------------------仅供参考,需根据情况修改!
#!/bin/bash
#获取linux服务器上/dev/sda7的磁盘空间大小
DISK_SIZE=`df -k|grep /dev/sda7 |awk '{ print substr($5,1,2) }'`
export DISK_SIZE
LANG=zh_CN.UTF-8
export LANG
#判断磁盘空间是否大于85% 如果大于85%就直接退出执行s
if [ $DISK_SIZE -gt 85 ]; then
echo DISK_SIZE is $DISK_SIZE over 85
exit
else
echo DISK_SIZE=$DISK_SIZE
fi
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
#oralce安装的路径
ORACLE_BASE=/opt/app/oracle
export ORACLE_BASE
ORACLE_HOME=/opt/app/oracle/proct/10.2.0/db_1
export ORACLE_HOME
#oracle安装的服务名称
ORACLE_SID=metardb
export ORACLE_SID
#BAK_PATH is a path that store your exp file
BAK_PATH="/orabak"
#LOG_FILE is a file that recorde the results of export
LOG_FILE="$BAK_PATH"/`date +%Y%m%d`_brief.log
#Define the exp user
USER=system
#Define the exp user's password
PASSWD=metarnet
#Determine the current user name
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
#Define the retention days of your backup file
DAYS=365
#******************************************************************
#It is unnecessary to edit the the below text in normal condition.*
#******************************************************************
echo "The start time is: "`date` >> $LOG_FILE
echo >> $LOG_FILE
if [ $DISK_SIZE -gt 85 ]; then
echo DISK_SIZE is $DISK_SIZE over 85|tee -a $LOG_FILE
exit
else
echo DISK_SIZE=$DISK_SIZE|tee -a $LOG_FILE
fi
#Define the backup file name
BAK_FILE=metardb_`date +%Y%m%d_%w`_full.dmp
#Define the backup log file name
BAK_LOG=metardb_`date +%Y%m%d_%w`_full.log
#Define your backup command
CMD_STR="
setenv ORACLE_HOME $ORACLE_HOME
exp $USER/$PASSWD@$ORACLE_SID file=$BAK_PATH/$BAK_FILE log=$BAK_PATH/$BAK_LOG full=y
"
#Begin backup
echo "Backup is started" >>$LOG_FILE
echo "......">>$LOG_FILE
if [ "$CUSER" = "root" ]
then
su - oracle -c "$CMD_STR" >> $LOG_FILE
RSTAT=$?
else
/usr/bin/csh -c "$CMD_STR" >> $LOG_FILE
RSTAT=$?
fi
if [ "$RSTAT" = "0" ]
then
echo "Backup to Hard disk is ended successful!" >> $LOG_FILE
else
echo "Notice! Backup hard disk is ended unsuccessful!">> $LOG_FILE
fi
#compress
#yestoday=`date +%D | awk -F/ '{s=$2-2}{printf"20%02d%02d%02d\n", $3,$1,s}'`
cd $BAK_PATH
#CMP_FILE="yujing_"$yestoday"_full.dmp"
echo "Compress "$BAK_FILE >>$LOG_FILE
gzip $BAK_FILE
#Delete 3 days ago file
OLDFILE=metardb_`date -d '3 days ago' +%Y%m%d_%w`_full.dmp.gz
OLDLOG=metardb_`date -d '3 days ago' +%Y%m%d_%w`_full.log
rm -rf /orabak/$OLDFILE
rm -rf /orabak/$OLDLOG
echo >>$LOG_FILE
echo "Backup to Hard disk End time is: "`date`>>$LOG_FILE
热心网友
时间:2022-04-07 22:59
加偶QQ告诉你,499793803追问前辈你好,我加不进去您QQ,麻烦您加我吧,583868727