备份脚本

#############################

[oracle@rac02 backup_scripts]$ cat rman_bus_level_0_bk.sh
###########################
##  rman_bus_level_0_bk.sh      ##
##        2014-04-02              ##
###########################

#!/bin/sh

# ---------------------------------------------------------------------------
# Oracle home path.
# ---------------------------------------------------------------------------
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_HOME
# ---------------------------------------------------------------------------
# the Oracle SID of the target database.
# ---------------------------------------------------------------------------
ORACLE_SID=bus
export ORACLE_SID
# ---------------------------------------------------------------------------
# the RMAN_LOG_FILE.
# ---------------------------------------------------------------------------
dt=`date +%Y%m%d`;
backDest=/mnt/bak
RMAN_LOG_FILE=$backDest/rman_bus_dest/bus_level_0_bk_$dt.log
# ---------------------------------------------------------------------------
# Set the Oracle Recovery Manager name.
# ---------------------------------------------------------------------------
RMAN=$ORACLE_HOME/bin/rman

$RMAN nocatalog target /  log $RMAN_LOG_FILE append <<-EOF
RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;

backup incremental level 0 DATABASE FORMAT '$backDest/rman_bus_dest/db_level_0_%U_%T' skip inaccessible    TAG='inc_level_0';

sql 'alter system archive log current';

backup FORMAT '$backDest/rman_bus_dest/arch_%U_%T' skip inaccessible  ARCHIVELOG ALL tag='bus_arch' DELETE ALL INPUT;
backup current controlfile tag='bus_ctl' format='$backDest/rman_bus_dest/ctl_%U_%T';
#backup spfile tag='bus_spfile' format='$backDest/rman_bus_dest/spfile_%U_%T';

release channel c2;
release channel c1;
}
crosscheck backup;
delete noprompt obsolete;
delete noprompt expired backup;
list backup summary;
EOF
#
# Let's delete the redundancy backup logs
#

find $backDest/rman_bus_dest  -type f -mtime +0  -name "*.log"  -exec rm {} \;

#############################

# ---------------------------------------------------------------------------
# Oracle home path.
# ---------------------------------------------------------------------------
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_HOME
# ---------------------------------------------------------------------------
# the Oracle SID of the target database.
# ---------------------------------------------------------------------------
export ORACLE_SID=bus
# ---------------------------------------------------------------------------
# the RMAN_LOG_FILE.
# ---------------------------------------------------------------------------
date=`date +%Y%m%d`
backDest=/mnt/bak
RMAN_LOG_FILE=$backDest/rman_bus_dest/bus_level_2_bk_$date.log
# ---------------------------------------------------------------------------
# Set the Oracle Recovery Manager name.
# ---------------------------------------------------------------------------
RMAN=$ORACLE_HOME/bin/rman

$RMAN nocatalog target /  log $RMAN_LOG_FILE append <<-EOF
RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;

backup incremental level 2 DATABASE FORMAT '$backDest/rman_bus_dest/db_level_2_%U_%T' skip inaccessible    TAG='inc_level_2';

sql 'alter system archive log current';

backup FORMAT '$backDest/rman_bus_dest/arch_%U_%T' skip inaccessible  ARCHIVELOG ALL tag='bus_arch' DELETE ALL INPUT;
backup current controlfile tag='bus_ctl' format='$backDest/rman_bus_dest/ctl_%U_%T';
#backup spfile tag='bus_spfile' format='$backDest/rman_bus_dest/spfile_%U_%T';
release channel c2;
release channel c1;
}
#report obsolete;
#delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
list backup summary;
EOF

#############################

Rman的format格式中的%
%c 备份片的拷贝数
%d 数据库名称
%D 位于该月中的第几天 (DD)
%M 位于该年中的第几月 (MM)
%F 一个基于DBID唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII为该数据库的DBID,YYYYMMDD为
日期,QQ是一个1-256的序列
%n 数据库名称,向右填补到最大八个字符
%u 一个八个字符的名称代表备份集与创建时间
%p 该备份集中的备份片号,从1开始到创建的文件数
%U 一个唯一的文件名,代表%u_%p_%c
%s 备份集的号
%t 备份集时间戳
%T 年月日格式(YYYYMMDD)

#############################

下面是两种连接方式
[oracle@oracle3A ~]$ rman target/ Recovery Manager: Release 11.2.0.1.0 - Production on Mon Feb 22 16:59:59 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: FLT (DBID=4164685130) RMAN> [oracle@oracle3A ~]$ rman Recovery Manager: Release 11.2.0.1.0 - Production on Mon Feb 22 17:00:57 2016 Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved. RMAN> connect target connected to target database: FLT (DBID=4164685130) SQL> select dbid from v$database;       DBID
----------
4158553139
RMAN> show all;

RMAN configuration parameters for database with db_unique_name FLT are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
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 COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/oracle3A/product/11.2.0/dbhome_1/dbs/snapcf_flt.f'; # default

http://blog.chinaunix.net/uid-17240229-id-306718.html

把归档日志的物理文件删除后,我们就可以正常登入ORACLE了,但是还没完全把归档日志删除干净,ORACLE的controlfile中仍然记录着这些archivelog的信息,在oracle的OEM管理器中有可视化的日志展现出,当我们手工清除archive目录下的文件后,这些记录并没有被我们从controlfile中清除掉,接下去我们要做的就是这个工作。
我们利用RMAN进行删除操作,

两种方式:

1、先查看使用率,再删除物理文件,再用rman删除。
SQL> select * from V$FLASH_RECOVERY_AREA_USAGE;
[oracle@stdg archivelog]$ pwd
/u01/app/oracle/fast_recovery_area/STDGGT/archivelog
[oracle@stdg archivelog]$ rm -rf 2016_11_22
[oracle@stdg archivelog]$ rman target /
RMAN> list archivelog all;
RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-6';
上面直接不能删除,需要先用下面的命令,然后才能删除。
RMAN> crosscheck archivelog all;
RMAN> delete expired archivelog all;
SQL> select * from V$FLASH_RECOVERY_AREA_USAGE;
用上面的sql查看文件数量与容量大小相应的减少了。

2、先查看使用率,直接用rman删除。
SQL> select * from V$FLASH_RECOVERY_AREA_USAGE;
[oracle@stdg archivelog]$ pwd
/u01/app/oracle/fast_recovery_area/STDGGT/archivelog
[oracle@stdg archivelog]$ rman target /
RMAN> list archivelog all;
RMAN> delete archivelog until time 'sysdate-5';
RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-6';
SQL> select * from V$FLASH_RECOVERY_AREA_USAGE;

SYSDATE-7,表明当前的系统时间7天前,before关键字表示在7天前的归档日志,如果使用了闪回功能,也会删除闪回的数据。
同样道理,也可以删除从7天前到现在的全部日志,不过这个命令要考虑清楚,做完这个删除,最好马上进行全备份数据库
DELETE ARCHIVELOG from TIME 'SYSDATE-7'; 删除从7天前到现在的全部日志,慎用
UNIX/LINUX下也可以通过FIND找到7天前的归档数据,使用EXEC子操作删除
find /oraarchive -xdev -mtime +7 -name "*.dbf" -exec rm -f {} ;
这样做仍然会在RMAN里留下未管理的归档文件
仍需要在RMAN里执行下面2条命令
crosscheck archivelog all;
delete expired archivelog all;
所以还不如上面的方法好用,不过用FIND的好处就是,可以在条件上,和EXEC子项上做很多操作,实现更复杂的功能

RMAN> shutdown immediate;

using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down RMAN> startup mount connected to target database (not started)
Oracle instance started
database mounted Total System Global Area 3106619392 bytes Fixed Size 2257272 bytes
Variable Size 2768244360 bytes
Database Buffers 318767104 bytes
Redo Buffers 17350656 bytes RMAN> backup database format '/u01/app/oracle/full%U.bak'; Starting backup at 12-JAN-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1885 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/DFLCP
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 12-JAN-17
RMAN> backup as copy database;

Starting backup at 01-FEB-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=23 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=+DATA1/orcl/datafile/system.256.934287737
output file name=+FRA/orcl/datafile/system.261.934824851 tag=TAG20170201T173411 RECID=2 STAMP=934824856
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=+DATA1/orcl/datafile/sysaux.257.934287737
output file name=+FRA/orcl/datafile/sysaux.262.934824859 tag=TAG20170201T173411 RECID=3 STAMP=934824862
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=+DATA1/orcl/datafile/example.269.934287837
output file name=+FRA/orcl/datafile/example.263.934824865 tag=TAG20170201T173411 RECID=4 STAMP=934824866
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=+DATA1/orcl/datafile/undotbs1.258.934287737
output file name=+FRA/orcl/datafile/undotbs1.256.934824867 tag=TAG20170201T173411 RECID=5 STAMP=934824868
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=+FRA/orcl/controlfile/backup.257.934824871 tag=TAG20170201T173411 RECID=6 STAMP=934824870
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=+DATA1/orcl/datafile/users.259.934287737
output file name=+FRA/orcl/datafile/users.258.934824871 tag=TAG20170201T173411 RECID=7 STAMP=934824871
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 01-FEB-17
channel ORA_DISK_1: finished piece 1 at 01-FEB-17
piece handle=+FRA/orcl/backupset/2017_02_01/nnsnf0_tag20170201t173411_0.264.934824873 tag=TAG20170201T173411 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 01-FEB-17 RMAN> delete obsolete;
using target database control file instead of recovery catalog
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=26 device type=DISK
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set 2 01-FEB-17
Backup Piece 2 01-FEB-17 +FRA/orcl/backupset/2017_02_01/ncsnf0_tag20170201t122244_0.260.934806193 Do you really want to delete the above objects (enter YES or NO)? y
deleted backup piece
backup piece handle=+FRA/orcl/backupset/2017_02_01/ncsnf0_tag20170201t122244_0.260.934806193 RECID=2 STAMP=934806192
Deleted 1 objects ############
report命令
RMAN> report schema; Report of database schema for database with db_unique_name ORCL List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 750 SYSTEM *** +DATA1/orcl/datafile/system.256.934287737
2 550 SYSAUX *** +DATA1/orcl/datafile/sysaux.257.934287737
3 100 UNDOTBS1 *** +DATA1/orcl/datafile/undotbs1.258.934287737
4 5 USERS *** +DATA1/orcl/datafile/users.259.934287737
5 313 EXAMPLE *** +DATA1/orcl/datafile/example.269.934287837 List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 29 TEMP 32767 +DATA1/orcl/tempfile/temp.268.934287837

RMAN> report need backup database;

using target database control file instead of recovery catalog
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of files with less than 1 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------
1    0     /u01/app/oracle/oradata/testdb/system01.dbf
2    0     /u01/app/oracle/oradata/testdb/sysaux01.dbf
3    0     /u01/app/oracle/oradata/testdb/undotbs01.dbf
4    0     /u01/app/oracle/oradata/testdb/users01.dbf
5    0     /u01/app/oracle/oradata/testdb/lcpsys.dbf
6    0     /u01/app/oracle/oradata/testdb/monitor.dbf

RMAN> report obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
no obsolete backups found

RMAN> report need backup database;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
Report of files with less than 1 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------

RMAN> report unrecoverable;

Report of files that need backup due to unrecoverable operations
File Type of Backup Required Name
---- ----------------------- -----------------------------------

############

list命令

RMAN> list copy;

List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time
------- ---- - --------------- ---------- ---------------
2       1    A 01-FEB-17       1084830    01-FEB-17
        Name: +FRA/orcl/datafile/system.261.934824851
        Tag: TAG20170201T173411

3       2    A 01-FEB-17       1084836    01-FEB-17
        Name: +FRA/orcl/datafile/sysaux.262.934824859
        Tag: TAG20170201T173411

5       3    A 01-FEB-17       1084840    01-FEB-17
        Name: +FRA/orcl/datafile/undotbs1.256.934824867
        Tag: TAG20170201T173411

7       4    A 01-FEB-17       1084843    01-FEB-17
        Name: +FRA/orcl/datafile/users.258.934824871
        Tag: TAG20170201T173411

4       5    A 01-FEB-17       1084839    01-FEB-17
        Name: +FRA/orcl/datafile/example.263.934824865
        Tag: TAG20170201T173411

List of Control File Copies
===========================

Key     S Completion Time Ckp SCN    Ckp Time
------- - --------------- ---------- ---------------
6       A 01-FEB-17       1084841    01-FEB-17
        Name: +FRA/orcl/controlfile/backup.257.934824871
        Tag: TAG20170201T173411

List of Archived Log Copies for database with db_unique_name ORCL
=====================================================================

Key     Thrd Seq     S Low Time
------- ---- ------- - ---------
4       1    11      A 01-FEB-17
        Name: +FRA/orcl/archivelog/2017_02_01/thread_1_seq_11.259.934826715

RMAN> list backup;

List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3       Full    80.00K     DISK        00:00:00     01-FEB-17
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20170201T173411
        Piece Name: +FRA/orcl/backupset/2017_02_01/nnsnf0_tag20170201t173411_0.264.934824873
  SPFILE Included: Modification time: 01-FEB-17
  SPFILE db_unique_name: ORCL

rman的使用的更多相关文章

  1. RMAN异机恢复快速参考

    应用场景:服务器A为正常运行的生产环境,需要在服务器B上部署一套相同环境做测试. 数据库环境:RHEL6.4 + Oracle 11.2.0.4.7 一. 服务器A备份数据库 1.1 在线备份(数据库 ...

  2. 用RMAN备份EBS数据库的脚本

    rman_bak.sh rman target / nocatalog log=/d01/rmanbak/bak_`date +%m%d%H%M`.log<< EOF  run  {  c ...

  3. RAC+asm通过rman恢复到单实例+asm

    1.恢复参数文件,并修改参数文件 参数文件指名几个最简单的就行,我的参数文件如下: 2.恢复控制文件,并启动数据库到mount 如果是把备份集从别的服务器拷贝到本地恢复的服务器的目录,使用下面的语句指 ...

  4. RMAN Catalog创建、配置和管理

    环境:RHEL6.4 + Oracle 11.2.0.4 一.创建数据库catdb 1.1 官档的建库脚本示例 1.2 根据我实际环境修改如下项 1.3 创建必要目录并赋予权限 1.4 执行脚本建库 ...

  5. 使用RMAN创建复制数据库

    我的实验环境: - 源数据库A机: RHEL6.4 + Oracle 11.2.0.4 IP地址:192.168.99.159 db_name=oradb 数据库已正常运行 - 复制数据库B机: RH ...

  6. DG环境数据库RMAN备份策略制定

    DG环境数据库RMAN备份策略制定: 主库(Primary) 全库备份 归档备份 删除历史文件夹 备库(Standby) 删除归档 引用说明 主库(Primary) $ crontab -l 0 1 ...

  7. 记录一则RMAN备份策略修正案例

    背景:在给某客户处理问题时,发现客户数据库的备份空间即将用尽,进一步查看发现是用户数据库的当前RMAN备份策略存在潜在问题,需要修改备份策略. 环境:SunOS 5.10 + Oracle 11.2. ...

  8. RMAN异机恢复遭遇ORA-01547、ORA-01152、ORA-01110错误案例

    测试环境:     操作系统  :  Red Hat Enterprise Linux ES release 4 (Nahant Update 4)   VMWARE     数据库     :  O ...

  9. RMAN异机还原遭遇ORA-19698错误案例

    实验环境:               操作系统    :Oracle Linux Server release 5.7 64 bit               数据库版本:Oracle Datab ...

  10. RMAN备份脚本一列分享

    在ORACLE数据库中,RMAN备份的脚本非常多,下面介绍一例shell脚本如何通过RMAN备份,以及FTP上传RMAN备份文件以及归档日志文件的脚本. fullback.sh 里面调用RMAN命令做 ...

随机推荐

  1. Spring MVC配置文件解释

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  2. KeySweeper 微软无线键盘嗅探装置

    Author:Samy Kamkar From: http://samy.pl/keysweeper/ 中文字幕由Galaxy无名提供 PS:视频传到youku之后发现50秒左右的字幕被干掉了,不知道 ...

  3. Android Priority Job Queue (Job Manager):后台线程任务结果传回前台(三)

     Android Priority Job Queue (Job Manager):后台线程任务结果传回前台(三) 在附录文章4,5的基础上改造MainActivity.java和MyJob.ja ...

  4. 破解 crackme(完全拆解警告窗口)

    系统 : Windows xp 程序 : crackme 程序下载地址 :http://pan.baidu.com/s/1kUrbcAr 要求 : 注册机编写 & 去除Nag窗口 使用工具 : ...

  5. python学习札记(1)

    首先给大家推荐一个很好的python入门网站,感觉比<python基础>之类的书更容易懂,廖雪峰小站,希望有学习资源同学们也能多多交流.下面是今天所学: 下面总结一些非常有特色的函数及其应 ...

  6. 换个心境搞IT,在IT职场如何打拼?

    刚进入IT这行时,我也是从程序员做起.尤其是前两三个月里,那种感觉就像时时刻刻处于备战状态一样.我是一个在对自己的要求方面有洁癖的人,在没有任何经验的状态下,只有坚持苦干,把下发的每件编程任务做好,才 ...

  7. java学习第八天

    第九次课 目标 1.  多态 2.  抽象类 3.  接口 4.  内部类(了解) 一.多态polymorphism 追求”高内聚低耦合”通过三大特性: 封装继承及多态来实现. 多态:多种形态,”出去 ...

  8. Golang 交叉编译

    各平台的GOOS和GOARCH参考 OS ARCH OS version linux 386 / amd64 / arm >= Linux 2.6 darwin 386 / amd64 OS X ...

  9. LeetCode Binary Tree Postorder Traversal(数据结构)

    题意: 用迭代法输出一棵二叉树的后序遍历结果. 思路: (1)用两个栈,一个存指针,一个存标记,表示该指针当前已经访问过哪些孩子了. /** * Definition for a binary tre ...

  10. Exploratory Software Testing

    最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...