1、数据库环境

数据库DBID及打开模式
SQL> select dbid,open_mode from v$database;
DBID OPEN_MODE
---------- ----------
4106451204 READ WRITE

数据文件:
SQL> select file#,status,enabled,name from v$datafile;

FILE# STATUS ENABLED NAME
---------- ------- ---------- --------------------------------------------------------------------------------
1 SYSTEM READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/system01.dbf
2 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/undotbs01.dbf
3 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/sysaux01.dbf
4 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/tbs_1.dbf
5 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/tbs3.dbf
6 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/tbs_big01.dbf
7 ONLINE READ WRITE /u01/app/oracle/oradata/ocmdb/dfile/rman.dbf

控制文件:
SQL> select status,name from v$controlfile;

STATUS NAME
------- --------------------------------------------------------------------------------
/u01/app/oracle/ocmdb/cfile/ora_control1
/u01/app/oracle/ocmdb/cfile/ora_control2
/u01/app/oracle/ocmdb/cfile/control3

联机日志:
SQL> select group#,status,type,member from v$logfile;

GROUP# STATUS TYPE MEMBER
---------- ------- ------- --------------------------------------------------------------------------------
1 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo01.log
1 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo11.log
3 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo03.log
2 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo02.log
5 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo05.log
5 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo55.log
4 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo04.log
4 ONLINE /u01/app/oracle/oradata/ocmdb/lfile/redo44.log

2、数据库备份脚本

冷备份脚本
#rem script:coldbak.sh
#rem creater:chon
#rem date:2011
#rem desc:offline full backup database

#--connect database
sqlplus / as sysdba <<EOF
#--shutdown database
shutdown immediate;
#--Copy Data file
!cp /u01/app/oracle/oradata/ocmdb/dfile/*.dbf /backup
!cp /u01/app/oracle/oradata/ocmdb/undotbs01.dbf /backup
#--Copy Control file
!cp /u01/app/oracle/ocmdb/cfile/* /backup
#--Copy Log file
!cp /u01/app/oracle/oradata/ocmdb/lfile/*.log /backup
#--Copy archive log
!cp -R /u01/app/oracle/rmanbak/OCMDB/archivelog/* /backup
#--startup database
startup;

说明:
1、以上脚本在数据库关闭状态下备份数据库所有的数据文件,联机日志,控制文件,归档日志(在一个目录下),如果成功备份,所有文件是一致的。
2、没有备份参数文件,参数文件可以另外备份,没有必要每次都备份,只需要在改变设置后备份一次。
3、如果以上命令没有成功依次执行,那么备份将是无效的,如连接数据库不成功,那么肯定关闭数据库也不成功,那么备份则无效
4、冷备份建议下人工干预下执行。

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

OS热备份
查看表空间和数据文件对应关系
SQL> select file_id,tablespace_name,file_name from dba_data_files;

FILE_ID TABLESPACE_NAME FILE_NAME
---------- ------------------------------ --------------------------------------------------------------------------------
7 RMAN_TS /u01/app/oracle/oradata/ocmdb/dfile/rman.dbf
6 BIG_TBS /u01/app/oracle/oradata/ocmdb/dfile/tbs_big01.dbf
5 TBS3 /u01/app/oracle/oradata/ocmdb/dfile/tbs3.dbf
4 TBS_1 /u01/app/oracle/oradata/ocmdb/dfile/tbs_1.dbf
3 SYSAUX /u01/app/oracle/oradata/ocmdb/dfile/sysaux01.dbf
2 UNDOTBS /u01/app/oracle/oradata/ocmdb/undotbs01.dbf
1 SYSTEM /u01/app/oracle/oradata/ocmdb/dfile/system01.dbf

数据库OS热全备份脚本

#rem script:hotbak.sh
#rem creater:chon
#rem date:2011
#rem desc:backup all database datafile in archive

#--connect database
sqlplus / as sysdba <<EOF

#--archive
alter system archive log current;

#--start hotbak
alter tablespace system begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/system01.dbf /backup
alter tablespace system end backup;

alter tablespace UNDOTBS begin backup;
!cp /u01/app/oracle/oradata/ocmdb/undotbs01.dbf /backup
alter tablespace UNDOTBS end backup;

alter tablespace SYSAUX begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/sysaux01.dbf /backup
alter tablespace SYSAUX end backup;

alter tablespace TBS_1 begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/tbs_1.dbf /backup
alter tablespace TBS_1 end backup;

alter tablespace TBS3 begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/tbs3.dbf /backup
alter tablespace TBS3 end backup;

alter tablespace BIG_TBS begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/tbs_big01.dbf /backup
alter tablespace BIG_TBS end backup;

alter tablespace RMAN_TS begin backup;
!cp /u01/app/oracle/oradata/ocmdb/dfile/rman.dbf /backup
alter tablespace RMAN_TS end backup;
#--end

#--bak control file
#--binary
alter database backup controlfile to '/backup/controlbinbak.000';
#--ascii
alter database backup controlfile to trace;

alter system archive log current;

说明:
1、热备份必须在数据库归档方式下才可以运行
2、以上脚本可以在数据库运行状态下备份数据库所有的数据文件(除了临时数据文件),没有必要备份联机日志。
3、归档日志至少需要一次完整备份之后的所有日志。
4、如果以上命令没有成功依次执行,那么备份也是无效的,如连接数据库不成功,那么备份则无效

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

RMAN备份脚本
--本地

创建文件夹
mkdir /home/oracle/backup
mkdir /home/oracle/backup/script
mkdir /home/oracle/backup/log
mkdir /home/oracle/backup/export

--备份目的地
mkdir /home/oracle/rman_backup

创建备份表空间

create tablespace rman_tbs datafile '/oradata/luke/rman_tbs01.dbf' size 1024M;

创建备份用户
create user rman identified by rman default tablespace rman_tbs temporary tablespace temp;

grant connect,resource ,recovery_catalog_owner to rman;

rman catalog rman/rman
create catalog tablespace rman_tbs;
connect target sys/lukewhx@luke
register database;
report schema;

configure retention policy to redundancy 2;
configure retention policy to recovery window of 7 days;

--倒出RMAN用户数据脚本exp_rman.par (即备份catalog库)
userid=rman/rman
file=/home/oracle/backup/export/rman.dmp
log=/home/oracle/backup/log/rman.log

-- 倒出RMAN数据SHELL脚本exp_rman.sh
#!/bin/bash
cd $HOME
. .bash_profile
cd $HOME/backup/script
exp parfile=exp_rman.par

-- 零级备份RMAN脚本level0_backup.rcv
connect catalog rman/rman
connect target sys/unumall@unu2
run {

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0 database format '/home/oracle/rman_backup/level0_%d_%s_%p_%u.bak'
tag='level 0' include current controlfile;
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d2;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;

--零级备份SHELL脚本的level0_backup.sh
#!/bin/bash
cd $HOME
. .bash_profile
cd $HOME/backup/script
rman cmdfile=level0_backup.rcv msglog=$HOME/backup/log/level0_backup.log
. /home/oracle/backup/script/exp_rman.sh

--一级差异增量备份RMAN脚本 level1_backup.rcv
connect catalog rman/rman
connect target sys/luke@luke
run {
allocate channel d1 type disk;
backup incremental level 1 format '/home/oracle/rman_backup/level1_%d_%s_%p_%u.bak' tag = 'level 1' database;
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;

--一级差异增量备份SHELL脚本level1_backup.sh

#!/bin/bash
cd $HOME
. .bash_profile
cd /home/oracle/backup/script
rman cmdfile=level1_backup.rcv msglog=$HOME/backup/log/level1.log
. /home/oracle/backup/script/exp_rman.sh

--二级差异增量备份RMAN脚本 level2_backup.rcv
connect catalog rman/rman
connect target sys/luke@luke
run {
allocate channel d1 type disk;
backup incremental level 2 format '/home/oracle/rman_backup/level2_%d_%s_%p_%u.bak' tag = 'level 2' database;
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/rman_backup/log_%d_%s_%p_%u.bak' delete all input;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;

--二级差异增量备份SHELL脚本level2_backup.sh
#!/bin/bash
cd $HOME
. .bash_profile
cd /home/oracle/backup/script
rman cmdfile=level2_backup.rcv msglog=$HOME/backup/log/level2.log
. /home/oracle/backup/script/exp_rman.sh

提高 RMAN增量备份性能

alter database enable block change tracking using file
'/u01/app/oracle/admin/devdb/bdump/luke.log';

desc v$block_change_tracking;

linux下定时执行备份脚本

crontab -e -u oracle
SHELL=/bin/bash --以下脚本在bash下执行
MAILTO=oracle --执行日志以邮件形式邮给oracle用户,可以/var/spool/mail/oracle下查收
10 1 * * 0 /home/oracle/backup/script/level0_backup.sh
10 1 * * 1 /home/oracle/backup/script/level2_backup.sh
10 1 * * 2 /home/oracle/backup/script/level2_backup.sh
10 1 * * 3 /home/oracle/backup/script/level1_backup.sh
10 1 * * 4 /home/oracle/backup/script/level2_backup.sh
10 1 * * 5 /home/oracle/backup/script/level2_backup.sh
10 1 * * 6 /home/oracle/backup/script/level2_backup.sh

一周差异备份策略:
备份目标库和catalog库
周日0级全备,周一周二为2级,周三为1级,周四周五周六为2级。
每天凌晨1点10分开始备份

零级备份
backup incremental level 0 database;
一级差异增量 差异增量是默认增量备份方式
backup incremental level 1 database;
一级累计增量
backup incremental level 1 cumulative database;

oracle备份之备份测试脚本(冷备、热备、rman)的更多相关文章

  1. Redis - Keepalived + redis 主备热备切换

    1. 热备方案 硬件:server两台,分别用于master-redis及slave-redis 软件:redis.keepalived 实现目标: 由keepalived对外提供虚拟IP(VIP)进 ...

  2. oracle数据库基于(streams流复制)的双机热备配置手册

    ------------------------------------------------------------------------------- 主数据库: 操作系统:windows 2 ...

  3. 基于nginx实现web服务器的双机热备

    1.适用场景 对于部署重要的服务,会使用两台服务器,互相备份,共同执行同一服务.当一台服务器出现故障时,可以由另一台服务器承担服务任务,从而在不需要人工干预的情况下,自动保证系统能持续提供服务.双机热 ...

  4. 基于防火墙的VRRP技术--华为防火墙双机热备--VGMP

    目录 主备备份双机热备配置 负载分担双机热备配置 为了解决多个VRRP备份组状态不一致的问题,华为防火墙引入VGMP(VRRP Group Management Protocol)来实现对VRRP备份 ...

  5. windows下oracle数据库定时备份与压缩批处理脚本(win7/win2008亲测通过)

    第一种方式:全备份,并直接覆盖原来的备份文件,固定命名. 脚本: @echo off exp system/a123@HZPG file=e:\db_backup\oradata.dmp log=e: ...

  6. oracle数据库热备中的备份和恢复及例子

    手工热备(开库状态) 备份控制文件: alter database backup controlfile to '/u01/oradata/prod/con.bak1'; 备份数据文件(这里用到pl/ ...

  7. Windows下Oracle数据库自动备份批处理脚本

    expdb命令版本 @echo off REM ########################################################### REM # Windows Se ...

  8. Oracle冷备和热备脚本

    Oracle冷备和热备脚本 冷备脚本: set feedback off set heading off set verify  off set trimspool off set echo off ...

  9. Oracle数据库的备份方法

    1.引言 Oracle数据库的备份方法很多,无论使用那种备份方法,备份的目的都是为了在出现故障后能够以尽可能小的时间和代价恢复系统.比如使用export实用程序导出数据库对象.使用Oracle备份数据 ...

随机推荐

  1. PHP convert_uuencode() 函数

    实例 编码字符串: <?php$str = "Hello world!";echo convert_uuencode($str);?>高佣联盟 www.cgewang. ...

  2. Skill 返回list中的倒数第二个数据

    https://www.cnblogs.com/yeungchie/ code procedure(ycLast2(list) prog((index ouput) unless(type(list) ...

  3. 6.3 省选模拟赛 Decompose 动态dp 树链剖分 set

    LINK:Decompose 看起来很难 实际上也很难 考验选手的dp 树链剖分 矩阵乘法的能力. 容易列出dp方程 暴力dp 期望得分28. 对于链的情况 容易发现dp方程可以转矩阵乘法 然后利用线 ...

  4. CF R 633 div 1 1338 C. Perfect Triples 打表找规律

    LINK:Perfect Triples 初看这道题 一脸懵逼.. 完全没有思路 最多就只是发现一点小规律 即. a<b<c. 且b的最大的二进制位一定严格大于a b的最大二进制位一定等于 ...

  5. 关于双线性插值中重叠像素与空白像素掩膜函数的一种迭代batch的写法

    from __future__ import division import matplotlib.pyplot as plt import numpy as np import tensorflow ...

  6. vmware15虚拟机安装教程

    自己碰到的问题:本人win7 64位旗舰版系统.之前用VMware12pro版本的软件,在安装Ubuntu18.04之后,有时候开启Ubuntu虚拟机时有点问题,重启就可以了.但是不稳定,所以改用VM ...

  7. 原来写个Vue 首页就这么简单

    全栈的自我修养: 为我们的项目添加首页 You can never replace anyone. What is lost is lost. 每个人都是无可替代的,失去了便是失去了. 前言 上篇文章 ...

  8. C语言学习笔记之数组与指针的关系

    首先,大家先需知道一个关于基类型的概念 基类型:组成一个新类型的基础类型 这句话是什么意思呢?举个例子: int a[3] = {1,2,3}; 上面是由三个int类型的数组成一个新的类型也就是数组, ...

  9. 【Java】AES加机解密工具类代码

    import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import javax.crypt ...

  10. C#LeetCode刷题之#674-最长连续递增序列( Longest Continuous Increasing Subsequence)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3734 访问. 给定一个未经排序的整数数组,找到最长且连续的的递增 ...