search
HomeDatabaseMysql TutorialOracle备份工具、文件命名格式、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 [CLEAR];此命令用于将指定的表空间不备份到备份集中, 此命令对只读表空间是非常有用的。

--修改保存天数
  用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';
}

 

Statement
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
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

See all articles

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

MantisBT

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.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

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),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version