Oracle数据库中rman备份脚本非常实用
查询字符集
SQL> select * from nls_database_parameters;
NLS_CHARACTERSET
一、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 /%F';
allocate channel ch1 device type disk format '/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
export ORACLE_HOSTNAME
ORACLE_SID= 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".
rman target cmdfile 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 F';
allocate channel ch1 device type disk format /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=export ORACLE_HOSTNAME
ORACLE_BASE; export ORACLE_BASE
ORACLE_HOME; export ORACLE_HOME
ORACLE_SID=; 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".
//rman target cmdfile db_bak1.rman 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 ;
allocate channel ch1 device type disk format /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=; export ORACLE_HOSTNAME
ORACLE_BASEORACLE_BASE
ORACLE_HOME; export ORACLE_HOME
ORACLE_SID=; 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".
target cmdfiledb_bak2.rman 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
--------------------------------------推荐阅读 --------------------------------------
RMAN 配置归档日志删除策略
Oracle基础教程之通过RMAN复制数据库
RMAN备份策略制定参考内容
RMAN备份学习笔记
Oracle数据库备份加密 RMAN加密
--------------------------------------分割线 --------------------------------------
: