- N +

ORACLE数据库如何备份

ORACLE数据库有多种归档方式,作为数据库管理都应该熟练掌握,这里仅介绍如何使用RMAN对数据库进行备份。

RMAN备份必须在Oracle的归档模式下进行。
SQL>archive log list



如果数据库不在归档模式,如何切换?
shutdown immediate
startup mount
alter database archivelog;
alter database open

进入RMAN备份环境:
$rman target /

查看RMAN的参数配置:
RMAN>show all;

启动控制文件的自动备份:
RMAN>configure controlfile autobackup on;

最简单的全库备份:
RMAN>backup database;

查看刚才的备份信息:
RMAN>list backup;

查看备份总体信息:
RMAN>list backup summary;

编写备份脚本:

通过df查看硬盘使用量,计算出备份冗余数,此处假设为10:
RMAN>CONFIGURE RETENTION POLICY TO REDUNDANCY 10;

创建备份文件夹:
在/u01/app/oracle下创建文件夹RmanBackup

创建一个0级全库备份的脚本BackupFull.sh:
# script. :BackupFull.sh
# creater: Taohuan
# date:2016/7/24
# desc: backup full datebase datafile in archive with RMAN
# connect database

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH

rman target / << EOF_RMAN
run{
allocate channel c1 type disk;
backup incremental level 0 tag 'db0' format
'/u01/app/oracle/RmanBackup/db0_%d_%T_%s' database include current controlfile;
delete noprompt obsolete;
release channel c1;
}
# end

创建一个1级增量备份的脚本Incr1.sh:
# script. :Incrl.sh
# creater: Taohuan
# date:2016/7/24
# desc: backup full datebase datafile in archive with RMAN
# connect database

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH

rman target / << EOF_RMAN
run{
allocate channel c1 type disk;
backup incremental level 1 tag 'db1' format
'/u01/app/oracle/RmanBackup/db1_%d_%T_%s' database include current controlfile;
delete noprompt obsolete;
release channel c1;
}
# end

给2个脚本执行权限:
chmod 755 BackupFull.sh Incr1.sh

使用crontab设置自动执行ORACLE备份脚本
crontab -e
输入以下内容:
0 1 * * 0 /u01/app/oracle/RmanBackup/BackupFull.sh >>/u01/app/oracle/RmanBackup/BackupFull.log
0 1 * * 3 /u01/app/oracle/RmanBackup/BackupFull.sh >>/u01/app/oracle/RmanBackup/BackupFull.log
30 1 * * 1-2 /u01/app/oracle/RmanBackup/Incr1.sh >>/u01/app/oracle/RmanBackup/Incr.log
30 1 * * 4-6 /u01/app/oracle/RmanBackup/Incr1.sh >>/u01/app/oracle/RmanBackup/Incr.log

解释:
周日和周三凌晨1:00执行0级全库备份,周一、二、四、五、六凌晨1:30执行1级增量备份。
返回列表
上一篇:返回列表
下一篇:异构环境Oracle数据库迁移
留言与评论(共有 0 条评论)
   
验证码: