码迷,mamicode.com
首页 > 其他好文 > 详细

rman备份/恢复

时间:2018-10-22 14:54:50      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:sequence   时间格式   configure   format   recover   keep   product   locate   并且   

全备脚本

cat rman_full.sh

#!/bin/bash
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export PATH=$ORACLE_HOME/bin:$PATH
rman target / log /opt/oracle/backup/rman_full.log append<<EOF
run
{allocate channel c1 type disk;
allocate channel c2 type disk;
backup database filesperset 4 format /opt/oracle/backup/full_%d_%T_%s_%p;
sql alter system archive log current;
backup archivelog all format /opt/oracle/backup/arch_%d_%T_%s_%p delete input;
backup current controlfile format /opt/oracle/backup/ctl_%d_%T_%s_%p;
crosscheck backup;
crosscheck archivelog all;
delete noprompt obsolete;
delete noprompt  expired backup;
delete noprompt  expired archivelog all;
}
EOF

 

增备脚本

[root@centos74 /opt/sh 12:00:58&&14]#cat rman_arch.sh 
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export PATH=$ORACLE_HOME/bin:$PATH
rman target / log /opt/oracle/backup/rman_arch.log append<<EOF
run
{allocate channel c1 type disk;
allocate channel c2 type disk;
sql alter system archive log current;
backup archivelog all format /opt/oracle/backup/arch_%d_%T_%s_%p delete input;
backup current controlfile format /opt/oracle/backup/ctl_%d_%T_%s_%p;
crosscheck backup;
crosscheck archivelog all;
delete noprompt  expired backup;
delete  noprompt expired archivelog all;
}
EOF

 

恢复脚本

export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export PATH=$ORACLE_HOME/bin:$PATH
rman target / log /opt/oracle/backup/rman_arch.log append<<EOF
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
sql alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss";
set until time = 2011-10-19 22:21:38;
restore database;
recover database;
alter database open resetlogs;
}
EOF

rman备份/恢复步聚 

rman备份步聚

准备工作
1.control_file_record_keep_time初始化参数
rman元数据在控制文件中保留的最小有效天数,默认为7天(即备份数据不能超过7天不然,数据会丢失)
$ sqlplus / as sysdba
SQL> alter system set control_file_record_keep_time=30;
SQL> show parameter control;

2.启动归档模式
$ mkdir -p /opt/oracle/archdata #创建归档日志存放目录
$ sqlplus / as sysdba
SQL> archive log list;  #查看归档日志状态
Database log mode           No Archive Mode     
Automatic archival           Disabled    #关闭
Archive destination           /opt/oracle/archdata
Oldest online log sequence     3
Current log sequence           5

SQL> alter system set log_archive_dest_1=location=/opt/oracle/archdata scope=both; #更改归档日志存放目录
SQL> select dest_name,destination,status,error from v$archive_dest where dest_name=LOG_ARCHIVE_DEST_1; #查看归档日志存放目录

重启数据库mount状态,开启归档(凡是alter database操作都是修改“控制文件”内容)
SQL> shutdown immediate; #关闭数据库
SQL> startup mount;      #启动数据库到mount模式
SQL> alter database archivelog; #开启归档模式
SQL> alter database open;       #启动数据库

SQL> alter system switch logfile;  # 刚刚开启归档还没有生成日志,我们手工切换一下
SQL>  select sequence#,name,archived,applied from v$archived_log;    # 数据库层查看归档日志文件

rman备份注意事项
1备份顺序
备份数据--》备份归档数据--》份控制文件

2.备份要有日志信息
rman target / log /tmp/rman_full.log  #登陆rman,把输出日志重定向到/tmp/rman_full.log

RMAN环境变量设置
rman target /
show all;  #查看所有配置
#默认配置保留策略是一个备份
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
#配置恢复期窗口是90天,意思就是能够恢复到这90天中的任意一天,那么要求就是最少保留一个90天之前的备份
并且有自那之后产生的所有归档日志
CONFIGURE RETENTION POLICY TO recovery window of  90 days;
CONFIGURE RETENTION POLICY clear;
#备份的设备类型默认是disk,磁盘类型,
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
#这个是备份为磁带类型
CONFIGURE DEFAULT DEVICE TYPE TO stb;
#自动备份控制文件
CONFIGURE CONTROLFILE AUTOBACKUP ON;

备份
请查看全量备份脚本

 

rman恢复控制文件

sqlplus / as sysdba;
SQL> shutdown immediate;
SQL> startup mount; 
rman target /
RMAN> list backupset;
RMAN> restore controlfile from xxxxx;  #xxxx是控制文件路径

 

rman恢复数据到指定时间点

原文地址: https://blog.csdn.net/u011364306/article/details/50013607

1.修改数据库时间格式
SQL> alter session set nls_date_format=yyyy-mm-dd hh24:mi:ss;
2.查看数据库时间
SQL> select sysdate from dual;
3.关闭数据库并启动到mount模式
SQL> shutdown immediate;
SQL>startup mount;

4.恢复数据库
请看恢复脚本

 

rman备份/恢复

标签:sequence   时间格式   configure   format   recover   keep   product   locate   并且   

原文地址:https://www.cnblogs.com/hanxiaohui/p/9829397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!