RMAN 增量备份shell脚本

前2天给公司的测试库写了个shell备份脚本,复杂的不会写,只能先从简单的入手,现贴出脚本文件供大家学习参考,有不对的地方也请大家多多指出!

#”――――――――sunday―――――――――――-”
source /home/oracle/.bash_profile
$ORACLE_HOME/bin/rman <<EOF
connect target /
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0 database format ‘/u02/rman/full_0_%u.bak’;
backup archivelog all format ‘/u02/rman/arch_%u.bak’;
backup current controlfile format ‘/u02/rman/control_%u.bak’;
release channel d1;
release channel d2;
}
list backup;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
exit;
EOF
echo “――――――――-end――――――――――”;date
#”――――――――monday―――――――――――-”
source /home/oracle/.bash_profile
$ORACLE_HOME/bin/rman <<EOF
connect target /
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 1 database format ‘/u02/rman/bp_1_%u.bak’;
backup archivelog all format ‘/u02/rman/arch_%u.bak’;
backup current controlfile format ‘/u02/rman/control_%u.bak’;
release channel d1;
release channel d2;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
exit;
EOF
echo “――――――――-end――――――――――”;date
#”――――――――tuesday―――――――――――-”
source /home/oracle/.bash_profile
$ORACLE_HOME/bin/rman <<EOF
connect target /
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 1 database format ‘/u02/rman/bp_1_%u.bak’;
backup archivelog all format ‘/u02/rman/arch_%u.bak’;
backup current controlfile format ‘/u02/rman/control_%u.bak’;
release channel d1;
release channel d2;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
exit;
EOF
echo “――――――――-end――――――――――”;date
#”――――――――wendesday―――――――――――-”
source /home/oracle/.bash_profile
$ORACLE_HOME/bin/rman <<EOF
connect target /
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 2 database format ‘/u02/rman/bp_2_%u.bak’;
backup archivelog all format ‘/u02/rman/arch_%u.bak’;
backup current controlfile format ‘/u02/rman/control_%u.bak’;
release channel d1;
release channel d2;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
exit;
EOF
echo “――――――――-end――――――――――”;date
#”――――――――thursday―――――――――――-”
source /home/oracle/.bash_profile
$ORACLE_HOME/bin/rman <<EOF
connect target /
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 1 database format ‘/u02/rman/bp_1_%u.bak’;
backup archivelog all format ‘/u02/rman/arch_%u.bak’;
backup current controlfile format ‘/u02/rman/control_%u.bak’;
release channel d1;
release channel d2;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
exit;
EOF
echo “――――――――-end――――――――――”;date
#”――――――――Friday―――――――――――-”
source /home/oracle/.bash_profile
$ORACLE_HOME/bin/rman <<EOF
connect target /
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 2 database format ‘/u02/rman/bp_2_%u.bak’;
backup archivelog all format ‘/u02/rman/arch_%u.bak’;
backup current controlfile format ‘/u02/rman/control_%u.bak’;
release channel d1;
release channel d2;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
exit;
EOF
echo “――――――――-end――――――――――”;date
#”――――――――saturday―――――――――――-”
source /home/oracle/.bash_profile
$ORACLE_HOME/bin/rman <<EOF
connect target /
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 1 database format ‘/u02/rman/bp_1_%u.bak’;
backup archivelog all format ‘/u02/rman/arch_%u.bak’;
backup current controlfile format ‘/u02/rman/control_%u.bak’;
release channel d1;
release channel d2;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
exit;
EOF
echo “――――――――-end――――――――――”;date
把每天的脚本代码写进一个sh文件然后设置crontab
crontab如下
10 1 * * 0 /u01/crontab_bp_shell/sunday_bp.sh
10 1 * * 1 /u01/crontab_bp_shell/monday_bp.sh
10 1 * * 2 /u01/crontab_bp_shell/tuesday_bp.sh
10 1 * * 3 /u01/crontab_bp_shell/wendesday_bp.sh
10 1 * * 4 /u01/crontab_bp_shell/thursday_bp.sh
10 1 * * 5 /u01/crontab_bp_shell/friday_bp.sh
10 1 * * 6 /u01/crontab_bp_shell/saturday_bp.sh
好了,一个简单的备份策略就这样出来了!


你可能感兴趣的:(rman)