最近用户在做备份审核,发现了很多问题。恰好通过这次审核,优化了备份脚本。分享给需要的朋友
环境说明:备份发起在备库执行,这样降低主库资源消耗(确实因为这个出过问题,头疼啊)
oracle 19c
单节点执行即可,注意需要配置账号和密码
全备leve0
#!/bin/bash
oracle_home=/u01/app/oracle/product/19/dbhome_1
export oracle_home
oracle_sid=test
export oracle_sid
mailto=ttttt@qq.com
execdate=`date "%y%m%d%h%m%s"`
backupname=`date "20%y%m%d"`
#echo `date "20%y%m%d"`
mkdir /backup/$backupname
#subject="$oracle_sid @ `hostname` db backup $execdate"
rman_log_file=/backup/log/$oracle_sid$execdate.out
rman=$oracle_home/bin/rman
target_connect_str=sys/password@oraclesid
destination=/backup/$backupname
echo ==== started on `date` ==== >> $rman_log_file
echo >> $rman_log_file
#find /backup -name
#rm $destination/*
$rman target $target_connect_str nocatalog log $rman_log_file <
run {
allocate channel ch00 type disk maxpiecesize=8000m;
allocate channel ch01 type disk maxpiecesize=8000m;
allocate channel ch02 type disk maxpiecesize=8000m;
allocate channel ch03 type disk maxpiecesize=8000m;
allocate channel ch04 type disk maxpiecesize=8000m;
allocate channel ch05 type disk maxpiecesize=8000m;
allocate channel ch06 type disk maxpiecesize=8000m;
allocate channel ch07 type disk maxpiecesize=8000m;
crosscheck copy;
delete noprompt expired copy;
crosscheck backup;
delete noprompt expired backup;
delete force noprompt backup device type disk completed before 'sysdate-1';
delete noprompt obsolete;
backup as compressed backupset incremental level 0
format '$destination/lev0_%u.bkp' database;
backup as compressed backupset archivelog all format '$destination/arch_%u.bkp';
crosscheck archivelog all;
delete noprompt archivelog until time 'sysdate-1';
backup current controlfile format '$destination/%d_ctrl_%u.bak';
backup spfile format '$destination/%d_spfile_%u.bak';
release channel ch00;
release channel ch01;
release channel ch02;
release channel ch03;
release channel ch04;
release channel ch05;
release channel ch06;
release channel ch07;
}
exit;
eof
echo >> $rman_log_file
df -h >> $rman_log_file
echo >> $rman_log_file
echo >> $rman_log_file
cp $rman_log_file $destination
mail -s "[ip] erpdb status:success" $mailto<
....`date`...
[ip] erpdb status:success
`tail -100 $rman_log_file`
eof
增量备份
#!/bin/bash
oracle_home=/u01/app/oracle/product/19/dbhome_1
export oracle_home
oracle_sid=test
export oracle_sid
mailto=ttttttttt@qq.com
execdate=`date "%y%m%d%h%m%s"`
backupname=`date "20%y%m%d"`
#echo `date "20%y%m%d"`
mkdir /backup/$backupname
#subject="$oracle_sid @ `hostname` db backup $execdate"
rman_log_file=/backup/log/$oracle_sid$execdate.out
rman=$oracle_home/bin/rman
target_connect_str=sys/password@testoracle_sid
destination=/backup/$backupname
echo ==== started on `date` ==== >> $rman_log_file
echo >> $rman_log_file
#find /backup -name
#rm $destination/*
$rman target $target_connect_str nocatalog log $rman_log_file <allocate channel ch00 type disk maxpiecesize=6000m;
allocate channel ch01 type disk maxpiecesize=6000m;
allocate channel ch02 type disk maxpiecesize=6000m;
allocate channel ch03 type disk maxpiecesize=6000m;
allocate channel ch04 type disk maxpiecesize=6000m;
crosscheck copy;
delete noprompt expired copy;
crosscheck backup;
delete noprompt expired backup;
delete force noprompt backup device type disk completed before 'sysdate-2';
delete noprompt obsolete;
sql 'alter system archive log current';
backup as compressed backupset incremental level 1
format '$destination/lev1_%u.bkp' database;
sql 'alter system archive log current';
backup as compressed backupset archivelog all format '$destination/arch_%u.bkp';
crosscheck archivelog all;
delete noprompt archivelog until time 'sysdate-1';
backup current controlfile format '$destination/control_%u_%t.bkp';
release channel ch00;
release channel ch01;
release channel ch02;
release channel ch03;
release channel ch04;
}
exit;
eof
echo >> $rman_log_file
df -h >> $rman_log_file
echo >> $rman_log_file
echo >> $rman_log_file
echo ==== ended on `date` ==== >> $rman_log_file
cp $rman_log_file $destination
mail -s "[ip ] erpdb status:success" $mailto<
最后修改时间:2022-11-17 15:34:25
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。