linux 计划任务 数据库rman全备份
[root@ipolx1 ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
01 0 * * * oracle /script/db_backup.cmd
[root@ipolx1 ~]# cat /script/db_backup.cmd
source /home/oracle/.bash_profile
rman target / cmdfile=/script/db_backup.rman > /script/log/rman.log
sqlplus /nolog @/script/create_restore.sql >> /script/log/rman.log
export datetime=`date '+%Y%m%d.%H%M%S'`
mv /script/log/rman.log /script/log/rman.log.$datetime
exit
[root@ipolx1 ~]# cat /script/db_backup.rman
run
{
delete backup;
}
run
{
configure maxsetsize to unlimited ;
configure device type disk parallelism 4;
configure controlfile autobackup on;
allocate channel c1 type disk format '/oradata/rman_data/%d_%T_%s_%U.DBF' maxpiecesize 2g;
allocate channel c2 type disk format '/oradata/rman_data/%d_%T_%s_%U.DBF' maxpiecesize 2g;
allocate channel c3 type disk format '/oradata/rman_data/%d_%T_%s_%U.DBF' maxpiecesize 2g;
allocate channel c4 type disk format '/oradata/rman_data/%d_%T_%s_%U.DBF' maxpiecesize 2g;
backup tag 'full' database;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
run
{
configure device type disk parallelism 1;
configure controlfile autobackup format for device type disk to '/oradata/rman_data/%F.CTL';
allocate channel c1 type disk format '/oradata/rman_data/%d_%T_%s_U.ARC' ;
backup archivelog all delete input;
release channel c1;
}
[root@ipolx1 ~]# cat /script/create_restore.sql
connect / as sysdba;
define base_date=sysdate
define dest_path=/oradata
set pagesize 10000;
set linesize 200;
set heading off;
set verify off;
set feedback off;
spool /oradata/restore.rcv;
prompt connect target / ;
select 'restore controlfile from ''' || max(handle) || ''';'
from v$backup_piece
where handle like '%.CTL' ;
prompt alter database mount;;
prompt run { ;
select 'set until sequence ' || to_char(sequence# + 1) || ' thread ' || thread# || ';'
from v$backup_redolog
where next_change# = (select max(next_change#) from v$backup_redolog) ;
select 'set newname for datafile ' || file# || ' to ''&dest_path' ||
substrb(name, instr(name,'/',-1)) || ''';'
from v$datafile;
prompt restore database from tag 'FULL';;
prompt switch datafile all;;
prompt recover database;;
prompt } ;
spool off;
spool /oradata/recover.rcv;
select 'alter database rename file ''' || member || '''' ||
' to ''&dest_path' || substrb(member, instr(member,'/',-1)) || ''';'
from v$logfile;
prompt alter database open resetlogs;;
prompt alter tablespace temp add tempfile '&dest_path/TEMP01.DBF' size 50M;;
prompt shutdown abort ;;
prompt startup ;;
prompt exit ;
spool off ;
exit
[root@ipolx1 ~]#