title: Oracle开启归档模式并设置RMAN自动备份策略
categories: 数据库
tags:
- Oracle
- RMAN
timezone: Asia/Shanghai
date: 2019-01-06
软件版本
Oracle 11g 11.2.0.4
1.开启和关闭归档模式
1.管理员登录
sqlplus / as sysdba
2.查看是否开启归档模式
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 2
Current log sequence 4
3.关闭数据库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
4.启动数据库到mount状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area 759943168 bytes
Fixed Size 2257112 bytes
Variable Size 499126056 bytes
Database Buffers 255852544 bytes
Redo Buffers 2707456 bytes
Database mounted.
5.启用归档模式并查看
SQL> alter database archivelog;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 2
Next log sequence to archive 4
Current log sequence 4
6.启动数据库
SQL> alter database open;
Database altered.
7.关闭归档模式
# 关闭数据库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
# 启动数据库到mount状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area 759943168 bytes
Fixed Size 2257112 bytes
Variable Size 499126056 bytes
Database Buffers 255852544 bytes
Redo Buffers 2707456 bytes
alter database noarchivelog;Database mounted.
# 关闭归档模式
SQL> alter database noarchivelog;
Database altered.
# 查看状态
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 2
Current log sequence 4
2.RMAN自动全备脚本
#!/bin/bash
backtime=`date +%Y%m%d`
echo $backtime
# by 小六 20181126 1327133225@qq.com
# ######################### oracle RAC RMAN自动备份脚本 #########################
# 备份要求
# 条件一:在node1每晚进行全量备份,同时删除过期备份和归档日志文件;
# by all
# su - oracle
# mkdir -p /home/oracle/log
# mkdir -p /home/oracle/bak
#
# %c 备份片的拷贝数
# %d 数据库名称
# %D 位于该月中的第几天 (DD)
# %M 位于该年中的第几月 (MM)
# %F 一个基于DBID唯一的名称,这个格式的形式为c-IIIIIIIIII-YYYYMMDD-QQ,其中IIIIIIIIII为该数据库的DBID,YYYYMMDD为日期,QQ是一个1-256的
序列
# %n 数据库名称,向右填补到最大八个字符
# %u 一个八个字符的名称代表备份集与创建时间
# %p 该备份集中的备份片号,从1开始到创建的文件数
# %U 一个唯一的文件名,代表%u_%p_%c
# %s 备份集的号
# %t 备份集时间戳
# %T 年月日格式(YYYYMMDD)
$ORACLE_HOME/bin/rman log=/home/oracle/log/node1_backupall_$backtime.log <<EOF
connect target /
run{
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
allocate channel c1 type disk FORMAT '/home/oracle/bak/%d_%T_%U';
allocate channel c2 type disk FORMAT '/home/oracle/bak/%d_%T_%U';
backup as compressed backupset database ;
backup as compressed backupset archivelog all delete input;
# report obsolete命令用于列出rman资料库中能够被删除的全备份、数据文件拷贝和归档日志记录。
# report obsolete;
# 删除陈旧备份(noprompt=不提示)
# delete noprompt obsolete;
# 核对所有备份集
crosscheck backup;
# 核对归档日志
crosscheck archivelog all;
# 删除EXPIRED备份集(noprompt=不提示)
# delete noprompt expired backup;
# 释放通道
release channel c1;
release channel c2;
}
EOF
echo
echo "Backup Complete!"
echo