Lab-05-Creating Database Backups
Lab-05-Creating Database Backups
Overview
In these practices, you will create a script file that can be used to re-create the control file. You
will also create a whole database backup and a partial database backup.
Overview
In this practice, you back up your control file to a trace file and then create a file of SQL
commands that can be used to re-create the control file.
Tip
The loss of a single control file causes the database instance to fail because all control files
must be available at all times. However, recovery can be a simple matter of copying one of the
other control files. The loss of all control files is slightly more difficult to recover from, but is not
usually catastrophic as long as you created a copy of the control file by backing it up to a trace
file.
Tasks
1. Open a terminal window and start SQL*Plus and connect to the CDB root as the SYS user
with SYSDBA privileges.
$ sqlplus / as sysdba
…
SQL>
2. Verify that the control files are multiplexed.
SQL> SELECT name FROM v$controlfile;
NAME
----------------------------------------------------------------
/u01/app/oracle/oradata/ORCLCDB/control01.ctl
/u01/app/oracle/fast_recovery_area/ORCLCDB/control02.ctl
SQL>
3. Back up the control file to a trace file. Exit SQL*Plus.
SQL> ALTER DATABASE BACKUP controlfile TO trace;
Database altered.
SQL> EXIT
…
$
Question: Are the data files, temp files, and control files that structure the ORCLCDB
database included in the SQL script?
Answer: Yes, they are included. All data and temp files of the different containers (the CDB
root, CDB seed, PDB1, and so on) and the multiplexed redo log files are present.
Question: When would you have to regenerate the trace file from the current control files?
Answer: Because the control file changes after each data file or redo log file change
(adding, removing, resizing) or database attribute change (ARCHIVELOG), you would have
to redo the backup of your control file to a trace file.
9. Close all terminal windows.
Overview
In this practice, you use Recovery Manager (RMAN) to configure automatic backups of the
control file and server parameter file (SPFILE) when a backup of the database is made and
when there is a structural change to the database.
Assumptions
You are logged in to the compute node as the oracle user.
Timing Estimate
Tasks
1. Open a terminal window. Start Recovery Manager and connect to the CDB root (target
database) as the SYS user.
$ rman target /
…
connected to target database: ORCLCDB (DBID=2778750799)
RMAN>
2. Show all RMAN settings. Notice the CONFIGURE CONTROLFILE AUTOBACKUP ON;
setting.
RMAN> SHOW ALL;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name
ORCLCDB are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO
'%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO
BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; #
default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; #
default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
Overview
In this practice, you use Recovery Manager to back up your entire database, including the
archived redo log files, the SPFILE, and the control files. The backup should be the base for an
incremental backup strategy.
Timing Estimate
It should take approximately 30 minutes to complete this practice.
Tasks
1. Open a terminal window. Start Oracle Recovery Manager (RMAN) and connect to the CDB
RMAN>
2. View the structure of the CDB in terms of PDBs, tablespaces, and data files (permanent
and temporary). Your file numbers will differ from those shown below.
RMAN> REPORT schema;
Report of database schema for database with db_unique_name
ORCLCDB
RMAN>
3. Back up the whole database. Your results will be different from the results shown below; for
example, the piece handle names will be different.
RMAN> BACKUP DATABASE;
RMAN>
Question: How can hot backups (inconsistent backups) be used in complete database
recovery?
Answer: During a complete recovery, restored online backups are recovered until the
current SCN is matched, with the use of the archive log files and online redo log files.
RMAN>
./8857B36632797E5CE0536210ED0ADAC7/backupset/2019_06_20:
total 588196
-rw-r----- 1 oracle oinstall 602308608 Jun 20 15:47
o1_mf_nnndf_TAG20190620T154656_gjqbmzl3_.bkp
./8857B36632797E5CE0536210ED0ADAC7/backupset/2019_06_18:
total 1305840
-rw-r----- 1 oracle oinstall 66494464 Jun 18 19:39
o1_mf_nnndf_TAG20190618T193903_gjlhgq5r_.bkp
-rw-r----- 1 oracle oinstall 602128384 Jun 18 19:29
o1_mf_nnndf_TAG20190618T192926_gjlgx5j1_.bkp
-rw-r----- 1 oracle oinstall 66494464 Jun 18 18:04
o1_mf_nnndf_TAG20190618T180429_gjl9xfgb_.bkp
-rw-r----- 1 oracle oinstall 602054656 Jun 18 17:22
o1_mf_nnndf_TAG20190618T172148_gjl7g5kp_.bkp
./onlinelog:
total 0
$
Question: Where are the backups of control files and SPFILE located?
Answer: They are created in the autobackup subdirectory.
Question: How are backups deleted?
Answer: Space management in the FRA is governed by a backup retention policy. A
retention policy determines when files are obsolete, which means that they are no
RMAN>
b. Issue the SHOW RETENTION POLICY command. The policy is REDUNDANCY 1.
RMAN> SHOW RETENTION POLICY;
using target database control file instead of recovery catalog
RMAN>
Question: How does Oracle determine when files are obsolete?
Answer: There are two retention policy parameters that are mutually exclusive:
If a retention policy is enabled with RECOVERY WINDOW OF 5 DAYS, the window
stretches from the current time (SYSDATE) to the point of recoverability, which is the
earliest date to which you want to recover. The point of recoverability is SYSDATE -
integer days in the past.
If a retention policy is enabled with REDUNDANCY r, then RMAN skips backups only if
at least n backups of an identical file exist on the specified device, where n=r+1
(default is 1).
RMAN automatically deletes obsolete backup sets and copies in the FRA when space is
needed.
8. Manually delete obsolete files by issuing the DELETE OBSOLETE command. If there are
obsolete files, respond YES when prompted. Your results will differ from this example.
RMAN> delete obsolete;
RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=32 device type=DISK
Deleting the following obsolete backups and copies:
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ -----------------
Backup Set 2 2019-06-18:17:22:22
Backup Piece 2 2019-06-18:17:22:22
/u01/app/oracle/fast_recovery_area/ORCLCDB/8857B36632797E5CE0536
RMAN>
9. Back up the database and archive logs as image copies. At the same time, free space in
the FRA by deleting the archive log files once they are backed up.
a. Perform the backup.
RMAN> BACKUP AS COPY DATABASE PLUS ARCHIVELOG DELETE INPUT;
RMAN>
Question: What would you do if an error such as the following occurs?
RMAN-00571:
===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS
===============
RMAN-00571:
Overview
In this practice, you use Recovery Manager to back up ORCLPDB1, including the archived redo
log files. You also back up a specific tablespace in ORCLPDB2.
Time Estimate
It should take approximately 20 minutes to complete this practice.
Tasks
1. Open a terminal window. Start Recovery Manager (RMAN) and connect to the CDB root as
the SYS user.
RMAN>
2. Back up ORCLPDB1, including the archived redo log files.
RMAN> BACKUP PLUGGABLE DATABASE ORCLPDB1 PLUS ARCHIVELOG;
Starting backup at 2019-06-20:17:57:57
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=37 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=36 RECID=11
STAMP=1011456318
input archived log thread=1 sequence=37 RECID=13
STAMP=1011456386
input archived log thread=1 sequence=38 RECID=14
STAMP=1011463077
channel ORA_DISK_1: starting piece 1 at 2019-06-20:17:57:58
channel ORA_DISK_1: finished piece 1 at 2019-06-20:17:57:59
piece
handle=/u01/app/oracle/fast_recovery_area/ORCLCDB/backupset/2019
_06_20/o1_mf_annnn_TAG20190620T175758_gjql96rc_.bkp
tag=TAG20190620T175758 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2019-06-20:17:57:59
…
RMAN>
5. Try to configure the recovery setting for the PDB so that the SPFILE and control file are
Overview
In this practice, you will configure Block Change Tracking (BCT). Although BCT is optional, it
reduces the time required for an incremental backup from the time to scan all the blocks in the
database to a time proportional to the number of blocks that have changed since the last
backup.
The BCT file can contain only 8 bitmaps, so the backup cannot be optimized if there have been
more than 8 incremental backups since the parent level backup that the new incremental will be
based on. Consider the 8-bitmap limit when developing your incremental backup strategy. For
example, if you make a level 0 database backup followed by 7 differential incremental backups,
the block change tracking file now includes 8 bitmaps. If you then make a cumulative level 1
Time Estimate
It should take approximately 5 minutes to complete this practice.
Tasks
1. Configure block change tracking to place the BCT file in the default data file creation
destination.
a. Open a terminal window and start SQL*Plus and connect to your ORCLCDB database
with administrator privileges.
$ sqlplus / as sysdba
…
SQL>
b. Set the DB_CREATE_FILE_DEST initialization parameter to
/u01/app/oracle/oradata/ORCLCDB.
SQL> ALTER SYSTEM SET DB_CREATE_FILE_DEST =
'/u01/app/oracle/oradata/ORCLCDB';
System altered.
SQL>
c. Enable block change tracking by using the ALTER DATABASE statement.
SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;
SQL>
Note: In another practice, you will disable block change tracking again, because it is
not required for the practice environment.
2. Exit SQL*Plus.
SQL> exit
…
$
3. Close the terminal window.
Overview
In this practice, you create an image copy of the target database for use as a base for an
incremental backup strategy. You perform an incremental level 1 backup, and apply the
incremental to the level 0 backup.
Note: Applying the incremental backup to the level 0 image copies makes the level 0 backup
the same as if you had taken a level 0 instead of level 1.
Assumptions
You have completed Practice 5-5. If you skipped the required practice, complete the Catchup
Step in a terminal window.
Tasks
1. (Catchup Step) If you skipped Practice 5-5, run the prep05-06.sh script in a terminal
window and then proceed step 2.
$ /home/oracle/labs/admin/prep05-06.sh
...
SQL>
System altered.
SQL>
Database altered.
...
$
2. Open a terminal window. Perform the following steps to check if the ORCLPDB1 pluggable
database is open.
a. Log in to SQL*Plus as SYSDBA.
$ sqlplus / as sysdba
…
SQL>
b. Check the open mode of the PDBs.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB1 READ WRITE NO
RMAN>
As the backup is performed, notice where the backup files are created.
5. Open a new terminal window and start a workload that updates your database by executing
the DBMod_Backup_workload.sh script.
$ cd /home/oracle/labs/DBMod_Backup
$ ./DBMod_Backup_workload.sh
…
SQL>
Session altered.
SQL> Connected.
SQL> SQL> SQL> SQL> SQL> 2 3 4
2190 rows updated.
SQL>
Commit complete.
…
$
Note: The script updates over 2000 rows.
RMAN>
Note: The time of the incremental data file backup is faster than the original level 0 and
some data files do not need to be backed up at all.
7. Apply the incremental backups to the existing level 0 backup. Notice the recovery of the
data file copy and the restore operation.
RMAN> run {
ALLOCATE CHANNEL "ch1" DEVICE TYPE DISK FORMAT
"/home/oracle/backup/orclcdb/%U";
RECOVER COPY OF DATABASE WITH TAG 'BASE01';
}
…
Starting recover at 2019-06-20:21:12:44
no copy of datafile 5 found to recover
no copy of datafile 6 found to recover
no copy of datafile 8 found to recover
channel ch1: starting incremental datafile backup set restore
channel ch1: specifying datafile copies to recover
recovering datafile copy file number=00001
name=/home/oracle/backup/orclcdb/data_D-ORCLCDB_I-2778750799_TS-
SYSTEM_FNO-1_1ju4jnpc
RMAN>
Statement processed
RMAN>
9. Exit RMAN and remove your test data by executing the
DBMod_Backup_cleanupINVENTORY.sh script.
RMAN> exit
…
$ ./DBMod_Backup_cleanupINVENTORY.sh
$
10. Optionally, use your other terminal window to view the output in the /tmp/cleanup.log
file while the DBMod_Backup_cleanupINVENTORY.sh script is executing.
$ cat /tmp/cleanup.log
11. Use the RMAN DELETE OBSOLETE command to delete obsolete backups. Be sure to
respond YES when prompted.
$ rman target "'/ as sysbackup'"
…
connected to target database: ORCLCDB (DBID=2778750799
RMAN>
Note: Your output may be different depending on the repetition of practices.
12. Optionally, crosscheck all data file copies of the ORCLCDB database.
RMAN> crosscheck datafilecopy all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
RMAN>
13. Exit RMAN.
RMAN> exit
$
14. Close all terminal windows.
Overview
In this practice, you create backups of important database files that are not part of the default
backup set.
Time Estimate
It should take approximately 10 minutes to complete this practice.
Tasks
1. Back up the control file to a trace file. Then exit SQL*Plus and view the trace file.
Note: This command creates a SQL script to re-create a control file.
Database altered.
SQL>
d. Exit from SQL*Plus.
SQL> exit
…
$
e. View the trace file. What can you learn from its content?
Note: The trace file requires some editing before it can be used.
$ cat /home/oracle/backup/orclcdb/control.sql
…
-- the database with the NORESETLOGS option and should be used
only if
-- the current versions of all online logs are available. The
second