RMAN 备份案例-shell 脚本

简介:

RMAN 备份案例-shell 脚

通过shell 结合RMAN建立数据库的备份,可以简化数据库备份的工作,以下为一个备份案例:


系统环境:

操作系统:RedHat EL6

Oracle: Oracle 11gR2


    本方案结合RMAN的Catalog DB建立备份,通过Catalog DB可以很方便的存储RMAN的备份脚本,方便备份的调用。

wKiom1M71mezn-CXAAA5zhzok5U009.jpg

备份案例:

wKioL1M72YXxCwy5AAA6yed68bw808.jpg

1、删除obsolete bakcup script

------按照备份保留策略,删除recovery windows 15 天以上的备份(obsolete)

create global script global_del_obso comment 'A script for obsolete backup and delete it'

{

crosscheck archivelog all;

delete noprompt expired archivelog all;

allocate channel ch1 device type disk;

delete noprompt obsolete recovery window of 15 days;

release channel ch1;

}

2、backup controlfile script

------备份控制文件

create global script global_bkctl comment 'A script for backup control file'

{

allocate channel ch1 device type disk;

backup as compressed backupset

current controlfile reuse

format='/dsk4/backup/backupctl.ctl'

tag='bkctl';

release channel ch1;

}


3、backup archivelog script

-----备份归档日志

create global script global_arch comment "backup archivelog and then delete it" {

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

sql "alter system archive log current";

set limit channel ch1 readrate=10240;

set limit channel ch1 kbytes=4096000;

set limit channel ch2 readrate=10240;

set limit channel ch2 kbytes=4096000;

backup as compressed backupset

format='/dsk4/backup/arch_%d_%U'

tag='bkarch'

archivelog all delete input;

release channel ch1;

release channel ch2;

}


   对于数据文件建立增量备份

4、backup datafile script(level 0)

------增量备份 0级

create global script global_inc0 comment "backup database as incrmental level 0"{

execute global script global_del_obso;

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

set limit channel ch1 readrate=10240;

set limit channel ch1 kbytes=4096000;

set limit channel ch2 readrate=10240;

set limit channel ch2 kbytes=4096000;

backup as compressed backupset

incremental level 0 database

format='/dsk4/backup/inc0_%d_%U'

tag='inc0';

release channel ch1;

release channel ch2;

execute global script global_arch;

execute global script global_bkctl;

}

5、backup datafile script(level 1)

------差异备份 1级

create global script global_inc1 comment "backup database as incrmental level 1"{

execute global script global_del_obso;

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

set limit channel ch1 readrate=10240;

set limit channel ch1 kbytes=4096000;

set limit channel ch2 readrate=10240;

set limit channel ch2 kbytes=4096000;

backup as compressed backupset

incremental level 1 database

format='/dsk4/backup/inc1_%d_%U'

tag='inc1';

release channel ch1;

release channel ch2;

execute global script global_arch;

execute global script global_bkctl;

}

6、backup datafile script(level 1 cumulative)

----累积增量备份 1级

create global script global_inc1_cu comment "backup database as incrmental cumulative level 1"{

execute global script global_del_obso;

allocate channel ch1 device type disk;

allocate channel ch2 device type disk;

set limit channel ch1 readrate=10240;

set limit channel ch1 kbytes=4096000;

set limit channel ch2 readrate=10240;

set limit channel ch2 kbytes=4096000;

backup as compressed backupset

incremental  level 1 cumulative database

format='/dsk4/backup/inc1_%d_%U'

tag='inc1';

release channel ch1;

release channel ch2;

execute global script global_arch;

execute global script global_bkctl;

}


7、list scripts

------查看catalog 库里的备份脚本


RMAN> list script names;


List of Stored Scripts in Recovery Catalog



   Global Scripts



      Script Name

      Description

      -----------------------------------------------------------------------

      global_arch

      backup archivelog and then delete it


      global_bkctl

      A script for backup control file


      global_del_obso

      A script for obsolete backup and delete it


      global_inc0

      backup database as incrmental level 0


      global_inc1

      backup database as incrmental level 1


      global_inc1_cu

      backup database as incrmental cumulative level 1


RMAN>


8、test scripts


------测试执行备份脚本


run{

execute global script global_inc0;

execute global script global_inc1;

execute global script global_inc1_cu;

}


9、建立RMAN连接Tartget DB和Catalog DB脚本及备份脚本


1、连接 target and  catalog db


[oracle@rh6 script]$ cat connect.rcv

connect target sys/oracle@test1;

connect catalog rman/rman@cuug;


2、连接到target and catalog db ,执行备份


[oracle@rh6 script]$ cat inc0.rcv

@@/home/oracle/script/connect.rcv

run{

execute global script global_inc0;

}


[oracle@rh6 script]$ cat inc1.rcv

@@/home/oracle/script/connect.rcv

run{

execute global script global_inc1;

}


[oracle@rh6 script]$ cat inc1_cu.rcv

@@/home/oracle/script/connect.rcv

run{

execute global script global_inc1_cu;

}


[oracle@rh6 script]$


10、shell 备份脚本


[oracle@rh6 script]$ cat inc0.sh

nohup $ORACLE_HOME/bin/rman cmdfile=/home/oracle/script/inc0.rcv log=/home/oracle/script/inc0.log append &

[oracle@rh6 script]$ cat inc1.sh

nohup $ORACLE_HOME/bin/rman cmdfile=/home/oracle/script/inc1.rcv log=/home/oracle/script/inc1.log append &

[oracle@rh6 script]$ cat inc1_cu.sh

nohup $ORACLE_HOME/bin/rman cmdfile=/home/oracle/script/inc1_cu.rcv log=/home/oracle/script/inc1_cu.log append &


11、crontab 备份计划

[oracle@rh6 script]$ crontab -l

0 0 * * 0 sh /home/oracle/script/inc0.sh

0 0 * * 1 sh /home/oracle/script/inc1.sh

0 0 * * 2 sh /home/oracle/script/inc1.sh

0 0 * * 3 sh /home/oracle/script/inc1.sh

0 0 * * 4 sh /home/oracle/script/inc1_cu.sh

0 0 * * 5 sh /home/oracle/script/inc1.sh

0 0 * * 6 sh /home/oracle/script/inc1.sh










本文转自 客居天涯 51CTO博客,原文链接:http://blog.51cto.com/tiany/1389244,如需转载请自行联系原作者
目录
相关文章
|
6天前
|
分布式计算 Hadoop Shell
使用shell脚本实现自动SSH互信功能
使用shell脚本实现自动SSH互信功能
16 1
|
6天前
|
Unix Shell Linux
轻松编写 AIX Shell 脚本
轻松编写 AIX Shell 脚本
14 1
|
6天前
|
监控 关系型数据库 Shell
Shell脚本入门:从基础到实践,轻松掌握Shell编程
Shell脚本入门:从基础到实践,轻松掌握Shell编程
|
6天前
|
关系型数据库 MySQL Shell
在Centos7中利用Shell脚本:实现MySQL的数据备份
在Centos7中利用Shell脚本:实现MySQL的数据备份
|
6天前
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
30 5
|
6天前
|
Shell 程序员 数据安全/隐私保护
shell 脚本 if-else判断 和流程控制 (基本语法|基础命令)
shell 脚本 if-else判断 和流程控制 (基本语法|基础命令)
|
6天前
|
存储 Shell C语言
shell脚本 编程 变量 基本入门(详解)
shell脚本 编程 变量 基本入门(详解)
|
6天前
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
16 3
|
6天前
|
弹性计算 运维 监控
|
6天前
|
存储 弹性计算 运维
自动化收集员工信息的Shell脚本
【4月更文挑战第30天】
14 0