数据库Oracle数据的异地的自动备份
数据库Oracle数据的异地的自动备份
正在看的ORACLE教程是:数据库Oracle数据的异地的自动备份。在大型商业应用中,数据的异地容灾备份十分重要,也必不可少。笔者根据自己的实践经验,设计了一套简洁地实现异地数据自动备份的方法,可供数据库管理人员参考。文中所有的程序都经过测试,运行良好。这里模拟的异地运行环境为一主一备两套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条语句建立一个取当前日期的变量,以便在最后一条语句的备份文件名里含有当前日期信息。
[NextPage]
异地传输
在备份主机里建立一个备份目录:/data/oradata/newbackup, 在本地主机Oracle用户的注册目录/export/home/oracle里建立一个.netrc文件。设定好备份主机的IP地址,备份主机上的用户为oraclebk, 口令为testbk2。.netrc文件内容为:
machine x.x.x..x
login oraclebk
password testbk2
macdef init
bin
lcd /export/home/oracle/backup
cd /data/oradata/backup
mput *
bye
说明: 前3条语句完成在备份主机上的登录,第4条语句定义一个名为init的宏,第5条语句表示以二进制传输,第6条语句表示进入本地工作目录,第7条语句表示进入备份主机目录,第8条语句完成将本地主机/export/home/oracle/backup目录下的所有文件传输至备份主机/data/oradata/backup目录下,最后一条语句退出ftp会话进程。
.netrc文件编写完成后,用命令“chmod 600
.netrc”使该文件只能被该用户所访问。
自动执行
我们以oracle用户登录本地主机,用“crontab -e”编写crontab文件用以启动自动备份进程。oracle文件内容如下:
10 23 * * * /export/home/oracle/testbackup
30 23 * * * ftp -i x.x.x.x
说明:第1条语句指定每天自动在23点10分执行对数据库的备份,第2条语句指定每天自动在23点半启动ftp,将备份文件传输到备份主机(备份主机为符合语句中指定IP地址的主机)。
Oracle文件只能在Oracle用户名下用“crontab -e”命令来编辑。编辑完成后,可以在用“crontab-l”命令来查看crontab文件内容,同时在/var/spool/cron/crontabs目录下查看是否增加了一个Oracle文件。
至此,本地主机可以每天定时备份数据库,并定时把备份数据传到备份主机。这样,较好地实现了Oracle数据异地自动备份,本地主机如果有什么故障,数据有了可靠备份,同时,在一定程度上也减轻了系统管理人员烦琐、重复的备份工作。
上一页

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

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.
