rman備份/恢復

全備腳本

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
shutdown immediate;
startup mount; 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.恢復數據庫 請看恢復腳本
相關文章
相關標籤/搜索