linux下:
[oracle@his01 ~]$ crontab -e
0 3 * * 5 /backup/sh/backup_fulldb.sh
>>
/backup/rman
.log
--删备份
--删备份
0 3 * * 5 find /backup/backupset/ -mtime +15 -name '*.bak' -exec rm -rf {} \;
--删日志
--删日志
0 3 * * * find /archivelog/ -mtime +30 -name '*.arc' -exec rm -rf {} \;
注意:如果是使用root用户:0 3 * * 5 su - oracle -c /autobak/rmlog.sh
--自动备份作业
注意:如果是使用root用户:0 3 * * 5 su - oracle -c /autobak/rmlog.sh
--自动备份作业
[oracle@his01 sh]$ cat backup_fulldb.sh
export ORACLE_SID=orcl
rman target / nocatalog << EOF
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
sql 'alter system archive log current';
backup database format '/backup/backupset/dbfull_%d_%s_u%_%p.bak' ;
--备份并删除归档:
backup database format '/backup/backupset/dbfull_%d_%s_u%_%p.bak' plus archivelog delete all input format '/backup/backuparc/arch_%U';
backup database format '/backup/backupset/dbfull_%d_%s_u%_%p.bak' plus archivelog delete all input format '/backup/backuparc/arch_%U';
--压缩备份:
backup as compressed backupset database format '/backup/backupset/dbfull_%d_%s_u%_%p.bak' plus archivelog delete all input format '/backup/backuparc/arch_%U';
backup as compressed backupset database format '/backup/backupset/dbfull_%d_%s_u%_%p.bak' plus archivelog delete all input format '/backup/backuparc/arch_%U';
backup current controlfile format '/backup/backupset/cf_%U';
--检查备份集并删除过期记录
--检查备份集并删除过期记录
crosscheck backup of database;
delete noprompt obsolete;
delete noprompt expired backup of database;
delete archivelog until time 'sysdate-30';
--检查备份日志并删除过期记录
--检查备份日志并删除过期记录
crosscheck archivelog all;
delete noprompt expired archivelog all;
release channel c1;
release channel c2;
}
windows下:
分两步:
1、先写一个后缀名为.bat的批处理文件内容如下:
关于备份:
set ORACLE_SID=bhinsid
rman target sys/aqa cmdfile D:\autoscript\bakfull.sql
关于日志:
del D:\archivelog\*.arc /s /f /q rem物理删除日志删除archivelog所有文件arc结尾文件
set ORACLE_SID=bhinsid
rman target sys/aqa cmdfile D:\autoscript\delarchivelog.sql
2、创建自动脚本:
关于备份集bakfull.sql
RUN {
allocate channel c1 type disk;
sql 'alter system archive log current';
backup current controlfile format 'G:\rmanbak\ctl_%U.ctl';
backup database format 'G:\rmanbak\db_%U' plus archivelog delete all input format 'G:\rmanbak\arch_%U';
crosscheck backupset;
delete expired backup;
delete noprompt obsolete ;
release channel c1;
}
关于日志delarchivelog.sql:
RUN {
allocate channel c1 type disk;
crosscheck archivelog all;
delete expired archivelog all;
delete archivelog all completed before 'sysdate-15';
release channel c1;
}
windows下:
分两步:
1、先写一个后缀名为.bat的批处理文件内容如下:
关于备份:
set ORACLE_SID=bhinsid
rman target sys/aqa cmdfile D:\autoscript\bakfull.sql
关于日志:
del D:\archivelog\*.arc /s /f /q rem物理删除日志删除archivelog所有文件arc结尾文件
set ORACLE_SID=bhinsid
rman target sys/aqa cmdfile D:\autoscript\delarchivelog.sql
2、创建自动脚本:
关于备份集bakfull.sql
RUN {
allocate channel c1 type disk;
sql 'alter system archive log current';
backup current controlfile format 'G:\rmanbak\ctl_%U.ctl';
backup database format 'G:\rmanbak\db_%U' plus archivelog delete all input format 'G:\rmanbak\arch_%U';
crosscheck backupset;
delete expired backup;
delete noprompt obsolete ;
release channel c1;
}
关于日志delarchivelog.sql:
RUN {
allocate channel c1 type disk;
crosscheck archivelog all;
delete expired archivelog all;
delete archivelog all completed before 'sysdate-15';
release channel c1;
}