RMAN-自动备份脚本

发布时间 2023-03-28 11:20:51作者: 小狍

全备份

. ~/.bash_profile
DATE=`date +%Y-%m-%d-%H-%M-%S'
rman target / log=/u01/rman/log/rman_full_log_$DATE <<eof
run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
sql 'alter system archive log current';
crosscheck archivelog all;
delete noprompt expired backup;
backup as backupset database format
'/u01/rman/backup/rmanfull_%d_%T_%s_%p.bak';
sql 'alter system archive log current';
sql 'alter system archive log current';
sql 'alter system archive log current';
backup format '/u01/rman/backup/archfull%T%U' archivelog all;
crosscheck archivelog all;
delete noprompt archivelog until time='sysdate-3';
backup spfile format '/u01/rman/backup/spfile_%d_%T_%s_%p.bak';
backup current controlfile format '/u01/rman/backup/control_%d_%T_%s_%p.bak';
crosscheck archivelog all;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
report need backup;
release channel c1;
}
eof
find /u01/rman/backup/ -mtime +4 | xargs rm -f
find /u01/rman/log/ -mtime +7 | xargs rm -f

0级备份

. ~/.bash_profile
DATE=`date +%Y-%m-%d-%H-%M-%S'
rman target / log=/u01/rman/log/rman_0_log_$DATE <<eof
run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
sql 'alter system archive log current';
crosscheck archivelog all;
delete noprompt expired backup;
backup incremental level 0 database tag 'full' format
'/u01/rman/backup/0/level0_%d_%s_%p_%u.bak'
plus archivelog tag 'arch.bak' format
'/u01/rman/backup/0/arc_level0_%d_%s_%p_%u.bak' delete all input;
crosscheck archivelog all;
delete noprompt archivelog until time='sysdate-3';
backup tag 'spfile_bak' format '/u01/rman/backup/0/%d_spfile_%s_%T.bak' spfile;
backup tag 'ctl_bak' format '/u01/rman/backup/0/%d_ctl_%s_%T.bak' current controlfile;
release channel d1;
release channel d2;
}
eof

增量备份1

. ~/.bash_profile
DATE=`date +%Y-%m-%d-%H-%M-%S'
rman target / log=/u01/rman/log/rman_1_log_$DATE <<eof
run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 1 database format
'/u01/rman/backup/1/level1_%d_%s_%p_%u.bak'
plus archivelog tag 'level1_archive' format
'/u01/rman/backup/1/arc_level1_%d_%s_%p_%u.bak' delete all input;
crosscheck archivelog all;
delete noprompt archivelog until time='sysdate-3';
release channel d1;
release channel d2;
}
eof

增量备份2

. ~/.bash_profile
DATE=`date +%Y-%m-%d-%H-%M-%S'
rman target / log=/u01/rman/log/rman_2_log_$DATE <<eof
run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 2 database format
'/u01/rman/backup/2/level2_%d_%s_%p_%u.bak' plus
archivelog tag 'level2_archive' format
'/u01/rman/backup/2/arc_level2_%d_%s_%p_%u.bak' delete all input;
crosscheck archivelog all;
delete noprompt archivelog until time='sysdate-3';
release channel d1;
release channel d2;
}
eof