Backup Database Scripts under Linux

Source: Internet
Author: User

#!/bin/bash
Dbbackdir= "/home/oracle/fm/fm_backup" #数据库数据本机存放位置, according to the circumstances of their own modification
Logdir= "/home/oracle/fm/fm_backup/log.txt" #简单日志输出
#检查备份目录是否存在和是否有读写权限
If [-F "$LOGDIR"]; Then #检查日志输出文件
chmod a+w $LOGDIR #设置读写权限
Else
Touch $LOGDIR
chmod a+w $LOGDIR
Fi

If [-a "$DBBACKDIR"]; Then #检查数据库备份目录
chmod a+w $DBBACKDIR #设置权限
Else
Mkdir-p $DBBACKDIR
chmod a+w $DBBACKDIR
Fi

#动态生成当前日期, as part of the backup file name to differentiate files
Year= ' Date +%y '
Month= ' Date +%m '
day= ' Date +%d '
now= ' Date +%y-%m-%d ' #获取系统时间


############ #备份数据库 ################
echo "Database backup starts ..." >> $LOGDIR #写日志
CD $ Dbbackdir
su-l oracle-c "exp fmtest/[ Email protected] file= $DBBACKDIR/fmwork_cdb_$now.dmp log= $DBBACKDIR/fmwork_$now.log owner=fmtest Statistics=none "   #切换到oracle用户, export database
gzip $DBBACKDIR/fmwork_cdb_$now.dmp  #压缩打包数据库备份
Find $ Dbbackdir-mtime +7-type f-name "fmwork*"-exec rm  {} \;  #删除7天以上的数据库备份数据
echo "Database backup end!" > > $LOGDIR #写日志
Echo ############### END ################ >> $LOGDIR
Echo                >> $LOGDIR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.