Oracle数据的异地自动备份
在大型商业应用中,数据的异地容灾备份十分重要,也必不可少。笔者根据自己的实践经验,设计了一套简洁地实现异地数据自动备份的方法,可供数据库管理人员参考。文中所有的程序都经过测试,运行良好。这里模拟的异地运行环境为一主一备两套Sun Solaris系统,
在大型商业应用中,数据的异地容灾备份十分重要,也必不可少。笔者根据自己的实践经验,设计了一套简洁地实现异地数据自动备份的方法,可供管理人员参考。文中所有的程序都经过测试,运行良好。这里模拟的异地运行环境为一主一备两套Sun Solaris系统,所采用的备份方法为Oracle提供的标准备份:export。
相关命令
文中主要用到三个命令,这里先单独介绍一下:
export: 将数据库中数据备份成一个二进制系统文件,它有三种模式: 用户模式、表模式、整个数据库模式。还可分为三种备份类型:完全型、积累型、增量型。本文以整个数据库模式下的完全型为例说明。export使用格式为:
exp userid file
其中:userid的用法为username/userpassword,即Oracle中的用户名/口令。userid必须为exp的第一个参数,file指备份文件所放位置及名称。
ftp: 一般情况下可通过交互方式实现两台主机间的数据传输,即需要手工输入目标主机的IP地址、用户名、口令等。但是当用户使用ftp命令时,系统将会先在该用户的注册目录中寻找.netrc文件,并首先执行该文件。这样,我们可以通过编写一个.netrc的文件来达到自动备份的目的。要注意该文件必须命名为.netrc,且必须存放在启动ftp命令主机上的用户注册目录里。ftp常用选项:
-i:进行多文件传送时关闭交互提示;
-n:在连接之后不进行自动登录。
本文使用“-i”选项,以关闭交互提示。
crontab: cron是一个永久进程,它由/etc/rc.local启动执行。cron检查/var/spool/cron/crontabs/目录中的文件,找到所要执行的任务和执行任务的时间,并自动完成。该目录中文件由crontab命令建立。用户所建立的crontab文件存于/var/spool/cron/crontabs中,其文件名与用户名一致,本文使用crontab的用户为Oracle,所建立的文件名也为Oracle。
cron使用者的权限记载在下列两个文件中: /usr/var/adm/cron/cron.deny和/usr/var/adm/cron/cron.allow。前面的文件中所列的用户不允许使用crontab命令;后一文件中所列的用户允许使用crontab命令。crontab命令的常用格式为:
crontab -l:显示用户的crontab文件的内容;
crontab -r:从crontabs目录中删除用户的crontab文件;
crontab -e:编辑用户的crontab文件。
crontab文件每行中有6个字段,前5个为时间设定段,第6个为所要执行的命令。时间段分别为: minutes、hours、day of month、month、day of week,字段之间用空格或Tab分开。字段如果为“*”,表示该字段在所有可能的取值范围内取值; 如果一个字段是由连字符隔开的两个数字,表明命令可以在两个数字之间的范围内执行。
备份数据库
设定数据库的拥有者为Oracle,用户名为mistest,其口令为test,新建备份目录为/export/home/oracle/backup。建立一个命名为testbackup的备份文件,文件内容如下:
ORACLE-HOME=/export/home/oracle/815;export ORACLE-HOME
ORACLE-SID=ora815;export ORACLE-SID
rm /export/home/oracle/backup/*
rq=丶date +“%m%d”丶
/export/home/oracle/815/bin/exp mistest/test file=/export/home/oracle
/backup/exp$rq.dmp log=/exoport/home/oracle/backup/exp$rq.log
说明:前两句对Oracle数据库初始化,第3条语句清空备份目录,第4条语句建立一个取当前日期的变量,以便在最后一条语句的备份文件名里含有当前日期信息。
testbackup编写完成后,用“chmod +x testbackup”命令授予它可执行权限。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.
