暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle rman备份案例

oracleEDU 2017-10-26
1283

rman备份,全备(full)、0级(0-level)、1级(1-level)、2级(2-level)及自动删除2天前的归档备份。

crontab设置

每月30日2点做全备份,每星期日12点做0级备份,每星期三1点做1级备份,其他每天3点做2级备份。

[oracle@db ~]$ crontab -l

 0 2 30 * * oradata/full.sh

 0 0 * * 0 oradata/0level.sh

 0 1 * * 3 oradata/1level.sh

 0 3 * * 1,2,4,5,6 oradata/2level.sh

全备份

(0级备份与全备份的区别是全备份不能用增量备份,而0级备份则可以;)(文件名:full.sh)

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=

/u01/app/oracle/product/11.2.0/dbhome_1

export ORACLE_SID=orcl

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

#export PATH=$PATH:$ORACLE_HOME/bin

echo "--------------start----------------";date>>/databak/notes.txt

#backup start

rman target <<EOF  

run{ 

delete noprompt backupset;

allocate channel c1 device type disk;

allocate channel c2 device type disk;

allocate channel c3 device type disk;

backup full tag 'dbfull' format '/databak/fullbak/db0%u_%s_%p' database include current controlfile;

sql 'alter system archive log current'; 

backup filesperset 3 format '/databak/fullbak/db0%u_%s_%p' archivelog all delete input;  

delete noprompt archivelog until time 'sysdate - 2'  all ; #删除2天前的归档,注意sysdate-2是从现在的日期和时间开始进行删除,注意时间.

release channel c1;

release channel c2;

release channel c3;

}

exit;

EOF

echo "------------end-------------";date

0-level备份文件(文件名:0level.sh)

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=

/u01/app/oracle/product/11.2.0/dbhome_1

export ORACLE_SID=orcl

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

#export PATH=$PATH:$ORACLE_HOME/bin

echo "-------------start--------------";date>>/databak/notes.txt

#backup start

rman target <<EOF  

run{ 

allocate channel c1 device type disk;

allocate channel c2 device type disk;

allocate channel c3 device type disk;

backup incremental level 0 tag 'db0' format '/databak/0levelbak/db0%u_%s_%p' database skip readonly;

sql 'alter system archive log current';

backup filesperset 3 format '/databak/0levelbak/db0%u_%s_%p' archivelog all delete input;  #这样不能删除归档日志

delete noprompt archivelog until time 'sysdate - 2'  all ; #这句才可以删除,注意sysdate-2是从现在的日期和时间开始进行删除,注意时间.

release channel c1;

release channel c2;

release channel c3;

}

exit;

EOF

echo "-------------end-------------";date

1-level备份文件(文件名:1level.sh)

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=

/u01/app/oracle/product/11.2.0/dbhome_1

export ORACLE_SID=orcl

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

#export PATH=$PATH:$ORACLE_HOME/bin

echo "-------------start--------------";date>>/databak/notes.txt

#backup start

rman target <<EOF  

run{ 

allocate channel c1 device type disk;

allocate channel c2 device type disk;

allocate channel c3 device type disk;

backup incremental level 1 tag 'db1' format '/databak/1levelbak/db1%u_%s_%p' database skip readonly;

sql 'alter system archive log current';

backup filesperset 3 format '/databak/1levelbak/db1%u_%s_%p' archivelog all delete input;

release channel c1;

release channel c2;

release channel c3;

}

exit;

EOF

echo "-----------end-------------";date

2-level备份文件(文件名:2level.sh)

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=

/u01/app/oracle/product/11.2.0/dbhome_1

export ORACLE_SID=orcl

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

#export PATH=$PATH:$ORACLE_HOME/bin

echo "-------------start--------------";date>>/databak/notes.txt

#backup start

rman target <<EOF  

run{ 

allocate channel c1 device type disk;

allocate channel c2 device type disk;

allocate channel c3 device type disk;

backup incremental level 2 tag 'db1' format '/databak/2levelbak/db2%u_%s_%p' database skip readonly;

sql 'alter system archive log current';

backup filesperset 3 format '/databak/2levelbak/db2%u_%s_%p' archivelog all delete input;

release channel c1;

release channel c2;

release channel c3;

}

exit;

EOF

echo "-----------end-------------";date


Rman备份中变量的含义

backup incremental level 0 database format='LEV0_%d_%t_%U_%s_%p' 

format=string 文件路径和名称的格式串,其中可包含宏变量:

%c copy ID

%p backup piece ID

%s backup set ID

%e log sequence

%h log thread ID

%d database name

%n database name(x填充到8个字符)

%I DBID

%f file ID

%F DBID, day, month, year, and sequencer的复合

%N tablespace name

%t timestamp

%M mh mm格式

%Y year yyyy格式

%u backup set+time((x填充到8个字符)

%U %u_%p_%c


若想要将正在运行的备份终止,以sys用户登陆,使用如下命令查看备份的会话:

SQL> select SID,SERIAL# from v$session where module like 'backup%';


       SID    SERIAL#

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

55 4818


然后用以下命令将其会话杀掉:

alter system kill session 'SID,SERIAL#';

SQL> alter system kill session '55,4818' ;


System altered.


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

RMAN-03009: failure of backup command on ORA_DISK_1 channel at 08/04/2017 20:42:37

ORA-00028: your session has been killed



最后修改时间:2021-04-28 20:18:08
文章转载自oracleEDU,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论