重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

oracle脚本怎么备份 oracle备份命令

Oracle数据库RMAN的自动备份脚本简介

Oracle数据库RMAN的自动备份脚本简介

成都创新互联主打移动网站、网站设计制作、成都做网站、网站改版、网络推广、网站维护、国际域名空间、等互联网信息服务,为各行业提供服务。在技术实力的保障下,我们为客户承诺稳定,放心的服务,根据网站的内容与功能再决定采用什么样的设计。最后,要实现符合网站需求的内容、功能与设计,我们还会规划稳定安全的技术方案做保障。

各位同学知道Oracle数据库RMAN如何自动备份脚本嘛?下面我为大家整理了关于Oracle数据库RMAN的自动备份脚本文章,希望能为你提供帮助:

1、数据库设置为归档方式

2、数据库的备份脚本

db_full_backup.sh :数据库全备脚本

db_l0_backup.sh :数据库0级备份脚本

db_l1_backup.sh :数据库1级备份脚本

:数据FTP上传脚本

ftp_del.sh :数据FTP清理脚本

rman_bak.sh :数据备份主程序

3、备份原理

每周1、3、6进行0级备份

每周日、2、4、5进行1级备份

备份文件上传到FTP服务器

FTP服务器每周清理一次,但是清理后将周六和周日的备份进行保留(6.bak和0.bak)

所有工作防暑crontab中自动执行备份

4、备份目录含义

arc :数据库归档目录

rmanbak :数据库备份文件的保存目录

rmanscripts :数据库脚本存放路径

5、FTP目录

ftp上必须手动建立目录

L0:

---1

---3

---6

---6.bak

L1:

---2

---4

---5

---0

---0.bak

rman_bak.sh脚本主程序

#!/bin/bash

#--------------------------------------------

# Oracle auto backup using rman

#

# author:songrh

# week:1,3,6 Level 0 backup

# 2,4,5,0 Level 1 backup

# Copyright by ChenLong Tec

#--------------------------------------------

#

#

export ORACLE_BASE=/u02/oracle

export ORACLE_HOME=/u02/oracle/product/9.2.4

export ORACLE_SID=PROD

export LD_LIBRARY_PATH=$ORACLE_HOME/lib

export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib

export NLS_LANG=american_america.ZHS16GBK

export TNS_ADMIN=$ORACLE_HOME/network/admin

export ORA_NL33=$ORACLE_HOME/ocommon/nls/admin/data

export PATH=/bin:/usr/bin:/usr/sbin:$ORACLE_HOME/bin:$PATH

export PATH=$PATH:/opt/local/bin

#

SH_PATH=/u02/rmanscripts

ARC_PATH=/u02/arch

RMAN_BAK_PATH=/u02/rmanbak

#

#FULL_PATH=$RMAN_BAK_PATH/full

L0_PATH=$RMAN_BAK_PATH/L0

L1_PATH=$RMAN_BAK_PATH/L1

#

#DAY_TAG=`date "%Y-%m-%d"`

LOG_TAG=`date "%Y-%m-%d"`

#FIRST_DAY=`date %e`

WEEK=`date %w`

#WEEK=1

#

# FTP configure

IP="122.120.150.155"

FTPUSER="ftpbak"

FTPPASS="******"

FTPROOT0="L0"

FTPROOT1="L1"

#

DISK_USE=`df -k |sed -n '/u02/'p | awk '{print $5}' |sed 's/%//'`

####check path function

############

if [[ $DISK_USE -ge 90 ]]; then

rm -rf $L0_PATH/*

rm -rf $L1_PATH/*

fi

if [ "$WEEK" = "6" -o "$WEEK" = "3" -o "$WEEK" = "1" ]; then

if [ ! -d $L0_PATH ]; then

mkdir $L0_PATH

fi

if [ "$WEEK" = "1" ]; then

rm -rf $L0_PATH/*

rm -rf $L1_PATH/*

mkdir $L0_PATH/$WEEK

$SH_PATH/db_l0_backup.sh $L0_PATH/$WEEK

cd $L0_PATH/$WEEK

$SH_PATH/ftp_del.sh $IP $FTPUSER $FTPPASS $FTPROOT0 $WEEK $WEEK_$LOG_TAG.log

else

if [ ! -d $L0_PATH/$WEEK ]; then

mkdir $L0_PATH/$WEEK

$SH_PATH/db_l0_backup.sh $L0_PATH/$WEEK

cd $L0_PATH/$WEEK

$SH_PATH/ $IP $FTPUSER $FTPPASS $FTPROOT0 $WEEK $WEEK_$LOG_TAG.log

else

;

oracle怎么用rman脚本进行备份

Oracle数据库中rman备份脚本非常实用

查询字符集

SQL select * from nls_database_parameters;

NLS_CHARACTERSET

AL32UTF8

备份时字符集很重要,不然会出乱码

一、0级备份(全备)红色是要修改的,根据个人的存放位置。

[oracle@oracle122 script]$ cat db_bak0.rman

run

{

configure retention policy to recovery window of 8 days;

configure controlfile autobackup on;

configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';

allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc0_%d_%s_%p_%u_%T';

backup incremental level 0 tag='level 0' database skip inaccessible filesperset 10 plus archivelog filesperset 20;

release channel ch1;

}

allocate channel for maintenance device type disk;

crosscheck backup;

delete noprompt expired backup;

delete noprompt obsolete;

delete noprompt archivelog until time 'sysdate-30';

0级运行脚本

[oracle@oracle122 script]$ cat exec_0_level.sh

ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME

ORACLE_BASE=/u01/app; export ORACLE_BASE

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME

ORACLE_SID=orcl; export ORACLE_SID

ORACLE_TERM=xterm; export ORACLE_TERM

PATH=/usr/sbin:$PATH; export PATH

PATH=$ORACLE_HOME/bin:$PATH; export PATH

export DATE=$(date +%Y_%m_%d)

export NLS_LANG="Simplified Chinese_china".AL32UTF8

/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak0.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append

二、1级备份(增量)

[oracle@oracle122 script]$ cat db_bak1.rman

run

{

configure retention policy to recovery window of 8 days;

configure controlfile autobackup on;

configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';

allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc1_%d_%s_%p_%u_%T';

backup incremental level 1 tag='level 1' database skip inaccessible filesperset 10 plus archivelog filesperset 20;

release channel ch1;

}

allocate channel for maintenance device type disk;

crosscheck backup;

delete noprompt expired backup;

delete noprompt obsolete;

delete noprompt archivelog until time 'sysdate-30';

1级运行脚本

[oracle@oracle122 script]$ cat exec_1_level.sh

ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME

ORACLE_BASE=/u01/app; export ORACLE_BASE

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME

ORACLE_SID=orcl; export ORACLE_SID

ORACLE_TERM=xterm; export ORACLE_TERM

PATH=/usr/sbin:$PATH; export PATH

PATH=$ORACLE_HOME/bin:$PATH; export PATH

export DATE=$(date +%Y_%m_%d)

export NLS_LANG="Simplified Chinese_china".AL32UTF8

/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak1.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append

三、2级备份(从0级追加到现在的备份)

[oracle@oracle122 script]$ cat db_bak2.rman

run

{

configure retention policy to recovery window of 8 days;

configure controlfile autobackup on;

configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';

allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc2_%d_%s_%p_%u_%T';

backup incremental level 2 tag='level 2' database skip inaccessible filesperset 10 plus archivelog filesperset 20 delete all input;

release channel ch1;

}

allocate channel for maintenance device type disk;

crosscheck backup;

delete noprompt expired backup;

delete noprompt obsolete;

2级运行脚本

[oracle@oracle122 script]$ cat exec_2_level.sh

ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME

ORACLE_BASE=/u01/app; export ORACLE_BASE

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME

ORACLE_SID=orcl; export ORACLE_SID

ORACLE_TERM=xterm; export ORACLE_TERM

PATH=/usr/sbin:$PATH; export PATH

PATH=$ORACLE_HOME/bin:$PATH; export PATH

export DATE=$(date +%Y_%m_%d)

export NLS_LANG="Simplified Chinese_china".AL32UTF8

/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak2.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append

定时备份星期天为0级全备,星期三为2级备份,星期一,星期二,星期四,星期五,星期六为1级增量备份晚上11点开始备份

[oracle@oracle122 script]$ crontab -l

* 23 * * 0 /home/oracle/rmanbak/script/exec_0_level.sh

* 23 * * 1 /home/oracle/rmanbak/script/exec_1_level.sh

* 23 * * 2 /home/oracle/rmanbak/script/exec_1_level.sh

* 23 * * 3 /home/oracle/rmanbak/script/exec_2_level.sh

* 23 * * 4 /home/oracle/rmanbak/script/exec_1_level.sh

* 23 * * 5 /home/oracle/rmanbak/script/exec_1_level.sh

* 23 * * 6 /home/oracle/rmanbak/script/exec_1_level.sh

oracle 备份与恢复、完全备份脚本

exp system/oracle@orcl buffer=1024 file=/home/oracle/backup/orcl.dmp full=y

exp test/test@orcl file=/home/oracle/backup/test.dmp owner=test

exp test/test@orcl file=/home/oracle/backup/student.dmp tables=(student,teacher)

exp 用户名/密码@远程的IP:端口/实例 file=存放的位置:\文件名称.dmp full=y

log=xx

imp demo/demo@orcl file=d:\back.dmp full=y ignore=y log=D:\implog.txt

imp test/test@orcl file=/home/oracle/backup/test.dmp

imp demo/demo@orcl file=d:\backup2.dmp tables=(teachers,students)

imp 用户名/密码@远程的IP:端口/实例 file=存放的位置\文件名称.dmp full=y

vi /home/oracle/fullbackup.sh

sysname='centos7'

syspath=/home/oracle/backup

v_date=$(date '+%Y%m%d%H%M%S')

logfile= {v_date}.log

echo backup_time {logfile}

echo "backup jcd" {logfile}

date '+%Y-%m-%d %H:%M:%S' syspath/orcl${v_date}.dmp

exp system/oracle@orcl file= {logfile}

echo "end_time" {logfile}

gzip ${filename}

0 2 * * * sh /home/oracle/fullbackup.sh


网站名称:oracle脚本怎么备份 oracle备份命令
当前地址:http://cqcxhl.com/article/hjijop.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP