The recent need for a scheduled Oracle Backup program, can be restored to the latest state, reference http://blog.sina.com.cn/s/blog_7756ebc30100tnqy.html, I have in the shell processing a bit, Get 2 shell scripts, init.sh, oraclebackup.sh, execute init.sh param1 (backup file path) param2 (archive log path), you can set up a scheduled backup, the script will set the timer, For more information, see the opening instructions for the init.sh file, and post the scripting code below:
init.sh
#!/bin/sh
# Oracle Automatic Timing Backup Program
#说明: Init.sh and oraclebackup.sh are 2 shell scripts for Oracle automatic scheduled backups.
# Backup tool: RMAN
# Backup mode: Incremental backup
# Archive Mode: Yes
# Use example:./init.sh/home/dev/databasebackup/home/dev/archivelogbackup
# The first parameter is the directory where the Oracle backup files are stored, and the second is the storage directory of the archived redo logs
# Backup the archive redo log every time the database is backed up, and then delete the archive redo log
# these 2 scripts need to be placed on an Oracle server
# Environment variables need to be configured well in advance Oracle_base,oracle_home,oracle_sid
# Oracle Default non-archive mode after installation
# init.sh need to restart the database during script execution
#init. Sh Script Execution Process:
# 1. Replace the 2 directory parameters with the oraclebackup.sh
# 2. Replace the ORACLE_BASE,ORACLE_HOME,ORACLE_SID 3 environment variables with the oraclebackup.sh
# 3. Configure Rman
# 4. Set Oracle to archive mode
# 5. Generate Timer files
# 6. Set Timer, timing Oracle Backup, backup file default save 15 days
# Perform level 0 backups every Sunday 1:00
# from Monday to Wednesday, Friday to Saturday 1:00 perform a Level 2 incremental backup
# Perform level 1 incremental backups every Thursday 1:00
# Perform tests every Saturday 16:00
# Delete Expired backup data every Sunday 18:00
#
# after init.sh is done, you can also perform a manual backup and restore of the database
# Perform level 0 backup:
# oraclebackup.sh-l0
# Perform Level 1 backup
# ORACLEBACKUP.SH-L1
# Perform level 2 backup
# ORACLEBACKUP.SH-L2
# Detect Backup Integrity
# oraclebackup.sh-c
# Delete Expired backups, save for 15 days by default
# oraclebackup.sh-d
# Restore the database to the latest state
# Oraclebackup.sh-r
#日志:
# The log executed by the script is in the Rmanlog directory of the first parameter (/home/dev/databasebackup), that is,/home/dev/databasebackup/rmanlog,
# Check the log below this folder periodically to see the backup information
#配置RMAN, backup for 15 days, optimized backup, automatic backup control file, control file backup location
template_rmancmd= "Connect target/;
Run {
CONFIGURE RETENTION POLICY to RECOVERY WINDOW of the days;
CONFIGURE BACKUP optimization on;
CONFIGURE Controlfile autobackup on;
CONFIGURE controlfile autobackup FORMAT for DEVICE TYPE DISK to ' oldpath_database/controlfile_backup/controlfile_%f ';
}"
#把oracle设置为归档模式
function Setarchivelog ()
{
Sqlplus/as SYSDBA <<eof
Shutdown immediate;
startup Mount;
ALTER DATABASE Archivelog;
Alter system set CONTROL_FILE_RECORD_KEEP_TIME=30 Scope=both;
Alter system set log_archive_dest_1= ' Location=${archivelog_path}/archivelog ' Scope=both;
ALTER DATABASE open;
Alter system archive log start;
Exit
Eof
}
#创建定时器文件crontabfile, set timer
#每周日1:00 perform level 0 backup
#每周一至周三, Friday to Saturday 1:00 perform a Level 2 incremental backup
#每周四1:00 perform level 1 incremental backups
#每周六16:00 performing detection
#每周日18:00 Delete expired backup data
function Setcrontab ()
{
If [-E./crontabfile]
Then
Rm./crontabfile
Fi
#创建子目录, create archivelog under archive log directory
#数据库备份目录下创建rmanlog, Controlfile_backup,database_backup Directory
#如果已经存在, you do not create
function Makesubdir ()
{
if [!-D "${archivelog_path}/archivelog"]
Then
mkdir ${archivelog_path}/archivelog
Fi
if [!-D "${archivelog_path}/rmanlog"]
Then
mkdir ${database_path}/rmanlog
Fi
if [!-D "${archivelog_path}/controlfile_backup"]
Then
mkdir ${database_path}/controlfile_backup
Fi
if [!-D "${archivelog_path}/database_backup"]
Then
mkdir ${database_path}/database_backup
Fi
}
#把数据库备份目录参数替换到oraclebackup. Sh
function Replacedatabasebakpath ()
{
Sed-i "S#^\ (${key1} *= *\) \ ([^]*\) \ (*.*\) #\1${database_path}\3#"./oraclebackup.sh
}
#把归档日志目录参数替换到oraclebackup. Sh
function Replacearchivelogbakpath ()
{
Sed-i "S#^\ (${key2} *= *\) \ ([^]*\) \ (*.*\) #\1${archivelog_path}\3#"./oraclebackup.sh
}
#检查oracle备份文件, if there is a corrupted record, it is placed in the V$database_block_corruption view,
#需要DBA定期检查V $DATABASE _block_corruption View, after the block is repaired,
The corresponding records in the #V $DATABASE _block_corruption are automatically deleted
function Backupcheck ()
{
Rman log=\ ' ${database_path}/rmanlog/rmancheck.log\ ' append <<eof
Connect target/;
Run {
#check Database
Backup validate check logical database;
#check Backup Set
Restore database validate check logical;
#crosscheck Backup
Crosscheck backup;
}
Eof
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.