Oracle备份工具、文件命名格式、rman操作
一、常用工具: Recovery Manager: rman只能执行热备(mount或open状态) Oracle Secure Backup 用户管理的备份: cp/dd [if= /of= /blocksize=] 二、rman命名 rman名称不允许重复,%U肯定不重复。 %c 备份片的拷贝数 %D 位于该月中的第几天 (DD) %M 位于该
一、常用工具:
Recovery Manager: rman只能执行热备(mount或open状态)
Oracle Secure Backup
用户管理的备份: cp/dd [if= /of= /blocksize=]
二、rman命名
rman名称不允许重复,%U肯定不重复。
%c 备份片的拷贝数
%D 位于该月中的第几天 (DD)
%M 位于该年中的第几月 (MM)
%F 一个基于DBID 唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,
%d 数据库名称其中IIIIIIIIII 为该数据库的DBID,YYYYMMDD 为日期,QQ 是一个1-256 的序列
%n 数据库名称,向右填补到最大八个字符
%u 一个八个字符的名称代表备份集与创建时间
%p 该备份集中的备份片号,从1 开始到创建的文件数
%U 一个唯一的文件名,代表%u_%p_%c
%s 备份集的号
%t 备份集时间戳
%T 年月日格式(YYYYMMDD)
三、rman相关操作
--登录rman
rman target /
rman target sys/passwork
rman target sys/passwork nocatalog (控制文件方式)
rman target sys/passwork catalog (恢复目录方式)
--查看参数
RMAN> show all;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_ORCL.f'; # default
注释:#default表示该配置仍然是初始的默认值。回到默认配置configure..clear。
1)configure retention policy to ..
--用来决定哪些备份不在需要,共有三个可选项:
a)redundancy 5
--表示某个数据文件的备份集存在的个数,此处为5份
b)recovery window of 7 days
--表示你希望数据库最早能恢复到几天前
c)none
--表示不需要采用保留策略
注释:a)和b)是互斥关系
.
2)CONFIGURE BACKUP OPTIMIZATION ...
--理论上,备份优化仅对于只读表空间或offline表空间起作用。当然,对于已经备份过的归档日志文件也会跳过,缺省为off
3)CONFIGURE DEFAULT DEVICE TYPE TO ..
--指定i/o操作的设备类型:SBT or DISK.缺省是disk。
4)CONFIGURE CONTROLFILE AUTOBACKUP ..
--当autobackup别置为on时,rman做任何备份操作,都会自动对控制文件进行备份。
5)CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'
--配置控制文件的备份片的路径和格式
比如:configure controlfile autobackup format for device type disk to '/u01/app/oracle/backup/%F'
6)CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET
--配置数据库设备类型的并行度。并行的数目决定了开启通道的个数
7)CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1
--是否启动复合备份,向指定的i/o设备中指定的位置生成指定的份数。缺省为1.
这个配置仅用于数据文件和归档文件,并且,只有在自动分配通道时才会生效!
8)CONFIGURE MAXSETSIZE TO UNLIMITED
--配置备份集的大小。一般是配置maxpiecesize,对备份片进行限制。
9)CONFIGURE ENCRYPTION FOR DATABASE OFF
--配置加密备份集。可以具体到某个表空间:
configure encryption for tablespace users on;
如果我们执行set encryption on indentified by think only,紧接其后所创建的备份就需要该密码才能进行正常的恢复
10)CONFIGURE ENCRYPTION ALGORITHM 'AES128'
--指定加密算法,还有一个是 ‘AES256'
11) CONFIGURE ARCHIVELOG DELETION POLICY TO NONE
--指定归档文件的删除策略,缺省是none,即:归档备份完之后就可以被删除
但是,在DG环境,DBA要保证归档文件在standby端成功接收并且应用之前,primary端始终保存该文件,
所以,DG环境当设为:applied on standby
12)CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_ORCL.f'
--配置控制文件的快照文件的存放路径和文件名,这个快照文件是在备份期间产生的,用于控制文件的读一致性
另外,CONFIGURE EXCLUDE FOR TABLESPACE
--修改保存天数
用sqlplus修改备份信息在控制文件中保留的天数
show parameter control_file_record_keep_time
alter system set control_file_record_keep_time=30 scope=spfile
shutdown immediate
startup
--rman数据库冷备份
shutdown immediate;
startup mount;
backup database format='/u01/backup/rman/%d_%T_%s.bak';
alter database open;
sql 'alter system archive log current';
--rman数据库热备份
backup database format='/u01/backup/rman/%d_%T_%s.bak';
sql 'alter system archive log current';
--备份表空间
backup tablespace emp;
--备份数据文件
backup datafile '/u01/mytest.dbf';
backup datafile 5 format='/u01/backup/rman/%N_%s.dbf';
--备份归档日志
backup archivelog all
backup archivelog from time 'sysdate-1'
backup archivelog from sequence 400
backup archivelog all delete input
backup archivelog from sequence 400 delete input
format='/u01/backup/rman/ar%T_%s.arc' --指定路径 %T 日期
--备份过去一天的归档文件
backup format='/u01/backup/rman/ar%d_%s.arc'
archivelog
from time='sysdate-1' until time='sysdate';
--备份数据文件和归档日志
backup format='/u01/backup/rman/t%d_%s.bak' tablespace emp plus archivelog;
--备份控制文件
backup current controlfile format='/u01/backup/rman/%d_%s.ctl';
--备份spfile
backup spfile format='/u01/backup/rman/spf%d_%s.par';
--压缩备份集
backup as compressed backupset tablespace emp;
--建立控制文件映像副本
copy current controlfile to '/u01/backup/rman/dbtest.ctl';
backup as copy format='/u01/backup/rman/dbtest01.ctl' current controlfile;
--建立数据文件映像副本
backup as copy format='/u01/backup/rman/8.dbf' datafile 8;
--rman维护命令
list backup --列出全部的备份信息
list backup of database --列出数据库备份
list backup of tablespace emp --列出指定的表空间备份
list backup of datafile 5 --列出指定的数据文件备份
list backup of controlfile --列出控制文件备份
list backup of spfile --列出spfile备份
list archivelog all --列出归档日志
list backup of archivelog all --列出归档日志的备份
list backup of database summary --列出可用的备份
list backup of tablespace emp summary --关于表空间的备份
list backup by file --按文件类型列出备份
list expired backup of archivelog all summary --失效的备份
report obsolete --查看过期的
delete obsolete --删除过期的
list recoverable backup of database --列出有效的备份
list expired backup --列出失效的备份
list expired backup of archivelog all --列出失效的归档日志备份
list expired backup of archivelog
until sequence 5 --列出指定序列号的失效归档日志备份
list expired backup of archivelog
until time "to_date('2012-6-30','yyyy-mm-dd')"
--列出指定时间的失效归档日志备份备份
list copy --列出映像文件副本
list copy of database
list copy of tablespace emp
list copy of datafile 6
list copy of archivelog all
list copy of controfile
report schema
report need backup --列出需要备份的
report need backup days 2 database --列出超过2天没有备份的
mount状态下
list incarnation;
reset database to incarnation 980;
--删除失效文件
删除失效备份
crosscheck backup(copy,archivelog all);
delete expired backup(copy,archivelog all);
删除失效日志
crosscheck archivelog all;
delete expired archivelog all;
crosscheck backup of tablespace sysaux --检查表空间备份
crosscheck backup of datafile 2 --检查数据文件2备份
crosscheck backup of controlfile --检查控制文件备份
crosscheck backup of spfile --检查spfile
crosscheck backup of copy --检查copy
crosscheck backup completed after 'sysdate-2' --当前时间前2天的备份
crosscheck copy of database
crosscheck copy of tablespace emp
crosscheck copy of controlfile
crosscheck copy of spfile
list backup summary --获得主键
validate backupset 16 --验证备份集16的有效性
change --修改备份状态
change backupset 16 unavailable
change backupset 16 available
change archivelog '/u01/backup/rman/***.log' unavailable
change backupset 16 delete --删除备份集16(同步删除)
delete expired backupset(archivelog all); --删除失效
delete expired --删除失效备份
delete obsolete --删除旧于备份策略日期(过期)的备份
--恢复检查
restore database validate;
validate backupset 218;
restore database preview;
restore tablespace users preview;
restore datafile 5 preview;
--命令块
run{
2> shutdown immediate;
3> startup mount;
4> allocate channel d1 type disk;
5> backup as backupset database
6> format='/u01/backup/rman/%d_%T.bak';
7> alter database open;
8> sql 'alter system archive log current';
9> }
select * from v$log;
select * from v$archived_log;
select * from v$backup_redolog;
--恢复顾问
list failure --诊断错误
advise failure --建议
repair failure --修复(数据文件和控制文件)
--rman下对数据文件重命名
run{
2> sql 'alter tablespace test_user offline';
3> set newname for datafile '/u01/app/oracle/oradata/test_user.dbf'
4> to '/u01/app/oracle/oradata/test_user01.dbf';
5> restore tablespace test_user;
6> switch datafile all;
7> recover tablespace test_user;
8> sql 'alter tablespace test_user online';
}
--rman下对数据文件移动
run{
2> sql 'alter tablespace test_user offline';
3> set newname for datafile '/u01/app/oracle/oradata/test_user01.dbf'
4> to '/u01/app/oracle/oradata/dbtest/test_user01.dbf';
5> restore tablespace test_user;
6> switch datafile all;
7> recover tablespace test_user;
8> sql 'alter tablespace test_user online';
}

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

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

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

The function in Oracle to calculate the number of days between two dates is DATEDIFF(). The specific usage is as follows: Specify the time interval unit: interval (such as day, month, year) Specify two date values: date1 and date2DATEDIFF(interval, date1, date2) Return the difference in days

The Oracle database startup sequence is: 1. Check the preconditions; 2. Start the listener; 3. Start the database instance; 4. Wait for the database to open; 5. Connect to the database; 6. Verify the database status; 7. Enable the service (if necessary ); 8. Test the connection.

The INTERVAL data type in Oracle is used to represent time intervals. The syntax is INTERVAL <precision> <unit>. You can use addition, subtraction, multiplication and division operations to operate INTERVAL, which is suitable for scenarios such as storing time data and calculating date differences.

To find the number of occurrences of a character in Oracle, perform the following steps: Get the total length of a string; Get the length of the substring in which a character occurs; Count the number of occurrences of a character by subtracting the substring length from the total length.

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

The method of replacing strings in Oracle is to use the REPLACE function. The syntax of this function is: REPLACE(string, search_string, replace_string). Usage steps: 1. Identify the substring to be replaced; 2. Determine the new string to replace the substring; 3. Use the REPLACE function to replace. Advanced usage includes: multiple replacements, case sensitivity, special character replacement, etc.
