Linux automatically backs up the Oracle database and uploads it to the Backup server script implementation

Source: Internet
Author: User

The actual project, backup data is an indispensable step, complete the automatic backup of data to reduce the workload of individuals, is our goal. There have been few scripts written before, but these simple operations can be done! Not much to say, to begin specific introduction:
Oracle version: 10.2.0
Operating system: linuxredhat6.3
Specific operation:
(1) Create a backup directory on the server and give permissions
Mkdir-p/backup/oracledata #新建Oracle数据库备份目录

Chown-r oracle:oinstall/backup/oracledata-r #设置目录权限为oinstall用户组的oracle用户 (user Oracle and user group Oinstall are set when the Oracle database is installed)

(2) Completing the backup script

Vi/backup/oracledata/ordatabak.sh #新建文件
Add the following information:
#!/bin/sh Oracle information can be viewed via. bash_profile
Export Oracle_base=/oracle/app/oracle
Export ORACLE_SID=ORCL
Export Oracle_home= $ORACLE _base/product/10.2.0/db_1
Export path= $PATH: $ORACLE _home/bin
Export Oracle_term=xterm
Export path= $PATH: $ORACLE _home/bin: $HOME/bin:/usr/bin:/sbin:/usr/sbin
Export ld_library_path= $ORACLE _home/lib: $ORACLE _home/rdbms/lib:/lib:/usr/lib:/usr/local/lib
Export Lang=c
Export Nls_lang=american_america. Al32utf8
#以上代码为Oracle数据库运行账号oracle的系统环境变量设置, you must add, otherwise crontab task schedule cannot be executed.
Datetime= ' Date +%y_%m_%d ' #当前系统时间
Days=7 #删除7天前的备份数据s
Orsid= ' 127.0.0.1:1521/ORCL ' #oralce连接信息
Orowner=oracle # Back up the data below this user
Bakuser=oracle #用此用户来执行备份, you must have permissions to the backup operation
Bakpass=oracle #执行备注的用户密码
Bakdir=/data/bakorcldata/moodle #备份文件路径 need to be created in advance.
Bakdata= $orowner "_" $dateTime. DMP #备份数据库名称
Baklog= $orowner "_" $dateTime. Log #备份执行时候生成的日志文件名称
ordatabak= $orowner "_" $dateTime. tar.gz #最后保存的Oracle数据库备份文件
remotepath=/opt/oracle/bakorcl/#上传到远程服务器的路径

CD $bakdir #进入备份目录
Mkdir-p $orowner #按需要备份的Oracle用户创建目录
CD $orowner #进入目录
Exp $bakuser/[email protected] $orsid grants=y owner= $orowner file= $bakdir/$orowner/$bakdata log= $bakdir/$orowner/$ Baklog #执行备份
TAR-ZCVF $ordatabak $bakdata $baklog #压缩备份文件和日志文件

Find $bakdir/$orowner-type f-name "*.log"-exec rm {} \; #删除备份文件
Find $bakdir/$orowner-type f-name "*.dmp"-exec rm {} \; #删除日志文件
Find $bakdir/$orowner-type f-name "*.tar.gz"-mtime + $days-exec rm-rf {} \; #删除7天前的备份 (note: {} \ has spaces in the middle)
SCP $bakdir/$orowner/$ordatabak 192.168.0.10: $remotePath #将备份文件上传到远程服务器 If you do not lose the password upload please refer to Http://blog.sina.com.cn/s/blog. _957ef38b0102vuxy.html
: wq! Save exit

(3) Add script execution permissions
chmod +x/backup/oracledata/ordatabak.sh #添加脚本执行权限
(4) Editing the system task execution plan
Crontab-e
Enter the message ":

* * * * * */data/bakorcldata/oradatabak.sh# daily 1 o'clock in the morning to perform ordatabak.sh backup files with Oracle user

: wq! #保存退出

Restart Crontab

Service Crond Restart

From this day to 1 o'clock in the morning the system will automatically complete the database backup, compression, and upload to the remote server under the specified path!

Linux automatically backs up the Oracle database and uploads it to the Backup server script implementation

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.