数据库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数据异地自动备份,本地主机如果有什么故障,数据有了可靠备份,同时,在一定程度上也减轻了系统管理人员烦琐、重复的备份工作。
上一页

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
