Task 1: Preparing to Use the Oracle Suggested Backup Strategy
To use the Oracle suggested backup strategy, ensure that:
The database is ARCHIVELOG mode
The fast recovery area size is configured, or a default device for storing backups is configured.
You have added a database host user to the OSBACKUPUPDBA operating system group, for operating system authentication.
Task 2: Create the Backup full Script-UNIX and Linux
[oracle@SERVER_DATABASE rman]$ pwd
/u01/app/oracle/rman_backup
[oracle@SERVER_DATABASE rman]$ more backup_script_full.sh
#!/bin/bash
ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/db_1;export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
PATH=$PATH:$ORACLE_HOME/bin; export PATH
chk_date=`date +%d`
chk_parity=`expr $chk_date % 2`
export bkdir=/backup11
BACKUP_DIR=$bkdir; export BACKUP_DIR
export DATA_DIR=$BACKUP_DIR/backup_full
export ARC_DIR=$BACKUP_DIR/backup_full
export BACKUP_DATA=$DATA_DIR/$ORACLE_SID"_data_f%t_s%s_s%p"
export BACKUP_ARC=$ARC_DIR/$ORACLE_SID"_arc_f%t_s%s_s%p"
export ORACLE_OWNER=oracle
export DATE=`date +%Y%m%d`
export IP=168_133
########### SCRIPT CHECK BACKUP FAILED############
backup_log_err='/u01/app/monitoring/log/backup_log.err';
backup_log_finish='/u01/app/monitoring/log/backup_log.finish';
/usr/bin/ls -lt /u01/app/rman_backup/log_full > $list_file;
i=1
while read line
do
let i=$i+1;
if [ $i -gt 2 ]
then
backup_log='/u01/app/rman_backup/log_full/'`echo $line | awk '{print $9}'`;
break;
fi
done < "$list_file"
grep -i error $backup_log > $backup_log_err
grep "Recovery Manager complete" $backup_log > $backup_log_finish
if [ `cat $backup_log_err|wc -l` -gt 0 ]
then
echo 'Backup have error';
exit;
fi
if [ !`cat $backup_log_finish|wc -l` -gt 0 ]
then
echo 'Backup have not finished yet';
exit;
fi
#######################################
cd $BACKUP_DIR
rm -rf backup_full_*
mv backup_full backup_full_$DATE
mkdir -p $DATA_DIR
mkdir -p $ARC_DIR
$ORACLE_HOME/bin/rman target / log /u01/app/rman_backup/log_full/rman_backup_full_$IP"_"$DATE.log <<EOF
RUN {
CROSSCHECK BACKUP OF DATABASE;
CROSSCHECK ARCHIVELOG ALL;
BACKUP AS COMPRESSED BACKUPSET FORMAT '$BACKUP_ARC' ARCHIVELOG ALL DELETE INPUT;
BACKUP AS COMPRESSED BACKUPSET FORMAT '$BACKUP_DATA' DATABASE SKIP READONLY;
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP AS COMPRESSED BACKUPSET FORMAT '$BACKUP_ARC' ARCHIVELOG ALL DELETE INPUT;
BACKUP CURRENT CONTROLFILE;
}
exit;
EOFTask 3: Testing the Backup Script
[oracle@SERVER_DATABASE rman]$ chmod 775 backup_script_full.sh [oracle@SERVER_DATABASE rman]$ nohup ./ backup_script_full.sh & [oracle@SERVER_DATABASE rman]$ tailf nohup.log RMAN-00557: could not open MSGLOG "/u01/app/rman_backup/log_full/rman_backup_full_165_145_20151225.log" Recovery Manager: Release 11.2.0.4.0 - Production on Fri Dec 25 17:05:50 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database:ORCL (DBID=1723703927) RMAN> 2> 3> 4> 5> 6> 7> 8> 9> using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=4018 instance=ptud11 device type=DISK specification does not match any backup in the repository released channel: ORA_DISK_1 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=4018 instance=ptud11 device type=DISK validation succeeded for archived log archived log file name=+ARC/ptud1/archivelog/2015_12_17/thread_1_seq_3.256.898708303 RECID=4 STAMP=898708305 validation succeeded for archived log archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_1_seq_4.261.898767075 RECID=9 STAMP=898767075 validation succeeded for archived log archived log file name=+ARC/ptud1/archivelog/2015_12_21/thread_1_seq_5.262.899028659 RECID=10 STAMP=899028662 validation succeeded for archived log archived log file name=+ARC/ptud1/archivelog/2015_12_17/thread_2_seq_2.258.898708305 RECID=5 STAMP=898708307 validation succeeded for archived log archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_3.257.898767069 RECID=6 STAMP=898767069 validation succeeded for archived log archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_4.259.898767073 RECID=7 STAMP=898767072 validation succeeded for archived log archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_5.260.898767073 RECID=8 STAMP=898767072 validation succeeded for archived log archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_2_seq_6.263.899384879 RECID=11 STAMP=899384883 Crosschecked 8 objects Starting backup at 25-DEC-15 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting compressed archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=2 sequence=2 RECID=5 STAMP=898708307 input archived log thread=1 sequence=3 RECID=4 STAMP=898708305 input archived log thread=2 sequence=3 RECID=6 STAMP=898767069 input archived log thread=1 sequence=4 RECID=9 STAMP=898767075 input archived log thread=2 sequence=4 RECID=7 STAMP=898767072 input archived log thread=2 sequence=5 RECID=8 STAMP=898767072 input archived log thread=1 sequence=5 RECID=10 STAMP=899028662 input archived log thread=2 sequence=6 RECID=11 STAMP=899384883 input archived log thread=1 sequence=6 RECID=13 STAMP=899399158 input archived log thread=2 sequence=7 RECID=12 STAMP=899399156 channel ORA_DISK_1: starting piece 1 at 25-DEC-15 channel ORA_DISK_1: finished piece 1 at 25-DEC-15 piece handle=/backup11/backup_full/ptud11_arc_f899399162_s1_s1 tag=TAG20151225T170602 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:25 channel ORA_DISK_1: deleting archived log(s) archived log file name=+ARC/ptud1/archivelog/2015_12_17/thread_2_seq_2.258.898708305 RECID=5 STAMP=898708307 archived log file name=+ARC/ptud1/archivelog/2015_12_17/thread_1_seq_3.256.898708303 RECID=4 STAMP=898708305 archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_3.257.898767069 RECID=6 STAMP=898767069 archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_1_seq_4.261.898767075 RECID=9 STAMP=898767075 archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_4.259.898767073 RECID=7 STAMP=898767072 archived log file name=+ARC/ptud1/archivelog/2015_12_18/thread_2_seq_5.260.898767073 RECID=8 STAMP=898767072 archived log file name=+ARC/ptud1/archivelog/2015_12_21/thread_1_seq_5.262.899028659 RECID=10 STAMP=899028662 archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_2_seq_6.263.899384879 RECID=11 STAMP=899384883 archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_1_seq_6.264.899399153 RECID=13 STAMP=899399158 archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_2_seq_7.265.899399155 RECID=12 STAMP=899399156 Finished backup at 25-DEC-15 Starting backup at 25-DEC-15 using channel ORA_DISK_1 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00004 name=+DATA/ptud1/datafile/users.259.898072689 input datafile file number=00002 name=+DATA/ptud1/datafile/sysaux.257.898072689 input datafile file number=00001 name=+DATA/ptud1/datafile/system.256.898072689 input datafile file number=00003 name=+DATA/ptud1/datafile/undotbs1.258.898072689 input datafile file number=00006 name=+DATA/ptud1/datafile/data.dbf input datafile file number=00008 name=+DATA/ptud1/datafile/vsa.dbf input datafile file number=00007 name=+DATA/ptud1/datafile/mdata.dbf input datafile file number=00005 name=+DATA/ptud1/datafile/undotbs2.261.898072819 channel ORA_DISK_1: starting piece 1 at 25-DEC-15 channel ORA_DISK_1: finished piece 1 at 25-DEC-15 piece handle=/backup11/backup_full/ptud11_data_f899399248_s2_s1 tag=TAG20151225T170727 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:35 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 25-DEC-15 channel ORA_DISK_1: finished piece 1 at 25-DEC-15 piece handle=/backup11/backup_full/ptud11_data_f899399343_s3_s1 tag=TAG20151225T170727 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 25-DEC-15 sql statement: ALTER SYSTEM ARCHIVE LOG CURRENT Starting backup at 25-DEC-15 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting compressed archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=7 RECID=14 STAMP=899399351 input archived log thread=2 sequence=8 RECID=15 STAMP=899399353 input archived log thread=1 sequence=8 RECID=17 STAMP=899399363 input archived log thread=2 sequence=9 RECID=16 STAMP=899399362 channel ORA_DISK_1: starting piece 1 at 25-DEC-15 channel ORA_DISK_1: finished piece 1 at 25-DEC-15 piece handle=/backup11/backup_full/ptud11_arc_f899399363_s4_s1 tag=TAG20151225T170923 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: deleting archived log(s) archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_1_seq_7.265.899399351 RECID=14 STAMP=899399351 archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_2_seq_8.264.899399353 RECID=15 STAMP=899399353 archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_1_seq_8.262.899399363 RECID=17 STAMP=899399363 archived log file name=+ARC/ptud1/archivelog/2015_12_25/thread_2_seq_9.263.899399363 RECID=16 STAMP=899399362 Finished backup at 25-DEC-15 Starting backup at 25-DEC-15 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set channel ORA_DISK_1: starting piece 1 at 25-DEC-15 channel ORA_DISK_1: finished piece 1 at 25-DEC-15 piece handle=/u01/app/oracle/product/12.1.0.2/db_1/dbs/05qpnfm4_1_1 tag=TAG20151225T170924 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 25-DEC-15 |
Task 4: Scheduling the Daily Backup –UNIX and Linux
Firstly, configure oracle allow use crontab
[root@SERVER_DATABASE ~]# more /etc/cron.allow root oracle |
Creating a crontab file for oracle user from the contents of .crontab.
[oracle@SERVER_DATABASE rman]$ crontab -e MAILTO=thonh53@gmail.com # MI HH DD MM DAY CMD 00 19 * * * /u01/app/rman_backup/rman_backup_full.sh > /dev/null 2>&1 |
Checking the contents of the crontab file for oracle user
[oracle@SERVER_DATABASE rman]$ crontab -l MAILTO=thonh53@gmail.com # MI HH DD MM DAY CMD 00 19 * * * /u01/app/rman_backup/rman_backup_full.sh > /dev/null 2>&1 |
(Optional) Checking crontab log.
[root@SERVER_DATABASE ~]# tailf /var/log/cron Oct 30 18:01:01 localhost run-parts(/etc/cron.hourly)[7601]: finished 0anacron Oct 30 18:01:01 localhost run-parts(/etc/cron.hourly)[7592]: starting mcelog.cron Oct 30 18:01:01 localhost run-parts(/etc/cron.hourly)[7616]: finished mcelog.cron Oct 30 18:01:44 localhost crontab[7744]: (oracle) BEGIN EDIT (oracle) Oct 30 18:01:55 localhost crontab[7744]: (oracle) REPLACE (oracle) Oct 30 18:01:55 localhost crontab[7744]: (oracle) END EDIT (oracle) Oct 30 18:02:01 localhost crond[2526]: (oracle) RELOAD (/var/spool/cron/oracle) Oct 30 18:02:12 localhost crontab[7783]: (root) BEGIN EDIT (root) Oct 30 18:02:14 localhost crontab[7783]: (root) END EDIT (root) Oct 30 18:02:28 localhost crontab[7805]: (root) LIST (oracle) Oct 30 19:00:00 localhost CROND[7842]: (oracle) CMD (/u01/app/oracle/rman/backup_script_full.sh) |
Download Script:
https://drive.google.com/open?id=0B7a3DEnQ0-uzVF9uVms0dUlmZW8
https://drive.google.com/open?id=0B7a3DEnQ0-uzVF9uVms0dUlmZW8
0 komentar:
Post a Comment