rman全库备份――shell脚本实施方案

时间:2022-09-23 15:15:56

     rman是oracle的一个强大的工具,工作经验积累,直奔主题,如何使用rman工具进行脚本全库备份。

1.建立rman表空间

    SQL> create tablespace rman 

         2  logging datafile '/opt/oracle/oradata/rman/rman.dbf' size 1024M

         3  extent management local segment space management auto;

2.创建rman备份账号

    SQL> create user rman identified by rman default tablespace rman;

    SQL> grant connect,resource to rman;

    SQL> grant recovery_catalog_owner to rman;

    SQL> grant unlimited tablespace to rman;

    SQL> grant sysdba to rman;

3.查看日志是否归档

    SQL> archive log list;     

    Database log mode              Archive Mode

    Automatic archival             Enabled

    Archive destination            USE_DB_RECOVERY_FILE_DEST

    Oldest online log sequence     14

    Next log sequence to archive   16

    Current log sequence           16

4.建立catalog数据库及注册数据库

    oracle@linux-nao:~> rman catalog rman/rman

    Recovery Manager: Release 11.1.0.6.0 - Production on 星期三3月21           16:10:49 2012

    Copyright (c) 1982, 2007, Oracle.  All rights reserved.     connected to recovery catalog database          RMAN> create catalog tablespace "RMAN";     recovery catalog created     RMAN> exit

    oracle@linux-nao:~> rman target sys/oracle@orcl catalog rman/rman@orcl

    Recovery Manager: Release 11.1.0.6.0 - Production on 星期三3月21           16:20:34 2012

    Copyright (c) 1982, 2007, Oracle. All rights reserved.

    connected to target database: ORCL (DBID=1305015629)

    connected to recovery catalog database

    RMAN> register database; database registered in recovery catalog

    starting full resync of recovery catalog
    full resync complete

5.rman环境设置

   1) 设置保留30天的备份信息,

   RMAN> configure retention policy to recovery window of 30 days;

   new RMAN configuration parameters:

   CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;

   new RMAN configuration parameters are successfully stored

   starting full resync of recovery catalog

   full resync complete

   2) 启用控制文件自动备份及备份存放位置配置

   RMAN> configure controlfile autobackup on;

   new RMAN configuration parameters:

   CONFIGURE CONTROLFILE AUTOBACKUP ON;

   new RMAN configuration parameters are successfully stored

   starting full resync of recovery catalog

   full resync complete

6.查看配置信息

  RMAN> show all;

7.备份策略

  每周日00:00进行一次全库备份

  系统自动清除30天以前的备份信息

8.创建备份必要目录(以oracle身份创建)

  mkdir backup

  cd backup

  mkdir controlfileback 存放备份的控制文件

  mkdir dbback  存放备份的数据文件

  mkdir log     存放备份生成的日志,坚持该日志查看备份是否成功

  mkdir logback 存放归档日志文件

9.全库备份脚本dbback.sh

  
 
 
  1. #!/bin/bash 
  2. #this is rman auto full backup script 
  3. #Copyright by 21og 
  4. #date 2012-03-21 
  5. export ORACLE_SID=orcl 
  6. export ORACLE_HOME=/opt/oracle/product/10.2/db_1 
  7. export ORACLE_BASE=/opt/oracle 
  8. export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK" 
  9. backtime=`date +"20%y%m%d%H%M%S"
  10. cd $ORACLE_HOME/bin 
  11. rman target / catalog rman/rman log=/opt/oracle/backup/log/backupall_$backtime.log <<EOF 
  12. run{ 
  13. allocate channel c1 device type disk; 
  14. allocate channel c2 device type disk; 
  15. allocate channel c3 device type disk; 
  16. allocate channel c4 device type disk; 
  17. allocate channel c5 device type disk; 
  18. crosscheck backup; 
  19. sql 'alter system archive log current'
  20. backup database format '/opt/oracle/backup/dbback/db_%d_%T_%U'
  21. sql 'alter system archive log current'
  22. backup archivelog all format '/opt/oracle/backup/logback/arc_%t_%s' delete all input;  
  23. backup current controlfile format '/opt/oracle/backup/controlfileback/cntrl_%s_%p_%s'
  24. crosscheck archivelog all
  25. delete noprompt expired backup; 
  26. delete noprompt obsolete; 
  27. delete noprompt backup of database completed before 'sysdate - 30'
  28. release channel c1; 
  29. release channel c2; 
  30. release channel c3; 
  31. release channel c4; 
  32. release channel c5; 
  33. EOF 
  34. echo "backup complete!" 
10.crontab自动执行    1)以root身份编辑cron.allow文件,手动添加oracle用户允许使用cron服务。 启动cron服务 /etc/init.d/cron start

   2)以oracle身份执行crontab -e

       0 0 * * 0 /opt/oracle/backup/script/dbback.sh 2>&1 >/dev/null

OK,所有操作完毕,好累~~~

本文出自 “我就是我非此非彼” 博客,请务必保留此出处http://wukui127.blog.51cto.com/2866802/812761