This is the third of a series of excerpts from "Oracle DBA automation scripts" by Rajendra Gutta. Click for part one on cold backup under Unix and part two on hot backup under Unix. You can purchase the book here.
This section presents and
explains the scripts for taking a backup and recovering a database in the
Windows NT environment. We use the DOS Shell batch programming techniques
to automate the backup process. After the backup is complete, it is important to check the backup status by
reviewing log and error files generated by the scripts.
Cold Backup
Listing 3.9 performs a cold backup of a database under the Windows NT environment.
The cold backup script takes SID, the instance to be backed up, as
the input parameter. The general steps to write a backup script in Unix and
Windows NT are the same. The only difference is that we will be using commands
that are understood by Windows NT. Figure
3.6 shows the functionality of a cold backup program under Windows NT. Each
box represents a corresponding section in the program. For example, the Parameter
Checking section checks for the necessary input parameters and also checks for
the existence of the backup directories.
[IMAGE]
Listing 3.9 coldbackup_nt.bat
Cold Backup Script for Windows NT Checklist
Check to see that ORA_HOME, BACKUP_DIR, and
TOOLS are set to correct values according to your directory structure.
These variables are highlighted in the script.
Verify that CONNECT_USER is set to correct the username and
password.
Define the INIT_FILE variable to the location of the
Init.ora file.
Be sure that the user running the program has Write access to backup
directories.
When you run the program, pass SID as a parameter.
Cold ...
To continue reading for free, register below or login
To read more you must become a member of SearchOracle.com
');
// -->

Backup under Windows NT Troubleshooting and Status Check
Backup log files defined by LOG_FILE contain detailed information
about each step of the backup process. This is a very good place to start
investigating why a backup has failed or for related errors. This file will also
have the start and end time of backup. ERR_FILE has error
information.
A single line about the success or failure of backup is appended to the
SID.log file every time a backup is performed. This file is located
under the directory defined by the LOGDIR variable. The messages for a
cold backup are 'COLDBACKUP_FAIL', if the cold backup failed,
and 'Cold Backup Completed successfully', if the backup
completes successfully.
You can schedule automatic backups using the 'at' command,
as shown in the following:
This command runs a backup at 23:00 hours every Monday, Tuesday, Wednesday,
Thursday, and Friday.
The "Create Dynamic Files" section in the
coldbackup_nt.bat program creates the coldbackup.sql file (see
Listing 3.10) under the log directory. coldbackup.sql is called from
coldbackup_nt.bat and generates a list of data, control, and redo log
files to be backed up from the database. A sample coldbackup.sql is
shown in Listing 3.10 for your understanding. The contents of this file are
derived based on the structure of the database.
Listing 3.10 coldbackup.sql
When the coldbackup.sql file is called from the coldbackup_nt.bat program, it
spools output to the coldbackup_list.bat DOS batch file (see Listing 3.11). This
file has the commands necessary for performing the cold backup.
This is only a sample file. Note that in the contents of file data, control,
redo log, and Init.ora files are copied to respective backup
directories.
Listing 3.11 coldbackup_list.bat
Hot Backup
The hot backup program (see Listing 3.12) performs a hot backup of a database
under the Windows NT environment. The hot backup script takes SID, the
instance to be backed up, as the input parameter.
Listing 3.12 hotbackup_nt.bat
Hot backup program functionality can be shown with the similar diagram as for
a cold backup. The sections and their purposes in the program are the same as
for a cold backup.
Hot Backup Script under Windows NT Checklist
Check to see that ORA_HOME, BACKUP_DIR, and
TOOLS are set to the correct values according to your directory
structure. These variables are highlighted in the script.
Verify that CONNECT_USER is set to the correct username and
password.
Define the INIT_FILE variable to the location of the
Init.ora file.
Define the ARC_DEST variable to the location archive
destination.
Be sure that the user running the program has Write access to the backup
directories.
When you run the program, pass SID as a parameter.
Hot Backup under Windows NT Troubleshooting and Status Check
The backup log file defined by LOG_FILE contains detailed
information about each step of the backup process. This is a very good place to
start investigating why a backup has failed or for related errors. This file
will also have the start and end time of backup. ERR_FILE has error
information.
A single line about the success or failure of backup is appended to the
SID.log file every time a backup is performed. This file is located
under the directory defined by the LOGDIR variable. The messages for a
hot backup are 'HOTBACKUP_FAIL', if a hot backup failed, and
'Hot Backup Completed successfully', if a backup completes
successfully.
The "Create Dynamic Files" section, in the
hotbackup_nt.bat creates the hotbackup.sql file (see Listing
3.13) under the log directory. This generates a list of tablespaces, data,
control, and redo log files from the database. It is called from the
hotbackup_nt.bat program.
Listing 3.13 hotbackup.sql
The hotbackup.sql file is called from hotbackup_nt.bat and it spools output
to the hotbackup_list.sql SQL file (see Listing 3.14). This file has the
commands necessary for performing a hot backup.
This is only a sample file. Note in the file that the data, control, archive
log, and Init.ora files are copied to their respective backup
directories. First, it puts the tablespace into Backup mode, copies the
corresponding files to backup location, and then turns off the Backup mode for
that tablespace. This process is repeated for each tablespace, and each
copy command puts the status of the copy operation to
hbackup.log and reports any errors to the herrors.log
file.
Listing 3.14 is generated based on the structure of the database. In a real
environment, the database structure changes as more data files or tablespaces
get added. Because of this, it is important to generate the backup commands
dynamically, as shown in hotbackup_list.sql. It performs the actual
backup and is called from hotbackup_nt.bat.
Listing 3.14 hotbackup_list.sql
Export
The export program (see Listing 3.15) performs a full export of the database
under a Windows NT environment. The export script takes SID, the
instance to be backed up, as the input parameter.
Listing 3.15 export_nt.bat
This program performs an export of the database by using the parameter file
specified by export_par.txt. In Listing 3.16 is a sample parameter file that
performs a full export of the database. You can modify the parameter file to
suit to your requirements.
Listing 3.16 export_par.txt
Export Script under Windows NT Checklist
Check to see that ORA_HOME and BACKUP_DIR, TOOLS are
set to correct values according to your directory structure. These variables are
highlighted in the program.
Verify that CONNECT_USER is set to the correct username and
password.
Be sure that the user running the program has Write access to the backup
directories.
Edit the parameter file to your specific requirements. Specify the full
path of the location of your parameter file in the program.
When you run the program, pass SID as a parameter.
Export under Windows NT Troubleshooting and Status Check
The log file specified in the parameter file contains detailed information
about each step of the export process. This is a very good place to start
investigating why an export has failed or for related errors.
A single line about the success or failure of export is appended to the
SID.log file every time an export is performed. This file is located
under the directory defined by the LOGDIR variable. The messages for an
export are 'EXPORT_FAIL', if the export failed, and
'Export Completed successfully', if the export completes
successfully.
Reader Feedback:
Frank P. writes: Your article on Windows backups for Oracle is incorrect. In a hot backup, Oracle recommends the use of the supplied OCOPY utility, NOT Windows copy. See Metalink note #139327.1. Also, I believe that the scripts are using O/S authentication. This has major security risks and should be noted. Otherwise, good tip.
Do you have feedback to share? Send it in!