【
开启归档日志:
1、开启归档
a. 关闭数据库shutdown immediate
b. startup mount
c. alter database archivelog
d. alter database open
2、禁止归档
a. 关闭数据库shutdown immediate
b. startup mount
c. alter database noarchivelog
d. alter database open
归档信息可以通过如下语句查看
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
(备份和DG都必须是数据库处于归档模式下)
】
在oracle用户下创建脚本
并赋予权限chmod +x 脚本
chown oracle:oinstall 脚本
脚本内容
#!/bin/bash
date=`date +%Y%m%d`
export ORACLE_BASE=/data/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_OWNER=oracle
export ORACLE_SID=orcl
export ORACLE_TERM=xterm
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
/data/oracle/product/11.2.0/db_1/bin/rman target / <<EOF
RUN {
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "/opt/script/%F";
ALLOCATE CHANNEL CH1 DEVICE TYPE DISK FORMAT "/opt/script/%U";
BACKUP DATABASE SKIP INACCESSIBLE FILESPERSET 10
PLUS ARCHIVELOG FILESPERSET 20
DELETE ALL INPUT;
RELEASE CHANNEL CH1;
}
ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
CROSSCHECK BACKUPSET;
REPORT OBSOLETE;
DELETE OBSOLETE;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP;
exit;
EOF
====================================================================================================================================================================================================================================================
在oracle用户下执行
crontab -e
07 15 * * * /opt/script/backl
(分【0-59】 小时【1-23】 日期【1-31】 月份【1-12】 星期【0-6】 绝对路径)
crontab -l