环境:linux as3+oracle9i
具体的步骤:
1.邮件设置
[root@sxapp1 mail]# cd /etc/mail
[root@sxapp1 mail]# mv submit.cf submit.cfbak
[root@sxapp1 spool]# chmod a+wrx mqueue/
[root@sxapp1 mail]# echo "sdsdssd"|mail -s "sda" westlife_xu@eyou.com
[root@sxapp1 mail]# cd /etc/mail
[root@sxapp1 mail]# mv submit.cf submit.cfbak
[root@sxapp1 spool]# chmod a+wrx mqueue/
[root@sxapp1 mail]# echo "sdsdssd"|mail -s "sda" westlife_xu@eyou.com
2.建立备份目录
[root@sxapp1 mail]# su - oracle
[oracle@sxapp1 oracle]$ mkdir -p /home/oracle/phy_backup/data --备份文件存放目录
[oracle@sxapp1 oracle]$ mkdir -p /home/oracle/phy_backup/log --备份的log路径
[oracle@sxapp1 oracle]$ cd /home/oracle/phy_backup
3.备份脚本编写,测试(脚本要根据需求微调,我已经测试通过了)
[oracle@sxapp1 phy_backup]$ vi exp.sh
#!/bin/sh
. /home/oracle/.bash_profile
[oracle@sxapp1 phy_backup]$ vi exp.sh
#!/bin/sh
. /home/oracle/.bash_profile
#define variable......
backup_date=`date +%Y%m%d`
bak_home=/home --df -k里面必须能看见
backup_dest=/home/oracle/phy_backup/data --根据需要填写
backup_log=/home/oracle/phy_backup/log --根据需要填写
RECIPT='westlife_xu@eyou.com' --报警邮件设置
backup_date=`date +%Y%m%d`
bak_home=/home --df -k里面必须能看见
backup_dest=/home/oracle/phy_backup/data --根据需要填写
backup_log=/home/oracle/phy_backup/log --根据需要填写
RECIPT='westlife_xu@eyou.com' --报警邮件设置
--检查磁盘空间
# Check local disk space..................................
USED=` df -k|grep $bak_home|awk '{print $5}'|awk -F% '{print $1}'`
if [ $USED -gt 85 ]; then
echo "Disk space is full/243/254please check it"|mail -s "exp full backup failed" $RECIPT
exit 1
fi
# Check local disk space..................................
USED=` df -k|grep $bak_home|awk '{print $5}'|awk -F% '{print $1}'`
if [ $USED -gt 85 ]; then
echo "Disk space is full/243/254please check it"|mail -s "exp full backup failed" $RECIPT
exit 1
fi
--开始备份
#starting exp backup.....
exp system/abc123 full=y buffer=65536 file=$backup_dest/data_$backup_date.dmp log=$backup_log/data_$backup_date.log
#starting exp backup.....
exp system/abc123 full=y buffer=65536 file=$backup_dest/data_$backup_date.dmp log=$backup_log/data_$backup_date.log
--删除过期的备份文件
# delete expired backup ...
list=` find $backup_dest -mtime +7`
echo $list
rm -f $list
if [ $? -ne 0 ]; then
cat $backup_log/data_$backup_date.log|mail -s "exp full backup failed,please check it" $RECIPT
exit 1
fi
cat $backup_log/data_$backup_date.log|mail -s "$backup_date exp log " $RECIPT
~
"exp.sh" 37L, 1237C 已写入
# delete expired backup ...
list=` find $backup_dest -mtime +7`
echo $list
rm -f $list
if [ $? -ne 0 ]; then
cat $backup_log/data_$backup_date.log|mail -s "exp full backup failed,please check it" $RECIPT
exit 1
fi
cat $backup_log/data_$backup_date.log|mail -s "$backup_date exp log " $RECIPT
~
"exp.sh" 37L, 1237C 已写入
[oracle@sxapp1 phy_backup]$ chmod a+x exp.sh --授予可执行权限
[oracle@sxapp1 phy_backup]$ ./exp.sh --执行备份脚本
Export: Release 9.2.0.7.0 - Production on Thu Dec 14 14:37:53 2006
Export: Release 9.2.0.7.0 - Production on Thu Dec 14 14:37:53 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to: Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.7.0 - Production
Export done in ZHS16CGB231280 character set and AL16UTF16 NCHAR character set
About to export the entire database ...
. exporting tablespace definitions
. exporting profiles
. exporting user definitions
. exporting roles
. exporting resource costs
. exporting rollback segment definitions
. exporting database links
. exporting sequence numbers
. exporting directory aliases
. exporting context namespaces
。。。。。。。。。。。。
看脚本是否顺利的运行,备份之后应该会收到备份的log,检查log是否备份正常。如果正常的话就可以做个crontab了,自动执行计划
. exporting tablespace definitions
. exporting profiles
. exporting user definitions
. exporting roles
. exporting resource costs
. exporting rollback segment definitions
. exporting database links
. exporting sequence numbers
. exporting directory aliases
. exporting context namespaces
。。。。。。。。。。。。
看脚本是否顺利的运行,备份之后应该会收到备份的log,检查log是否备份正常。如果正常的话就可以做个crontab了,自动执行计划
[oracle@sxapp1 phy_backup]$ crontab -e
#min hour day month dayofweek command
0 2 * * * /home/oracle/phy_backup/exp.sh
#min hour day month dayofweek command
0 2 * * * /home/oracle/phy_backup/exp.sh
表示每天2点开始执行exp备份。
提示:
备份脚本至少要具备:1.磁盘空间的检查 2.备份log的完整记录 3.备份失败时的报警机制。 本不可能去整理的东西居然整理出来了,希望对别人能有点帮助。
备份脚本至少要具备:1.磁盘空间的检查 2.备份log的完整记录 3.备份失败时的报警机制。 本不可能去整理的东西居然整理出来了,希望对别人能有点帮助。