Exzilla.net
Contact
Home -> Articles -> OBR0-01 -> PERFORMING A FULL COLD BACKUP
 
Features
Forums
Files
Blogs
Document ID: # OBR-COLD-01 June 29, 2004
Document Title : A. PERFORMING A FULL COLD BACKUP  

Document Details :

A. PERFORMING A FULL COLD BACKUP

What to backup.

เราจำเป็น ต้องทำการ Backup Data file และ Control File ทั้งหมด ซึ่งเราสามารถตรวจสอบ Data files ทั้งหมดได้จาก statements เหล่านี้

select name from v$datafile;

select name from v$controlfile;

อย่างเช่น

$ sqlplus system/manager@viper

SQL*Plus: Release 8.1.6.0.0 - Production on Wed Feb 21 04:45:27 2001
(c) Copyright 1999 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oradata/viper/system01.dbf
/oradata/viper/tools01.dbf
/oradata/viper/rbs01.dbf
/oradata/viper/temp01.dbf
/oradata/viper/users01.dbf
/oradata/viper/indx01.dbf

6 rows selected.

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/oradata/viper/control01.ctl
/oradata/viper/control02.ctl
/oradata/viper/control03.ctl

SQL> exit

Disconnected from Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

$

ซึ่งเราก็จะได้รายชื่อ Data file ทั้งหมดมา นอกจาก รายชื่อ Data file เหล่านี้แล้ว เราควร Backup Parameter file และ password file ด้วย

Oracle ไม่แนะนำให้เรา Backup online redo log files อ่านเอกสารประกอบ (Oracle8i Backup and Recovery Guide, Release 2 (8.1.6), Part No. A76993-01, Avoid the backup of online redo logs, Page3-10)

A FULL COLD BACKUP

จากนั้น เราก็เริ่มขั้นตอนการ Backup Database แบบ FULL COLD BACKUP กัน โดยมีขั้นตอนดังนี้

1. ต้องทำการ Shutdown Database ก่อน

$
$ set -o vi
$ export ORACLE_SID=viper
$ svrmgrl

Oracle Server Manager Release 3.1.6.0.0 - Production
Copyright (c) 1997, 1999, Oracle Corporation. All Rights Reserved.
Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

SVRMGR> connect internal
Connected.
SVRMGR> select name from v$database;

NAME
---------
VIPER

1 row selected.

SVRMGR> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SVRMGR> exit
Server Manager complete.

$

2. ทำการ Copy Data files ทั้งหมด รวมทั้ง Parameter file และ Password file

cp /oradata/viper/system01.dbf /ub11h/oraBackup
cp /oradata/viper/tools01.dbf /ub11h/oraBackup
cp /oradata/viper/rbs01.dbf /ub11h/oraBackup
cp /oradata/viper/temp01.dbf /ub11h/oraBackup
cp /oradata/viper/users01.dbf /ub11h/oraBackup
cp /oradata/viper/indx01.dbf /ub11h/oraBackup
cp /oradata/viper/control01.ctl /ub11h/oraBackup
cp /oradata/viper/control02.ctl /ub11h/oraBackup
cp /oradata/viper/control03.ctl /ub11h/oraBackup
cp $ORACLE_HOME/dbs/orapwvier /ub11h/oraBackup
cp $ORACLE_HOME/admin/viper/pfile/initviper.ora /ub11h/oraBackup

3.Startup Database เพื่อกลับมาทำงานอย่างปกติ

$ export ORACLE_SID=viper
$ svrmgrl

Oracle Server Manager Release 3.1.6.0.0 - Production
Copyright (c) 1997, 1999, Oracle Corporation. All Rights Reserved.
Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production
SVRMGR> connect internal
Connected.

SVRMGR> startup
ORACLE instance started.
Total System Global Area 376086952 bytes
Fixed Size 94632 bytes
Variable Size 49020928 bytes
Database Buffers 326791168 bytes
Redo Buffers 180224 bytes
Database mounted.
Database opened.

SVRMGR> select name from v$database;

NAME
---------
VIPER
1 row selected.

SVRMGR> exit
Server Manager complete.

$

Recovery Database from A FULL COLD BACKUP

และเมื่อถึงขั้นเวลาที่เกิดควาเสียหายกับ Database ของเราก็ถึงเวลาของการ กู้ข้อมูลกลับมา ซึ่งสังเกตุว่า การ Backup Database แบบนี้เราจะได้ข้อมูลเฉพาะการ Backup ล่าสุดเท่านั้น ซึ่งก็แสดงว่าจะต้องมีข้อมูลบางส่วนหายไป :(

ตัวอย่างต่อไปนี้เป็นตัวอย่างการ Recovery Data กลับมาจากการทำ Backup แบบ A full cold backup

$ echo $ORACLE_SID

viper

$ svrmgrl

Oracle Server Manager Release 3.1.6.0.0 - Production
Copyright (c) 1997, 1999, Oracle Corporation. All Rights Reserved.
Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

SVRMGR> connect internal
Connected.
SVRMGR> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SVRMGR> exit
Server Manager complete.

$ ls -al

total 73
drwxr-xr-x 6 orasys dba 8192 Feb 22 00:59 .
drwxr-xr-x 32 root system 1024 Feb 14 08:00 ..
drwx------ 2 root system 8192 Jul 8 2000 .tags
drwxr-x--x 2 orasys dba 8192 Sep 6 23:41 dare
-rw-r----- 1 root operator 16384 Jul 8 2000 quota.group
-rw-r----- 1 root operator 16384 Jul 8 2000 quota.user
drwxr-xr-x 2 orasys dba 8192 Jul 14 2000 venom
drwxr-xr-x 2 orasys dba 8192 Feb 21 10:08 viper
$ mv viper viper.old
$ mkdir viper
$ pwd
/oradata

$ ls -al

total 81

drwxr-xr-x 7 orasys dba 8192 Feb 22 01:00 .
drwxr-xr-x 32 root system 1024 Feb 14 08:00 ..
drwx------ 2 root system 8192 Jul 8 2000 .tags
drwxr-x--x 2 orasys dba 8192 Sep 6 23:41 dare
-rw-r----- 1 root operator 16384 Jul 8 2000 quota.group
-rw-r----- 1 root operator 16384 Jul 8 2000 quota.user
drwxr-xr-x 2 orasys dba 8192 Jul 14 2000 venom
drwxr-xr-x 2 orasys dba 8192 Feb 22 01:00 viper
drwxr-xr-x 2 orasys dba 8192 Feb 21 10:08 viper.old

$
$ cd /ub11h/oraBackup
$ pwd
/ub11h/oraBackup
$ ls
control01.ctl control03.ctl initviper.ora rbs01.dbf temp01.dbf users01.dbf
control02.ctl indx01.dbf orapwviper system01.dbf tools01.dbf

$ cp *.dbf /oradata/viper
$ cp *.ctl /oradata/viper
$ ls /oradata/viper
control01.ctl control03.ctl rbs01.dbf temp01.dbf users01.dbf
control02.ctl indx01.dbf system01.dbf tools01.dbf

$ echo $ORACLE_SID
viper
$ svrmgrl

Oracle Server Manager Release 3.1.6.0.0 - Production
Copyright (c) 1997, 1999, Oracle Corporation. All Rights Reserved.
Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

SVRMGR> connect internal
Connected.
SVRMGR> startup
ORACLE instance started.
Total System Global Area 376086952 bytes
Fixed Size 94632 bytes
Variable Size 49020928 bytes
Database Buffers 326791168 bytes
Redo Buffers 180224 bytes
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/oradata/viper/redo01.log'

SVRMGR> recover database;
ORA-00283: recovery session canceled due to errors
ORA-00264: no recovery required
SVRMGR> alter database open resetlogs;
alter database open resetlogs
*
ORA-01139: RESETLOGS option only valid after an incomplete database recovery

SVRMGR>
SVRMGR> recover database until cancel;
Media recovery complete.
SVRMGR> alter database open resetlogs;

Statement processed.

SVRMGR>
SVRMGR> select instance,status,open_time from v$thread;
INSTANCE STATUS OPEN_TIME

---------------- ------ ---------
viper OPEN 22-FEB-01
1 row selected.

SVRMGR>

SVRMGR> exit
Server Manager complete.

$ ls /oradata/viper
control01.ctl control03.ctl rbs01.dbf redo02.log system01.dbf tools01.dbf
control02.ctl indx01.dbf redo01.log redo03.log temp01.dbf users01.dbf
$

Sample Scripts for A FULL COLD BACKUP

การที่เราต้องมานั่ง Key command line กันทุกครั้งที่ต้องทำงาน ก็อาจจะเกิดความผิดผลาดได้ ทางที่ดีก็ควรเขียน Script ไว้ใช้งานดีกว่านะครับ

ตัวอย่างนี้เป็นตัวอย่าง shell scripts ที่ ไป List รายชื่อ data files ทั้งหมดมา ด้วยก็ทำการ backup data file เหล่านั้น โดย script ก็จะมีขั้นตอนคร่าว ๆ คือ

  • list รายชื่อ file ทั้งหมด
  • shutdown Database
  • copy data files ทั้งหมดไปเก็บ
  • startup database กลับมา

#!/bin/ksh

################################################################
# aFullColdBackup.sh
# Dated: 18-Jan-2000
# Author: Teddy Graham, teddy@exzilla.net
# Developer Contact: Teddy Graham
# Subject: A FULL COLD BACKUP scripts
# Edition: 1.0
################################################################

# Step to A full cold backup
# 1. shutdown database
# 2. copy all datafile include parameter file and password file.
# 3. startup database

################################################################

# Please change below variable for macth your environment
# Change below for your backup distination directory
BACKUPDES=/ub11h/oraBackup
# Change for your Oracle SID
export ORACLE_SID=viper
# Change for your Oracle home
export ORACLE_HOME=/oracle/OraHome1

#####################################################
MYTMPFILE=/tmp/xx01.sql
MYDATAFILES=/tmp/xx02.txt
MYSTARTUP=/tmp/startup01.sql
MYSHUTDOWN=/tmp/shutdown01.sql
#####################################################

##Make a script file for list name of all files ###
cat > $MYTMPFILE << 0xff
set heading off
set pagesize 0
set feedback off
set echo off
spool $MYDATAFILES

select 'cp '|| name || ' $BACKUPDES' from v\$datafile;
select 'cp '|| name || ' $BACKUPDES' from v\$controlfile;

spool off

exit

0xff

##end list all file scripts ###

#####################################################
#####################################################

# Create Os command for backup all data file

#####################################################

sqlplus system/manager @$MYTMPFILE

#check all file for test all files that this scripts created
#echo "\necho from " $MYTMPFILE "\n"
#cat $MYTMPFILE
#echo "\necho from " $MYSTARTUP "\n"
#cat $MYSTARTUP
#echo "\necho from " $MYSHUTDOWN "\n"
#cat $MYSHUTDOWN

clear

#echo "\necho from " $MYDATAFILES "\n"

#cat $MYDATAFILES

############ Core Part ##########################

# shutdown DB

echo "\n*** Shutdown Database for Backup *****"
svrmgrl << 0xff
connect internal
shutdown immediate
exit

0xff

# Backup whole datafile
echo "\n\n***** Start copy all datafiles to backup Destination *****\n\n"
# Backup all datafile
echo "\n Wait for copy all data files :-| \n"
#cat $MYDATAFILES

sh $MYDATAFILES

echo "Finished copy all files :-) ,if you don't see any error text that mean completed ! "

# Backup parameters file and password file
#echo "cp $ORACLE_HOME/dbs/orapw$ORACLE_SID $BACKUPDES"

cp $ORACLE_HOME/dbs/orapw$ORACLE_SID $BACKUPDES

#echo "cp $ORACLE_HOME/admin/$ORACLE_SID/pfile/init$ORACLE_SID.ora $BACKUPDES

cp $ORACLE_HOME/admin/$ORACLE_SID/pfile/init$ORACLE_SID.ora $BACKUPDES

echo "\n\n***** End copy all datafiles to backup Destination *****\n\n"

# startup DB

echo "\n*** Startup Database for Backup *****"

svrmgrl << 0xff
connect internal
startup
exit

0xff

############ END Core Part ##########################
#### Clear all scripts ########
rm $MYTMPFILE
rm $MYDATAFILES
#### End clear all scripts ########

 

Sample Output Screen from Backup Scripts

ตัวอย่าง หน้าจอที่เกิดขึ้นจากการใช้งาน Script ด้านบน

*** Shutdown Database for Backup *****

Oracle Server Manager Release 3.1.6.0.0 - Production
Copyright (c) 1997, 1999, Oracle Corporation. All Rights Reserved.
Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production

SVRMGR> Connected.
SVRMGR> Database closed.
Database dismounted.
ORACLE instance shut down.
SVRMGR> Server Manager complete.

***** Start copy all datafiles to backup Destination *****

Wait for copy all data files :-|
Finished copy all files :-) ,if you don't see any error text that mean completed !

***** End copy all datafiles to backup Destination *****
*** Startup Database for Backup *****
Oracle Server Manager Release 3.1.6.0.0 - Production
Copyright (c) 1997, 1999, Oracle Corporation. All Rights Reserved.
Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production
SVRMGR> Connected.
SVRMGR> ORACLE instance started.
Total System Global Area 376086952 bytes
Fixed Size 94632 bytes
Variable Size 49020928 bytes
Database Buffers 326791168 bytes
Redo Buffers 180224 bytes
Database mounted.
Database opened.

SVRMGR> Server Manager complete.

$

Some Idea for Improve this backup script

1. Create log file for backup scripts

2. Error detecting while copy data files to backup destination

2.Scheduling Backup

More information

  • Oracle8i Backup and Recovery Guide, Release 2 (8.1.6), Part No. A76993-01
  • Otn.oracle.com



Copyright (c) 2001-2009 - Exzilla.net -  All Rights Reserved.
Contact Us | Privacy Policy | Terms & Conditions