Backup Recovery   «Prev  Next»

Lesson 4Creating backup scripts
Objective Create a backup script.

Creating Backup Scripts in Oracle

Now that you have created a catalog, you need to register your target database[1] with the catalog you have created.
This populates the catalog with initial information regarding the configuration of your target database and includes a full synchronization of the catalog with the control file of the target database.

Another good reason for performing backup

If you lose your catalog, you can partially regenerate it from the information within the control file, but you should avoid this predicament by backing it up. You can use RMAN to back up the catalog by creating a recovery-catalog schema within one of your other instances, by using that as the catalog for your primary catalog instance. Providing that these two instances do not share any common resources, this role reversal is free from single points of failure.

Update your catalog with RESYNC CATALOG

It is important that your recovery catalog has an up-to-date view of your database. When you execute RMAN operations on the database, RMAN automatically synchronizes the catalog with the target. However, depending on the volatility of your database, you may need to resynchronize the catalog more frequently. Always include catalog resynchronization as part of any structural database change (the addition of files, tablespaces, and so on) and ensure that a resynchronization occurs at intervals. To perform this action, issue the RESYNC CATALOG command from within RMAN.
Now you are ready to produce your first backups. You can enter RMAN commands interactively, or you can hold them within RMAN-stored scripts or operating-system command files.

RESYNC CATALOG

The `RESYNC CATALOG` command is still used with the Oracle Recovery Catalog. It is used to resynchronize the metadata in the Recovery Catalog with the metadata in the target database control file. The `RESYNC CATALOG` command is necessary for the following reasons:
  • The Recovery Catalog may be unavailable when RMAN performs operations that automatically resynchronize the metadata.
  • The target database may be running in ARCHIVELOG mode, and the Recovery Catalog is not automatically updated when online log switches occur or redo logs are archived.
  • The physical structure of the target database may have changed, such as when tablespaces are added or removed. The Recovery Catalog is not automatically updated when physical schema changes are made.
  • RMAN is connected to the target database as a standby database. The Recovery Catalog must be updated with information about the physical schema changes that have been made on the primary database.

To use the `RESYNC CATALOG` command, you must first connect to RMAN as the Recovery Catalog owner and specify the target database. For example, the following command would resynchronize the Recovery Catalog with the control file of the target database `my_database`:
RMAN> RESYNC CATALOG TARGET my_database;

The `RESYNC CATALOG` command is a powerful tool that can be used to ensure that the Recovery Catalog is always up-to-date with the metadata in the target database control file. This is important for ensuring the success of future backups and restores.
For more information on the `RESYNC CATALOG` command, please refer to the Oracle Database Backup and Recovery User's Guide.

RMAN within Windows

Initiating RMAN within a Microsoft Windows environment involves unique commands:

C:\> RMAN 
RMAN> CONNECT TARGET RMAN/RMAN@PETS
RMAN> CONNECT RCVCAT RMAN/RMAN@BACKUP 
RMAN> # then enter your RMAN commands here
C:\>

The first command connects to the target database (the database that you want to back up). You connect to the recovery catalog through the second command
RMAN> CONNECT RCVCAT RMAN/RMAN@BACKUP
The RMAN commands listed above will work on a Windows machine for a database called "PETS". The `RMAN` command-line utility is available on all platforms that support the Oracle Database.
To run RMAN on a Windows machine, you would first need to open a command prompt window. Once the command prompt window is open, you would navigate to the directory where the RMAN executable file is located. To connect to the database "PETS", you would use the following RMAN command:
RMAN> CONNECT TARGET RMAN/RMAN@PETS

To connect to the Recovery Catalog database "BACKUP", you would use the following RMAN command:
RMAN> CONNECT RCVCAT RMAN/RMAN@BACKUP

Once you are connected to the database and the Recovery Catalog, you can then enter your RMAN commands. For example, the following RMAN command would back up the database "PETS" to disk:
RMAN> BACKUP TARGET RMAN/RMAN@PETS DISK;

The following RMAN command would restore the database "PETS" to the point in time of the most recent backup:
RMAN> RESTORE TARGET RMAN/RMAN@PETS TO TIME CURRENT;

For more information on the RMAN command-line utility, please refer to the Oracle Database Backup and Recovery User's Guide.

Create database backups

The following code backs up your entire database, including a copy of the current control file:
RMAN> RUN {
2> ALLOCATE CHANNEL C1 TYPE DISK;
3> BACKUP DATABASE FORMAT 'D:\BACKUPS\%U';
4> RELEASE CHANNEL C1;
5> }

The next lesson uses the FORMAT parameter.
[1] target database: In the context of Oracle Backup and Recovery, the target database is the database that is being backed up or restored. It is the database that you want to protect from data loss or corruption.