Home Database Mysql Tutorial Oracle数据库的备份方法(转)

Oracle数据库的备份方法(转)

Jun 07, 2016 pm 04:35 PM
oracle backup introduction database method

1、引言 Oracle数据库的备份方法很多,无论使用那种备份方法,备份的目的都是为了在出现故障后能够以尽可能小的时间和代价恢复系统。比如使用export实用程序导出数据库对象、使用Oracle备份数据库、使用Oracle对称复制、使用Oracle并行服务器、使用Oracle冷

1、引言

Oracle数据库的备份方法很多,无论使用那种备份方法,备份的目的都是为了在出现故障后能够以尽可能小的时间和代价恢复系统。比如使用export实用程序导出数据库对象、使用Oracle备份数据库、使用Oracle对称复制、使用Oracle并行服务器、使用Oracle冷备份、使用Oracle热备份等各种备份方法都有其优缺点、适用的场合和相应的软硬件要求。本文主要就用export实用程序导出数据库对象、Oracle冷备份、Oracle热备份这三种最基本的备份方法进行详细的探讨,分析各自的优缺点和适用的场合,并给出自动执行这些备份方案的脚本文件。

2、三种备份方案的比较
 

冷备份

冷备份是Oracle最简单的一种备份;执行冷备份前必须关闭数据库;然后使用操作系统实用工具或者第三方工具备份所有相关的数据库文件。

优点:能简单快速地备份。能简单快速地恢复。执行简单。
缺点:必须关闭数据库,不能进行点恢复。

热备份
热备份是当数据库正在运行时进行数据备份的过程。执行热备份的前提是:数据库运行在可归档日志模式。适用于24X7不间断运行的关键应用系统。

优点:备份时数据库可以是打开的。热备份可以用来进行点恢复。初始化参数文件、归档日志在数据库正常运行时是关闭的,可用操作系统命令拷贝。
缺点:执行过程复杂。由于数据库不间断运行,测试比较困难。不能用操作系统实用工具拷贝打开的文件。必须使用Oracle提供的ocopy工具来拷贝打开的文件。热备份可能造成CPU、I/O过载,应在数据库不太忙时进行。

Export导出数据库对象
冷备份和热备份都备份物理数据库文件,因而被称为物理备份。而export备份的是数据库对象,因此被称为逻辑备份。

优点:能执行对象或者行恢复。备份和恢复速度更快。能够跨操作系统平台迁移数据库。数据库可一直运行。
缺点:export并不是冷备份和热备份的替代工具。冷、热备份可保护介质失效。export备份可保护用户或应用错误。

3、冷备份方案的实施

3.1 冷备份数据库的步骤
(1)关闭数据库;
(2)备份所有相关的数据库文件:初始化参数文件、控制文件(可用select name from v$controlfile;列出所有

控制文件)、数据文件(可用select name from v$datafile;列出所有数据文件)、Redo日志(可用select member from v$logfile;列出所有redo日志文件)、归档的Redo日志(可用select sequence#,first_time from v$loghist;列出所有归档redo日志文件的顺序号和产生时间)。
 

3.2 冷备份数据库的脚本文件coldbackup.bat
 

4、热备份方案的实施

4.1 热备份数据库的前提条件:数据库运行在归档模式
Oracle数据库的redo日志记录在数据库上进行的所有活动。LGWR后台进程以一种循环方式写这些日志文件,从第一个redo日志到下一个,直到该组的最后一个,然后由从第一个日志写起。
在非归档模式下,当循环写到最后一个日志文件后,就重写第一个日志。因此,非归档模式下唯一的数据库恢复办法就是使用冷备份。
在归档模式下,当redo日志满时,一个ARCH后台进程就读取全部redo日志,然后将其写到归档日志。因此,可以使用热备份和点恢复。在归档日志模式下,如果归档日志目的空间已满,数据库活动将暂时停止,只有释放一些空间后,数据库才能继续运行。通常,background_dump_destination将产生一个跟踪文件来显示归档方面的问题。
Oracle数据库安装默认运行在非归档模式,通过以下步骤可以从非归档模式转换为归档模式:
(1)编辑参数文件init.ora,设置以下参数
# 设置数据库自动归档
log_archive_start = true
# 设置归档日志文件的目录,该目录必须事先已建立,并有大量可利用的空间
log_archive_dest_1=”location=%oracle_base%\ oradata\%oracle_sid%\archive”
# 设置归档日志文件名的格式。%s表示顺序号,%t表示线程号。
log_archive_format = “%oracle_sid%%T%S.ARC”
(2)在sqlplus上运行以下命令
sqlplus>;connect sys/qazwsx as sysdba
sqlplus>;shutdown immediate;
sqlplus>;startup mount exclusive;
sqlplus>;alter database archivelog;
sqlplus>;alter database open;
sqlplus>;shutdown immediate;
(3)执行数据库冷备份
当数据库运行在归档模式下,数据库恢复过程要求使用冷备份时,归档日志是必需的。
(4)正常启动数据库,并确认数据库运行在归档模式
sqlplus >; startup;
sqlplus >; select * from v$database; 其log_mode会显示数据库是否归档模式
sqlplus >; archive log list; 也会显示数据库是否归档模式
如果Oracle数据库运行在归档模式,当进行数据库维护时,可能需要暂停数据库的归档,在完成维护后,再重新启动归档模式。通过以下步骤可以从归档模式转换为非归档模式:
sqlplus>;connect sys/qazwsx as sysdba
sqlplus>;shutdown immediate;
sqlplus>;startup mount exclusive;
sqlplus>;alter database noarchivelog;
sqlplus>;alter database open;
sqlplus >; select * from v$database; 其log_mode会显示数据库是否归档模式
sqlplus >; archive log list; 也会显示数据库是否归档模式
4.2 热备份数据库的步骤
(1)拷贝init.ora文件到备份目录(参数文件在数据库启动后处于关闭状态)。
(2)将需要备份的某个表空间置于开始备份模式。
(3)使用ocopy.exe拷贝表空间,然后将该表空间置于结束备份模式中(ocopy.exe不能用于直接拷贝联机的数据库文件)。
(4)对数据库中的每个表空间执行步骤2和3(可以通过视图dba_tablespaces和v$datafile查看数据库中有哪些表空间和数据文件)。
(5)通过在sqlplus上执行archive log list命令获取当前的日志顺序号,从oldest online log sequence开始到current log sequence的联机redo日志应该是热备份的一部分。
(6)在sqlplus上执行alter system switch logfile;命令来强迫日志切换,以便所有的日志都被归档。
(7)使用alter database backup controlfile to trace;命令获得控制文件的一个备份,可以到%oracle_base%\admin\%oracle_sid%\udump目录中寻找最新的跟踪文件,其中有重建控制文件的全部命令。
(8)使用windows nt的命令从%log_archive_dest%中拷贝归档的日志文件到备份目录。
4.3 热备份数据库的脚本文件hotbackup.bat
 

5、使用export作为备份策略

5.1 export的命令选项说明
Oracle数据库的exp工具提供tables、users、full database、tablespace四种级别的导出方式,把指定的数据库内容导出到一个或者多个oracle二进制文件中,该文件只允许用imp工具来读取,imp的命令选项可用imp help=y来查阅。
您可以通过输入 EXP 命令以及各种自变量来控制“导出”的运行方式。要指定参数,您可以使用关键字:
格式:EXP KEYWORD=value 或 KEYWORD=(value1,value2,…,valueN)
实例:EXP SCOTT/TIGER GRANTS=Y TABLES=(EMP,DEPT,MGR)
或 TABLES=(T11,T12),如果 T1 是分区表
USERID 必须是命令行中的第一个参数。

下列关键字仅用于可传输的表空间
TRANSPORT_TABLESPACE 导出可传输的表空间元数据 (N)
TABLESPACES 将传输的表空间列表
5.2 export备份数据库的脚本文件expbackup.bat

6、各种备份策略的自动执行方法

不管是冷备份、热备份,还是export备份;不管是unix平台,还是windows平台,都可以利用at命令来定时、自动执行上述备份策略。AT 命令安排在特定日期和时间运行命令和程序,在windows nt平台上必须首先运行调度服务(schedule),才能使用at命令。
AT命令用法如下:
AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] “command”
\\computername 指定远程计算机。 如果省略这个参数,会计划在本地计算机上运行命令。
id 指定给已计划命令的识别号。
/delete 删除某个已计划的命令。如果省略 id,计算机上所有已计划的命令都会被删除。
/yes 不需要进一步确认时,跟删除所有作业的命令一起使用。
time 指定运行命令的时间。
/interactive 允许作业在运行时,与当时登录的用户桌面进行交互。
/every:date[,...] 每个月或每个星期在指定的日期运行命令。如果省略日期,则默认为在每月的本日运行。
/next:date[,...] 指定在下一个指定日期(如下周四)运行命令。如果省略日期,则默认为在每月的本日运行。
“command” 准备运行的 Windows NT 命令或批处理程序。
举例如下:
(1) 每周五19:00执行冷备份
at 19:00 /every:F “coldbak.cmd”
(2) 每周二20:00执行热备份
at 20:00 /every:T “coldbak.cmd”
(3) 每周一、二、三、四、五21:00执行export备份
at 20:00 /every:M,T,W,Th,F “expbak.cmd”

转自: http://www.cnblogs.com/elegantok/archive/2009/03/31/1426290.html

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

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.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

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.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

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.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

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

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

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.

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

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.

See all articles