点击有惊喜
前提:
数据库已开启归档:
SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/product/11.2.0/db_1/dbs/arch Oldest online log sequence 23 Next log sequence to archive 25 Current log sequence 25 SQL> |
一、 RMAN备份脚本
Level0备份脚本
vim rman_bak_level0.sh #! /bin/bash export ORACLE_BASE=$ORACEL_BASE export ORACLE_HOME=$ORACLE_HOME export PATH=$ORACLE_HOME/bin:$PATH export ORACLE_SID=orcl export NLS_ rman target / <<EOF run{ allocate channel c1 type disk; allocate channel c2 type disk; backup incremental level 0 database format '/u01/backup/level0_%d_%s_%p_%u.bak'; sql 'alter system archive log current'; backup archivelog all delete input format '/u01/backup/archivelog_%d_%s_%p_%u.bak'; crosscheck backup; delete noprompt obsolete; release channel c1; release channel c2; } >>EOF |
Level1备份脚本
vim rman_bak_level1.sh #! /bin/bash export ORACLE_BASE=$ORACLE_BASE export ORACLE_HOME=$ORACLE_HOME export PATH=$ORACLE_HOME/bin:$PATH export ORACLE_SID=orcl export NLS_ rman target / <<EOF run{ allocate channel c1 type disk; allocate channel c2 type disk; backup incremental level 1 database format '/u01/backup/level1_%d_%s_%p_%u.bak'; sql 'alter system archive log current'; backup archivelog all delete input format '/u01/backup/archivelog_%d_%s_%p_%u.bak'; crosscheck backup; delete noprompt obsolete; release channel c1; release channel c2; } >>EOF |
Level2备份脚本
vim rman_bak_level2.sh #! /bin/bash export ORACLE_SID=orcl export NLS_ $ORACLE_HOME/bin/rman target / <<EOF run{ allocate channel c1 type disk; allocate channel c2 type disk; backup incremental level 2 database format '/u01/backup/level2_%d_%s_%p_%u.bak'; sql 'alter system archive log current'; backup archivelog all delete input format '/u01/backup/archivelog_%d_%s_%p_%u.bak'; crosscheck backup; delete noprompt obsolete; release channel c1; release channel c2; } >>EOF |
二、备份数据库测试
1.执行0级备份
[[email protected] scripts]$ ll
total 12
-rwxr--r-- 1 oracle oinstall 600 Oct 18 12:46 rman_bak_level0.sh
-rwxr--r-- 1 oracle oinstall 600 Oct 18 12:46 rman_bak_level1.sh
-rwxr--r-- 1 oracle oinstall 532 Oct 18 12:46 rman_bak_level2.sh
[[email protected] scripts]$
[[email protected] scripts]$ sh rman_bak_level0.sh
查看备份日志,成功备份
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicWZwpmL1QDM3YjYjBjZjBTM5QmYhhTMxMjZxATOkhTYjFzM0UjM5UWM0UGZ38CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.jpeg)
2.创建表level0
SQL> create table level0 as select * from scott.emp;
Table created.
3.执行1级增量备份
[[email protected] scripts]$ date
Wed Oct 18 12:58:19 CST 2017
[[email protected] scripts]$ sh rman_bak_level1.sh
查看备份日志,成功备份
4.创建表level1
SQL> create table level1 as select * from scott.dept;
Table created.
SQL> !date
Wed Oct 18 13:01:15 CST 2017
5.执行2级增量备份
[[email protected] scripts]$ sh rman_bak_level2.sh
查看备份日志,成功备份
点击有惊喜