[Oracle] Oracle Series 16--Database Backup

Review of past issues

1. Classification of database backup

1.1 Logical backup and physical backup

Database backup is divided into logical backup and physical backup according to the backup status.

(1) Logical backup

Use SQL to extract data from the database and save it as a binary file for backup. The business database adopts this method and does not need to be in archive mode. For example, in Oracle, use EXPORT to export database objects (users, tables, stored procedures), and use IMPORT to import logical backup files into the database (Oracle exp/imp).

  • Advantages: Only certain tables or certain data can be backed up; cross-platform recovery can be performed between different versions; storage can be compressed to save space.
  • Disadvantages: For large-scale databases, executing statements takes a long time; complete consistency cannot be guaranteed (such as new data being inserted at the same time).

(2) Physical backup

Physical backup refers to directly copying all contents on the database storage medium, including the operating system level and database engine level, so that the entire database can be completely restored. Generally requires an external storage device.

  • Advantages: Fast and reliable; able to provide consistent snapshots.
  • Disadvantages: It can only provide recovery to a "certain point in time", it cannot selectively backup and restore (by table or user), it can only back up and restore the entire database; it cannot be used for cross-platform migration.

Cold backup: occurs when the database has been shut down normally (offline state), and all data files are offline. During the backup process, the database cannot do other work and the integrity and consistency of the data can be guaranteed.
Hot backup: It is performed when the database is running (online state) and will not affect normal business operations. It can be backed up at the table space or database file level and is transparent to users. It can maintain business continuity and the backup time is short, which can reach seconds. level recovery (recovery to a certain point in time). To set the log to archive mode for hot backup, you need to consider that the data being written or modified may cause data inconsistency, and special measures must be taken to ensure data integrity.

(3) Archive mode and non-archive mode

Archive mode: In archive mode, the database saves historical records to a set of special files called "archive logs". These logs contain details of previously committed transactions, allowing lost or corrupted data to be recovered or restored. Performance will be reduced due to the need to write to the log file frequently.
Non-archive mode: In non-archive mode, when a transaction is committed, its results are written directly to the main data file. Instead of generating additional log files like archive mode. Although this method can improve performance and reduce space overhead, it also carries the risk of not being able to fully recover the data if it is lost or damaged.

1.2 Full backup/differential backup/incremental backup

(1) Full backup (Full): Backs up all selected files and does not rely on the archive attribute of the file to determine which files to back up (each file is marked as backed up, eliminating the archive attribute).

(2) Differential backup (Differential): Back up all files that have changed since the last full backup (the files will not be marked as backed up after the backup, and the archive attribute will not be eliminated). (Backup takes a long time, takes up a lot of space, and restores quickly).

(3) Incremental backup (Incremental): Back up all files that have changed since the last backup (no matter what kind of backup) (mark the files after the backup and eliminate the archive attribute). (The backup time is short, takes up less space, and restores slowly).

Combination example:

Complete + differential backup: A full backup is performed on Monday, and a differential backup is performed from Tuesday to Friday. If the data is damaged on Friday, Monday's full backup and Friday's differential backup need to be restored.
Complete + additional backup: Full backup is performed on Monday, and incremental backup is performed from Tuesday to Friday. If the data is damaged on Friday, you need to restore Monday's full backup and the incremental backups from Tuesday to Friday.

2. Oracle logical backup

Oracle supports two types of logical backups: export/import utilities and data pumps.

2.1 EXP/IMP

(1) EXP export

full mode

exp SYSTEM/MANAGER BUFFER=64000 file= C:\full.dmp full=Y

user mode

exp detail12/detail12 owner=(detail12,detail11) file=/home/oracle/detail.dmp
exp detail12/detail12@RACDB_192.168.1.13 file=d:/detail.dmp

Among them, RACDB_192.168.1.13 is the network service name of Oracle Net Configuration Assistant.

Table mode

exp detail12/detail12 owner=detail12 tables=(T_JBXX) file=/home/oracle/t_jbxx.dmp

If T_JBXX is a partitioned table, use the form tables=(T_JBXX1:P1, T_JBXX2:P2).

query field format:

query="""where dept_date<to_date('2014-02-01 00:00:10','yyyy-mm-dd hh24:mi:ss')"""

Note: You can add GRANTS=Y INDEXES=Y without importing permissions and indexes.

Keyword description

Keywords Description (default)
USERID username/password
FULL Export entire file(N)
BUFFER Data buffer size
OWNER List of owner usernames
FILE Output file (EXPDAT.DMP)
TABLES table name list
COMPRESS Import into a zone (Y)
RECORDLENGTH IO record length
GRANTS Export permission(Y)
INCTYPE Incremental export type
INDEXES Export Index(Y)
RECORD Trace delta export(Y)
DIRECT Direct path(N)
TRIGGERS Export trigger(Y)
LOG Screen output log file
STATISTICS Analysis object (ESTIMATE)
ROWS Export data rows (Y)
PARFILE Parameter file name
CONSISTENT Crosstab consistency(N)
CONSTRAINTS Derived constraints(Y)
OBJECT_CONSISTENT Transactions set to read-only during object export (N)
FEEDBACK Show progress every x lines (0)
FILE SIZE Maximum size of each dump file
FLASHBACK_SCN SCN used to set session snapshot back to previous state
FLASHBACK_TIME Used to get the time of the SCN closest to the specified time
QUERY select clause for exporting a subset of a table
RESUMABLE Hangs on encountering a whitespace-related error (N)
RESUMABLE_NAME Text string identifying a recoverable statement
RESUMABLE_TIMEOUT RESUMABLE wait time
TTS_FULL_CHECK Perform full or partial dependency checks on TTS
TABLESPACES List of tablespaces to export
TRANSPORT_TABLESPACE Export transportable tablespace metadata(N)
TEMPLATE Call the template name exported by iAS mode

(2)IMP import

full mode

imp SYSTEM/MANAGER BUFFER=64000 file=C:\full.dmp full=Y

user mode

imp detail12/detail12 fromuser=(detail12,detail11) touser=(detail12,detail11) file=/home/oracle/detail.dmp

Table mode

imp detail12/detail12 owner=detail12 tables=(T_JBXX) file=/home/oracle/t_jbxx.dmp

Notice

IMP import must specify Full=Y, or provide fromuser/touser parameters, or provide tables parameters.
Before importing, you need to set the character set as required. export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK. If
you ignore the table creation error, you can add IGNORE=Y. If you do not import permissions and indexes, you can add GRANTS=Y. INDEXES=Y. An
IMP-00032 error occurs during import, indicating that the SQL statement exceeds the buffer. Area length, you can add options: buffer=100000000
keyword description

Keywords Description (default)
USERID username/password
FULL Import entire file(N)
BUFFER Data buffer size
FROMUSER List of owner usernames
FILE Input file (EXPDAT.DMP)
TOUSER Username list
SHOW List only file contents (N)
TABLES table name list
IGNORE Ignore creation errors(N)
RECORDLENGTH IO record length
GRANTS Import permissions(Y)
INCTYPE Incremental import type
INDEXES Import index(Y)
COMMIT Submit array insert(N)
ROWS Import data rows (Y)
PARFILE Parameter file name
LOG Screen output log file
CONSTRAINTS 导入限制 (Y)
DESTROY 覆盖表空间数据文件 (N)
INDEXFILE 将表/索引信息写入指定的文件
SKIP_UNUSABLE_INDEXES 跳过不可用索引的维护 (N)
FEEDBACK 每 x 行显示进度 (0)
TOID_NOVALIDATE 跳过指定类型 ID 的验证
FILESIZE 每个转储文件的最大大小
STATISTICS 始终导入预计算的统计信息
RESUMABLE 在遇到有关空间的错误时挂起 (N)
RESUMABLE_NAME 用来标识可恢复语句的文本字符串
RESUMABLE_TIMEOUT RESUMABLE 的等待时间
COMPILE 编译过程, 程序包和函数 (Y)
STREAMS_CONFIGURATION 导入流的一般元数据 (Y)
STREAMS_INSTANTIATION 导入流实例化元数据 (N)

2.2 EXPDP/IMPDP

(1)数据泵介绍

Oracle Database 10g引入了最新的数据泵(Data Dump)技术,使DBA或开发人员可以将数据库元数据(对象定义)和数据快速移动到另一个oracle数据库中,与Export / Import相比,它提供更好的性能、安全性和灵活性。

并行处理: Oracle 数据泵支持并行处理(通过指定 PARALLEL 参数启用),这使得导入和导出任务更加快速和高效。
可定制: 数据泵允许用户选择要包含或排除的对象类型(如表、视图、约束等),以及要包含或排除的特定对象。
压缩: Oracle 数据泵支持压缩功能,可减少导出文件的大小,并提高传输速度。
安全性: 数据泵支持 SSL 加密协议来保护敏感信息,在安全方面非常有优势。
多平台兼容性: Oracle 数据泵支持多个平台上运行,例如 Windows 和 Linux 等操作系统。
(2)数据泵的使用

EXP和IMP是客户段工具程序,它们既可以在可以客户端使用,也可以在服务端使用。 EXPDP和IMPDP是服务端的工具程序,他们只能在ORACLE服务端使用,不能在客户端使用。

使用EXPDP工具时,其转储文件只能被存放在DIRECTORY对象对应的OS目录中,而不能直接指定转储文件所在的OS目录。因此,使用EXPDP工具时,必须首先建立DIRECTORY对象,并且需要为数据库用户授予使用DIRECTORY对象权限。

使用Data Pump,可将整个数据库或特定模式及其对象(如表格、索引、约束和其数据)导出/导入,还可指定选项,例如表空间、压缩级别、加密和远程导出/导入的网络链接。

Data Pump包括两个客户端实用程序:expdp(Export Data Pump)和impdp(Import Data Pump)。

e.g.

create directory imp_dir as 'D:\imp_dir';
GRANT READ, WIRTE ON DIRECTORY imp_dir TO detail;
expdp scott/tiger DUMPFILE=tmp_dump.dmp  DIRECTORY= imp_dir
impdp scott/tiger DUMPFILE=tmp_dump.dmp  DIRECTORY= imp_dir

Guess you like

Origin blog.csdn.net/u011397981/article/details/133563318