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,如需转载请自行联系原作者
目录
相关文章
|
8天前
|
缓存 监控 Shell
使用 HBase Shell 进行数据的实时监控和备份
使用 HBase Shell 进行数据的实时监控和备份
|
15天前
|
JavaScript 前端开发 Shell
Shell 脚本编程保姆级教程(上)
Shell 脚本编程保姆级教程(上)
|
10天前
|
Shell Linux C语言
|
12天前
|
Shell 网络安全
shell脚本 配饰ssh
【7月更文挑战第15天】
16 4
|
16天前
|
网络协议 Shell Linux
Shell脚本配置Centos静态ip地址
这是一个用于在CentOS上设置静态IP的Shell脚本摘要: - 脚本交互式获取用户输入的IP地址、子网掩码、网关和DNS。 - 使用`sed`命令动态更新`/etc/sysconfig/network-scripts/ifcfg-ENS33`配置文件。 - 修改`BOOTPROTO`为`static`,并设置IP、NETMASK、GATEWAY和DNS1字段。 - 用`systemctl restart network`重启网络服务。 - 提示用户新配置的静态IP信息。
|
15天前
|
Shell
Shell 脚本编程保姆级教程(下)
Shell 脚本编程保姆级教程(下)
|
22天前
|
Shell Linux
Linux Shell 脚本入门教程:开启你的自动化之旅
Shell是一种计算机程序,它充当了用户与操作系统之间的接口。在Linux系统中,Shell允许用户通过命令行界面(CLI)来控制计算机。Shell脚本则是一种使用Shell语言编写的脚本,它可以自动执行一系列的命令,帮助用户实现任务自动化,提高工作效率。
|
28天前
|
Shell
蓝易云 - 简单shell脚本的编写教程
以上就是编写一个基本Shell脚本的步骤。当然,Shell脚本可以做的远不止这些,你可以使用变量,控制结构(如if语句和循环),以及各种Shell命令和功能来编写更复杂的脚本。
25 1
|
1月前
|
监控 Shell Linux
Linux的Shell脚本详解
Linux的Shell脚本详解
|
1月前
|
Shell
shell脚本
shell脚本
23 2