Database Reference
In-Depth Information
■
the scripts in this section aren't meant to be production-strength backup and recovery scripts. rather, they
illustrate the basic concepts of scripting a cold backup and subsequent restore.
Note
The first script in this section makes a cold backup of a database. Before you use the cold backup script, you need
to modify these variables in the script to match your database environment:
ORACLE_SID
•
ORACLE_HOME
•
cbdir
The
cbdir
variable specifies the name of the backup-directory location. The script creates a file named
coldback.sql
, which is executed from SQL*Plus to initiate a cold backup of the database:
•
#!/bin/bash
ORACLE_SID=O12C
ORACLE_HOME=/u01/app/oracle/product/12.1.0.1/db_1
PATH=$PATH:$ORACLE_HOME/bin
#
sqlplus -s <<EOF
/ as sysdba
set head off pages0 lines 132 verify off feed off trimsp on
define cbdir=/u01/cbackup/O12C
spo coldback.sql
select 'shutdown immediate;' from dual;
select '!cp ' || name || ' ' || '&&cbdir' from v\$datafile;
select '!cp ' || name || ' ' || '&&cbdir' from v\$tempfile;
select '!cp ' || member || ' ' || '&&cbdir' from v\$logfile;
select '!cp ' || name || ' ' || '&&cbdir' from v\$controlfile;
select 'startup;' from dual;
spo off;
@@coldback.sql
EOF
exit 0
This file generates commands that are to be executed from an SQL*Plus script to make a cold backup of a
database. You place an exclamation mark (
!
) in front of the Unix
cp
command to instruct SQL*Plus to host out to the
OS to run the
cp
command. You also place a backward slash (
\
) in front of each dollar sign (
$
) when referencing
v$
data dictionary views; this is required in a Linux/Unix shell script. The
\
escapes the
$
and tells the shell script not to
treat the
$
as a special character (the
$
normally signifies a shell variable).