Views

Wednesday, October 26, 2016

Oracle - Taking Full Backup of Oracle Database

Taking full backup of Oracle Database.
 =========================
Unix Shell script to take full backup of Oracle 11g database.

Dbname – ORADB1
Backup location - /u02/backup
Log location - /u02/backup/log

#!/bin/bash
# Shell script to take rman level0 backup
# Environment variables
export ORACLE_HOME=/u02/app/oracle/product/11.2.0/db_1
export ORACLE_SID=$1
export LOG_DIR=/u02/backup/log
export BACKUP_DIR=/u02/backup
export NLS_DATE_FORMAT="MM/DD/YY HH24:MI:SS"
export TIMESTAMP=`date +%T-%m-%d-%Y`
export BACKUP_TYPE=FULL
export BACKUP_MEDIA=DISK
export MAXPIECESIZE=1G
export LOGFILE=$LOG_DIR/${ORACLE_SID}_${BACKUP_TYPE}_${BACKUP_MEDIA}_${TIMESTAMP}.log
# Script usage
if [ "$#" -ne 1 ]; then
  echo "Usage: level0.sh ORACLE_SID"
  exit 1
fi
# check if logged on with oracle user
if [ `whoami` != "oracle" ]; then
  echo "Must be logged on as oracle to run this script."
  exit 1
fi
# check if backup directory exist
if [ ! -d "$BACKUP_DIR" ]; then
        echo "Backup directory $BACKUP_DIR does not exist"
        exit 1
fi
# check if log directory exist
if [ ! -d "$LOG_DIR" ]; then
        echo "Log directory $LOG_DIR does not exist"
        exit 1
fi
echo `date` "Starting $BACKUP_TYPE Backup of $ORACLE_SID to $BACKUP_MEDIA" > $LOGFILE
# starting rman client
rman target / log=$LOGFILE <<EOF
run
{
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "/u02/backup/rman/ctl_%F";
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2;
allocate channel c1 type disk
format '${BACKUP_DIR}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}_%u_%p_%s' maxpiecesize ${MAXPIECESIZE};
backup incremental level 0 tag = 'Level0' database include current controlfile
PLUS ARCHIVELOG format '${BACKUP_DIR}/${ORACLE_SID}_Arch_${TIMESTAMP}_%u_%p_%s';
backup spfile format '${BACKUP_DIR}/${ORACLE_SID}_spfile_${TIMESTAMP}_%u_%p_%s';
}
exit
EOF

Files generated after backup.

[oracle@testing backup]$ ls /u02/backup
log
ORADB1_Arch_00:59:15-10-27-2016_0frjcbr4_1_15
ORADB1_Arch_00:59:15-10-27-2016_0irjcbsh_1_18
ORADB1_FULL_00:59:15-10-27-2016_0grjcbrb_1_16
ORADB1_FULL_00:59:15-10-27-2016_0hrjcbse_1_17
ORADB1_spfile_00:59:15-10-27-2016_0jrjcbsi_1_19
rman

[oracle@testing rman]$ ls /u02/backup/rman
ctl_c-2270880098-20161027-01

[oracle@testing rman]$ ls /u02/backup/log
ORADB1_FULL_DISK_00:59:15-10-27-2016.log

Lets look at the backup log file now.

[oracle@testing log]$ cat /u02/backup/log/ORADB1_FULL_DISK_00\:59\:15-10-27-2016.log

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Oct 27 00:59:15 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORADB1 (DBID=2270880098)

RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12>
using target database control file instead of recovery catalog
old RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
new RMAN configuration parameters:
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
new RMAN configuration parameters are successfully stored

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "/u02/backup/rman/ctl_%F";
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO "/u02/backup/rman/ctl_%F";
new RMAN configuration parameters are successfully stored

old RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 2;
new RMAN configuration parameters are successfully stored

allocated channel: c1
channel c1: SID=48 device type=DISK


Starting backup at 10/27/16 00:59:16
current log archived
channel c1: starting compressed archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=4 RECID=1 STAMP=925783884
input archived log thread=1 sequence=5 RECID=2 STAMP=925783934
input archived log thread=1 sequence=6 RECID=3 STAMP=925864250
input archived log thread=1 sequence=7 RECID=4 STAMP=926062473
input archived log thread=1 sequence=8 RECID=5 STAMP=926062681
input archived log thread=1 sequence=9 RECID=6 STAMP=926062712
input archived log thread=1 sequence=10 RECID=7 STAMP=926297747
input archived log thread=1 sequence=11 RECID=8 STAMP=926297872
input archived log thread=1 sequence=12 RECID=9 STAMP=926297956
channel c1: starting piece 1 at 10/27/16 00:59:16
channel c1: finished piece 1 at 10/27/16 00:59:23
piece handle=/u02/backup/ORADB1_Arch_00:59:15-10-27-2016_0frjcbr4_1_15 tag=LEVEL0 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:07
Finished backup at 10/27/16 00:59:23

Starting backup at 10/27/16 00:59:23
channel c1: starting compressed incremental level 0 datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u02/app/oracle/oradata/ORADB1/datafile/system01.dbf
input datafile file number=00002 name=/u02/app/oracle/oradata/ORADB1/datafile/sysaux01.dbf
input datafile file number=00005 name=/u02/app/oracle/oradata/ORADB1/datafile/example01.dbf
input datafile file number=00003 name=/u02/app/oracle/oradata/ORADB1/datafile/undotbs01.dbf
input datafile file number=00004 name=/u02/app/oracle/oradata/ORADB1/datafile/users01.dbf
channel c1: starting piece 1 at 10/27/16 00:59:23
channel c1: finished piece 1 at 10/27/16 00:59:58
piece handle=/u02/backup/ORADB1_FULL_00:59:15-10-27-2016_0grjcbrb_1_16 tag=LEVEL0 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:35
channel c1: starting compressed incremental level 0 datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 10/27/16 00:59:59
channel c1: finished piece 1 at 10/27/16 01:00:00
piece handle=/u02/backup/ORADB1_FULL_00:59:15-10-27-2016_0hrjcbse_1_17 tag=LEVEL0 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 10/27/16 01:00:00

Starting backup at 10/27/16 01:00:00
current log archived
channel c1: starting compressed archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=10 STAMP=926298001
channel c1: starting piece 1 at 10/27/16 01:00:01
channel c1: finished piece 1 at 10/27/16 01:00:02
piece handle=/u02/backup/ORADB1_Arch_00:59:15-10-27-2016_0irjcbsh_1_18 tag=LEVEL0 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 10/27/16 01:00:02

Starting backup at 10/27/16 01:00:02
channel c1: starting compressed full datafile backup set
channel c1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel c1: starting piece 1 at 10/27/16 01:00:02
channel c1: finished piece 1 at 10/27/16 01:00:03
piece handle=/u02/backup/ORADB1_spfile_00:59:15-10-27-2016_0jrjcbsi_1_19 tag=TAG20161027T010002 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 10/27/16 01:00:03

Starting Control File and SPFILE Autobackup at 10/27/16 01:00:03
piece handle=/u02/backup/rman/ctl_c-2270880098-20161027-01 comment=NONE
Finished Control File and SPFILE Autobackup at 10/27/16 01:00:06
released channel: c1

RMAN>

Recovery Manager complete.

Backup script Validation. You should have necessary validation in place for correct usage of script.

1.     running script without Oracle SID

[oracle@testing scripts]$ ./level0.sh
Usage: level0.sh ORACLE_SID

2.     running script without log directory

[oracle@testing backup]$ rm -rf log
[oracle@testing scripts]$ ./level0.sh ORADB1
Log directory /u02/backup/log does not exist

3.     running script without backup directory

[oracle@testing u02]$ mv backup backup1
[oracle@testing scripts]$ ./level0.sh ORADB1
Backup directory /u02/backup does not exist

4.     running script as non-oracle user

[oracle@testing scripts]$ su
Password:
[root@testing scripts]# ./level0.sh ORADB1
Must be logged on as oracle to run this script.



No comments:

Post a Comment

Leave a Reply...