RMAN 备份案例-shell 脚本

RMAN 备份案例-shell 脚

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


系统环境:

操作系统:RedHat EL6

Oracle: Oracle 11gR2


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

RMAN 备份案例-shell 脚本

备份案例:

RMAN 备份案例-shell 脚本

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,如需转载请自行联系原作者
上一篇:iOS开发系列----OC(文件管理类、文件句柄类)


下一篇:css:垂直方向外边距margin塌陷问题及解决