RMAN automatic backup and tape drive backup SHELL script

Source: Internet
Author: User
Tags rewind

(1) remote TELNET to back up data to the SHLL script of the tape drive

Lgmfcm:/u01/Oracle/CIC/BACKUP] cat TAPE_BACKUP.sh
:$ {OK = 0 }$ {FAIL = 1 }$ {CANCEL = 3}
: $ {MM = 'date + % m '}
: $ {DD = 'date + % d '}
: $ {YY = 'date + % y '}
: $ {DEVFILn = '/dev/rmt/0cn '}
: $ {FLOG =/u01/oracle/CIC/LOG/TAPE_bk _ $ {MM }$ {DD}. log}
: $ {FLST =/u01/oracle/CIC/LOG/TAPE_bk _ $ {MM }$ {DD}. lst}
:$ {HOST = 'uname-n '}
./U01/oracle/CIC/BACKUP/common. sh
START_YMD = 'date + % Y % m % d'
START_HMS = 'date + % H % M % s'
Echo "$ host tape Backup start at $ START_YMD $ START_HMS" >>$ FLOG
# Chkdate = 'get _ before_date $ {YY }$ {MM }$ {DD }'
# Tmpdate = 'expr substr $ chkdate 5 5'
/Usr/bin/mt-f $ {DEVFILn} rewind

If [$? -Eq 0]
Then
Echo "# Tape Check: Success/n" >>$ FLOG
Echo "# Tape Check: Success/n"
Else
Echo "# Tape Check: Error (Insert tape into Device)/n"> $ FLOG
Echo "# Tape Check: Error (Insert tape into Device)/n"

Exit $ {FAIL}
Fi

Echo "## Step 1: FULL Backup ###"> $ FLOG

Cd/

Find fz02/RMANBK/lgmfs/* $ {MM }$ {DD} *-print | sort-rn + 1 | head-9 | cpio-ocv-H od

C-C 30720-O $ DEVFILn | tee-a $ FLST

Find u08/EXP_BK/FZLFMES/* $ {MM} $ {DD}. *-print | cpio-ocv-H odc-C 30720-O $ DEV

FILn | tee-a $ FLST


Mt-f $ DEVFILn offline
Echo "## Step 1: FULL Backup End ###"> $ FLOG

Echo "please insert the secound tape"
Getyn "Was the secound tape insert? (Y/n )"

Echo "## Step 2: lgmf_db file & EXP Backup ###"> $ FL

OG

/Usr/bin/mt-f $ {DEVFILn} rewind
Cd/

Find fz02/RMANBK/lgmfs/* $ {YY }$ {MM }$ {DD} *-print | sort-n + 1 | head-7 | cpio-ocv-

H odc-C 30720-O $ DEVFILn | tee-a $ FLST
# Find u08/EXP_BK/lgmfs/* $ {MM} $ {DD}. *-print | cpio-ocv-H odc-C 30720-O $ DEV

FILn | tee-a $ FLST

Echo "## Step 2: lgmf_db file & EXP Backup END ###">

$ FLOG

Mt-f $ DEVFILn offline
Echo "please insert the third tape"
Getyn "Was the third tape insert? (Y/n )"

/Usr/bin/mt-f $ {DEVFILn} rewind
Cd/

Echo "## Step 3: lgmf_arch & fzlfmes datafile & arch & export Backup

### "> $ FLOG
Find fz01/RMANBK/FZLFMES/* $ {MM }$ {DD} *-print | cpio-ocv-H odc-C 30720-O $ DEV

FILn | tee-a $ FLST
Find fz02/RMANBK/lgmfas/* $ {MM }$ {DD} *-print | sort-rn + 1 | sed-n'10, 11 p; 11q' | cpi

O-ocv-H odc-C 30720-O $ DEVFILn | tee-a $ FLST
Echo "## Step 3: lgmf_arch & fzlfmes datafile & arch & export Backup End

### "> $ FLOG

Mt-f $ DEVFILn offline

Echo "please insert the fourth tape"
Getyn "Was the fourth tape insert? (Y/n )"

/Usr/bin/mt-f $ {DEVFILn} rewind
Cd/

Echo "# Step 4: lgmf_arch & fzlfmes datafile & arch & export Backup

### "> $ FLOG
Find u08/EXP_BK/lgmfs/* $ {MM} $ {DD}. *-print | cpio-ocv-H odc-C 30720-O $ DEVF

ILn | tee-a $ FLST
Find u08/RMANBK/lgmfs/* $ {MM} $ {DD} *-print | cpio-ocv-H odc-C 30720-O $ DEVFI

Ln | tee-a $ FLST
Echo "# Step 4: lgmf_arch & fzlfmes datafile & arch & export Backup End

### "> $ FLOG

Cd/


(2) Automatic RMAN script:

[Lgmfisu: root]/u01/oracle/CIC/BACKUP> cat DB_FULL_lgmfis.sh
MM = 'date + % m'
DD = 'date + % d'
YY = 'date + % y'

RMAN_LOG_FILE =/u01/oracle/CIC/LOG/full_hot_lgmfc_$ {YY }$ {MM }$ {DD}. log

ORACLE_HOME =/u01/app/oracle/product/9.2.0
Export ORACLE_HOME

ORACLE_SID = lgmfiis
Export ORACLE_SID
ORACLE_HOME = $ ORACLE_HOME
Export ORACLE_HOME
ORACLE_SID = $ ORACLE_SID
Export ORACLE_SID
# Find/fz02/RMANBK/lgmf_mtime + 0-exec rm {}/;
Find/u08/RMANBK/lgmf_mtime + 0-exec rm {}/;
Rm-f/fz02/RMANBK/lgmfs/db_full *

/U01/app/oracle/product/9.2.0/bin/rman target/nocatalog msglog $ RMAN_LOG_FILE
Append <EOF
RUN {
BACKUP FULL
FILESPERSET 4
FORMAT '/fz02/RMANBK/lgmfs/db_full _ % T _ % s _ % P'
DATABASE;
SQL 'alter system archive log current ';
BACKUP
Filesperset 20
FORMAT '/u08/RMANBK/lgmfs/al _ % T _ % s _ % P'
Archivelog all delete input;
BACKUP
FORMAT '/fz02/RMANBK/lgmfas/cntrl _ % T _ % s _ % P'
Current controlfile;
}
EOF

# Find/fz02/RMANBK/lgmf_mtime + 0-exec rm {}/;
# Find/u08/RMANBK/lgmf_mtime + 0-exec rm {}/;
You have mail in/var/mail/root
[Lgmfisu: root]/u01/oracle/CIC/BACKUP>

Mt-f $ DEVFILn offline
END_YMD = 'date + % Y % m % d'
END_HMS = 'date + % H % M % s'

Echo "$ host tape Backup Successfully Ended At $ END_YMD $ END_HMS" >>$

FLOG

 

Another file: COMMON. SH

[Lgmfisu: root]/u01/oracle/CIC/BACKUP> cat common. sh
Get_before_date ()
{
Y = 'expr substr $1 1 4'
M = 'expr substr $1 5 2'
D = 'expr substr $1 7 2'
YY = 'expr $ Y-1'
MM = 'expr $ M-1'
DD = 'expr $ D-1'
MM = 'printf "% 02d" $ mm'
DD = 'printf "% 02d" $ dd'
Dd = $ Y $ MM
Dad = 'get _ mon_days $ dd'
Be_date = $ Y $ M $ DD
If [$ D-eq 01]
Then
If [$ M-ne 01]
Then
Be_date = $ Y $ MM $ dad
Fi
If [$ M-eq 01]
Then
Be_date = $ YY "1231"
Fi
Fi
Echo $ be_date

}


Getyn (){
While echo "/n $ * (y/n )? /C"
Do read yn
Case "$ yn" in
[Yy]) return $ OK ;;
[Nn]) ConfirmYn "cancel The Job? ";;
*) Echo "Please enter y or n ";;
Esac
Done
}

ConfirmYn (){
While echo "/n $ * (y/n )? /C"
Do read yn
Case "$ yn" in
[Nn]) return $ OK ;;
[Yy]) echo "/n The Job is canceled ."
Sleep 3
Exit $ CANCEL ;;
*) Echo "Please enter y or n ";;
Esac
Done
}

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.