This article is a shell script. Primarily for Oracle database backups. By default, it is fully prepared by the evening of Monday. Additional time for cumulative incremental backups.
How to use:
If the script is saved with the name: oracle_backup.sh
Use the method for Oracle_backup.sh-p $ORACLE _directory-l $BACKUP _level
Oracle_directory can be obtained from the dba_directories.
Backup_level:0 (fully prepared) 1 increments.
#!/bin/SH################################################################: This script was used to backup Oracle database With RMAN. # #: A full backup would be taken early moring on Monday. # #: I recomment that the incremental backup should is taken on # #: every day except Monday. # #: Made by Halberd (Asiainfo-PMO),20160827# #: Modify Records: # #:1. # #: Thu May4 +: the: WuCst .# #: Halberd # # Add getopts. MakeThe scripts MoreFlexible #################################################################: initial environmentsource
~/. bash_profile#: Judgeifparameters is offered[$#==0] &&Echo-E"Usage:: $-[pl]\n P--and backup path \ n---backup level with 0 (full) or 1 (incremental) \ n Examples:: \ n $- P/home/oracle-l 1"&& exit1#: Variables setting#: Attach the arguments values to their variables whilegetopts p:l: Option Do Case "$option" inchp) Back_path="$OPTARG" ;; L)if [ "$OPTARG"==0 ] ; Then Level=0 elif [ "$OPTARG"==1 ] ; Then Level=1 Else Echo "Level 0 or 1 is recommended. Should better choose 0 for full backup or 1 for incremental backup"Exit1 fi ;; \?) Echo "Usage: [-P <path>] [-l]" Echo "-p:the path in which backup files would be allocated" Echo "-l:rman backup level"Exit1 ;; Esac Done#: Initial other basic VARIABLESMD=`Date+%m%d ' weekday=`Date+%W`if[-Z"$BACK _path" ] ; ThenBack_path="$ORACLE _home"/DBSEcho-E"WARNING:: The backup piecies is stored in $ORACLE _home/dbs. \ n"fiif[-Z"$LEVEL" ] ; Then if["$weekday"==1 ] ; ThenLevel=0 ElseLevel=1 fifiBack_format="$BACK _path"/db"$LEVEL"'_%d_%t_%u' Echo "backup_path: $BACK _path" Echo "Backup_level:" "$LEVEL" Echo "Backup_format: $BACK _format"#: Generate the Rman commandsback_comm='run{Allocate channel C1 type disk;\nallocate channel C2 type Disk;\nallocate channel C3 type Disk;\nbackup as com Pressed Backupset incremental level'"$LEVEL"'Format'\ ' "$BACK _format" \ ''database include current controlfile plus archivelog delete input;\nrelease channel C1;\nrelease channel C2;\nrelease Channel C3;\n}\ncrosscheck archivelog all;\ndelete noprompt expired archivelog all;\nreport obsolete;\ndelete noprompt o Bsolete;\nexit'#: Execute Rman BackupEcho-E $back _comm| Rman Target sys/oracle Log"$BACK _path"/rman_"$MD". Logexit
Oracle Backup Scripts