Database Refresh and Backups
Database Refresh and Backups
ORACLE DATABASE
Shashi Kallae
Oracle Database Refresh and Backups
TABLE OF CONTENTS
Introduction ....................................................................................................................................................3
About Backup .................................................................................................................................................3
What is the purpose of backup and recovery? ............................................................................................................................... 4
1
Oracle Database Refresh and Backups
Disk Space ............................................................................................................................................................. 17
RMAN backup at Source (Disk Based) .................................................................................................................... 18
Get the SCN from the control file needed for the restore. ...................................................................................... 26
Fetch Archive Redo Logs ........................................................................................................................................ 27
Restore the Database ............................................................................................................................................ 27
Recovery ............................................................................................................................................................... 29
Convert pfile to spfile ............................................................................................................................................ 30
Restart the database ............................................................................................................................................. 30
Open resetlogs ...................................................................................................................................................... 30
Change DBID using DBNEWID Utility...................................................................................................................... 31
What is DBNEWID Utility? ............................................................................................................................................................ 31
Troubleshooting SQL CODE Snippets (This part needs to be reviewed thoroughly) ........................................ 34
Drop all the standby redologs ....................................................................................................................... 36
Recreate Temp files ............................................................................................................................................... 37
Backup the control file to trace ............................................................................................................................. 37
Change the global name ........................................................................................................................................ 37
Create spfile .......................................................................................................................................................... 37
2
Oracle Database Refresh and Backups
Validate TDE Keys (Transport Data Encryption Keys) ............................................................................................. 38
Disclaimer: .................................................................................................................................................... 39
INTRODUCTION
When making changes to the application structure, you should test those changes on the
production data. But can you directly implement those changes on the production
database? The simple answer to this question is a “No.” Changes made to an application in a
lower environment aren’t reflected to the real-time users unless you deploy them in a
production environment. However, to validate these changes or updates, you would need
production data, and this will happen only if you refresh a non-production environment with the
production data.
Oracle recommends that you back up your non-production database before you refresh it
with the production database in case you want to roll it back for any reason.
Before we delve into the refresh, let's explore the Backup and Recovery of an Oracle database!
ABOUT BACKUP
3
Oracle Database Refresh and Backups
WHAT IS THE PURPOSE OF BACKUP AND RECOVERY?
In general, the purpose of database backup and recovery is to protect the database from data loss
and reconstruct the database from scratch in case of any disasters. There are several ways to
A Backup is a copy of a database or part of a database that can be used to reconstruct data
during disasters or database refresh tasks. Backups can be physical backups or logical backups.
PHYSICAL BACKUPS
4
Oracle Database Refresh and Backups
Data Files, control files, and archived redo log files are physical files. These files are used to
store and recover a database. Physical backups should be stored in different locations apart from
the source location, such as external disks or tapes. Backup tools from several vendors support
this process, but Oracle recommends using their native RMAN tool to back up and recover the
data.
LOGICAL BACKUPS
Logical backups comprise metadata such as tables, stored procedures, and others. Oracle
recommends using their native utility, the Oracle data pump to export logical data from the
source and import it into the target. Data pup command line clients such as expdp and impdp
use the DBMS_DATAPUMP and DBMS_METADATA PL/SQL packages.
RMAN BACKUP
5
Oracle Database Refresh and Backups
CONSISTENT BACKUP
Oracle database is said to be consistent when you shut down the database with the
SHUTDOWN NORMAL, SHUTDOWN IMMEDIATE, or SHUTDOWN TRANSACTIONAL
commands, which means Oracle offers three shutdown methods (NORMAL, IMMEDIATE,
and TRANSACTIONAL) to ensure data consistency. These three methods wait for ongoing
transactions to complete, or they roll back. This eliminates incomplete changes that may lead to
an inconsistent state. Also, this guarantees that all redo logs have been applied to the data files.
Redo logs record every database change. Applying them ensures all changes are reflected
before shutdown.
6
Oracle Database Refresh and Backups
INCONSISTENT BACKUP
A backup made when the database is in open mode is called Inconsistent. This is because while
the database is open, data is constantly being changed and updated. Backing up while this
happens means there's a higher chance of capturing the data in an incomplete state.
7
Oracle Database Refresh and Backups
INCREMENTAL BACKUPS
1. Incremental backup in the Oracle database captures only blocks of data that have changed
2. This makes the Incremental backups smaller than the full backups, which are easy to store
and recover.
3. Redo logs track the changes not yet written to the primary data files. Incremental backups
already capture these changes, minimizing the need to apply redo logs during data file media
recovery.
8
Oracle Database Refresh and Backups
1. This process repairs corrupted data blocks within a data file without taking the entire data file
2. This process is ideal for situations where only a few blocks are affected, saving time and
minimizing downtime.
BINARY COMPRESSION
1. This feature reduces the size of the backups by compressing the data before storing it.
2. This improves backup efficiency, as smaller backups require less storage space and less time
to transfer.
ENCRYPTED BACKUPS
1. Encryption protects sensitive data from unauthorized access even if the backups are
compromised.
2. This feature allows you to Securely Store the Backup sets by encrypting them.
3. Oracle’s Recovery Manager (RMAN) uses data encryption capabilities for this process.
9
Oracle Database Refresh and Backups
AUTOMATED DATABASE DUPLICATION
1. This process or feature allows you to create an exact replica of your database quickly.
2. It supports various storage configurations, directly copying data between Automatic Storage
3. This feature helps create Non-Production environments (Development, Test, QA) and
1. This Capability allows you to migrate data between databases running on different platforms.
2. This can be beneficial when you move your database from one Operating System to another
KEY TAKEAWAYS
Incremental backups are a space and time-efficient way to capture data changes in your
database. They are faster to create and, at the same time, faster to restore than the full backups.
Block media recovery efficiently repairs corrupted data blocks, Binary compression saves
storage space efficiently, Encrypted backups protect sensitive data, Automated database
10
Oracle Database Refresh and Backups
duplication simplifies database replication, and Cross-Platform data conversion helps and
Overall, the above-mentioned features offer tools to manage and secure the Oracle database
effectively.
Note
Approach Oracle Support when you are in question with any of the above tools. This way,
11
Oracle Database Refresh and Backups
The following tasks are associated with a backup and recovery strategy,
12
Oracle Database Refresh and Backups
1. Protect the database against data loss.
3. Schedule a backup.
6. When needed, reconstruct the database and recover the data from data loss.
7. Create a copy and store the database for long-term storage for the Data Archival process.
8. Move the database or part of the database from one environment to another, such as from
13
Oracle Database Refresh and Backups
Since we explored the importance of backups and several Data Protection methods, let’s look
PRE-REFRESH TASKS
SOURCE DATABASE
sourcedbProd1@sourcedbservername:/mount_name/directory_name/global_storage_location/sour
cedbProd1<database_name>
TARGET DATABASE
targetdbProd1@targetdbservername:/mount_name/directory_name/global_storage_location/targ
etdbProd1<database_name>
• Ensure to note the Non-Prod and Prod TDE Keys before you begin the process.
Transparent Data Encryption (TDE): TDE is a security feature in Oracle Database that
encrypts the data at rest, which means the data stored on the disk is encrypted, making it
14
Oracle Database Refresh and Backups
TDE protects against unauthorized access to the database and data files even if someone gains
access to the physical storage data files. They would require the TDE master encryption key to
15
Oracle Database Refresh and Backups
HOW DOES TDE WORK?
1) Groups of Tables are called Tablespaces. TDE encrypts entire Tablespaces or specific
access and use the data without any changes to their code.
3) The encryption and decryption happen in the background without impacting the
application’s performance, accessing the data using SQL (neither inbound SQL
5) Data encrypted with TDE is decrypted when the data is read from database files. If this
data goes over the network, it will be in clear-text. However, the data can be encrypted in
transit using TLS or Oracle’s Native encryption method over the network. This ensures
that the data traveling over the network from SQL*plus to the database and vice versa is
encrypted.
6) Use the Oracle Database Security Assessment Tool to determine what sensitive data is
16
Oracle Database Refresh and Backups
WHAT ELSE DOES TDE ENCRYPT?
4) Entire database backups (RMAN). Note: An Oracle Advanced security license is required to
encrypt RMAN backups to disk, regardless if the TDE master encryption key or a passphrase is
1) Oracle recommends using TDE Tablespace encryption because TDE Tablespace encryption
DISK SPACE
• Ensure the disk space at the source and target database servers or mounts.
• Ensure enough disk space for the RMAN export on the production database server
mount.
• Ensure enough space for the RMAN Import at the Non-Prod database server or mount.
17
Oracle Database Refresh and Backups
RMAN BACKUP AT SOURCE (DISK BASED)
The below steps to take a full RMAN backup to DISK in the Primary production database. Do
not run the full backup in the standby database. Double-check with your application teams if
they are concerned with the data from the primary database.
• Verify that the RMAN backup directory used in the backup script exists.
• Ensure the RMAN backup directory has enough space to hold the full database backup.
• The number of channels should be decided based on the number of available CPUs in the
host.
• The below command file for RMAN backup can be used; ensure to set the directory path
run
18
Oracle Database Refresh and Backups
allocate channel ch9 type disk;
‘/mount_name/directory_name/local_storage_location/sourcedbProd1<database_name>/RMAN_BAC
KUP_DIRECTORY/sourcedb_%d_%T_%t_%s_%p’;
'/mount_name/directory_name/local_storage_location/sourcedbProd1<database_name>/RMAN_BAC
KUP_DIRECTORY/archivelog_%d_%T_%t_%s_%p’;
'/mount_name/directory_name/local_storage_location/sourcedbProd1<database_name>/RMAN_BAC
KUP_DIRECTORY/controlfile_%d_%T_%t_%s_%p.ctl’;
'/mount_name/directory_name/local_storage_location/sourcedbProd1<database_name>/RMAN_BAC
KUP_DIRECTORY/spfile_%d_%T_%t_%s_%p’;
• Include a log file for the RMAN backup execution and verify the backup when completed
19
Oracle Database Refresh and Backups
PRE-REFRESH TASKS ON THE TARGET HOST
$ mkdir -p /tmp/dbrefresh_Feb052024_1017pmcst_monday
SQL>create
pfile=/tmp/dbrefresh_Feb052024_1017pmcst_monday/init_targetdbProd1.ora’
from spfile;
$ vi /tmp/dbrefresh_Feb052024_1017pmcst_monday/init_targetdbProd1.ora
db_file_name_convert='/mount_name/directory_name/oradata02/database_name01’,'/mount_name
/directory_name/oradata02/database_name02’,'/mount_name/directory_name/oradata01/databas
e_name01’,'/mount_name/directory_name/oradata01/database_name02'
20
Oracle Database Refresh and Backups
log_file_name_convert='/mount_name/directory_name/oradata02/database_name01’,'/mount_nam
e/directory_name/oradata02/database_name02/onlinelog','/mount_name/directory_name/oradat
a01/database_name01’,'/mount_name/directory_name/oradata01/database_name02/onlinelog'
4. Back up the existing control file to trace on the target database before dropping the target DB.
5. Take a backup of all the User account passwords for all users or schemas in the database.
dba_users;
21
Oracle Database Refresh and Backups
DROP EXISTING TARGET DATABASE.
SQL> startup
pfile='/mount_name/directory_name/orabin/admin/dbrefresh_Feb052024_1017pmcst_monday/init
drop database;
Ensure all the files are removed from the fra location; there shouldn’t be any files.
Path: /mount_name/directory_name/fra01
2. Mount database.
4. Get the SCN from the control file needed for the restore.
5. Generate restore preview. Ensure all archive redo logs are fetched from the production
environment.
22
Oracle Database Refresh and Backups
RESTORE THE CONTROL FILE FROM THE BACKUP.
rman target /
run {
'/mount_name/directory_name/global_storage_location/sourcedbProd1/rman_full_backup/sourc
edbProd1_primary_contril_xxxxxx_xxxxxx_x_x_xxxxxxxx.ctl’;
MOUNT DATABASE.
SQL> alter database mount;
Example
23
Oracle Database Refresh and Backups
102 Full 163.75M DISK 00:00:03 2024-01-02 09:00:00
BP Key: 102 Status: AVAILABLE Compressed: NO Tag:
TAG20240102T090000
Piece Name: /path/to/controlfile_backup_20240102.bkp
Controlfile Included: Ckp SCN: 2345678 Ckp time: 2024-01-02 08:59:59
• Two backup sets of the control file are listed (BP Key 101 and BP Key 102).
• Each backup set includes details such as the backup type (Full), size, device type, elapsed
• The "Piece Name" indicates the file path of the backup piece.
• The "Controlfile Included" section provides information about the control file copy
included in the backup set, including the checkpoint SCN (Ckp SCN) and checkpoint
• The SCNs are listed under "Controlfile Included" as "Ckp SCN". In this example, the
SCNs are "1234567" and "2345678" for the respective backup sets. These SCNs
represent the System Change Number when the backup was taken, which helps identify
24
Oracle Database Refresh and Backups
HOW DO YOU GET SCN?
Look into the above section for more details on how to get SCN. The below section is just an
extension of the above.
RMAN> list backup of controlfile;
This command in RMAN does not directly provide the SCN details of the control file backups.
Instead, you would need to query additional data dictionary views to obtain the SCN
information.
This query retrieves the backup set ID, backup start time, and SCN details of the control file
backups. Adjust the WHERE clause to filter for the control file backups based on your
database configuration. Additionally, note that the SCN information is obtained from
the V$BACKUP_DATAFILE view, which tracks SCN details of backup data files, including
Executing this SQL query will provide you with the SCN details of the control file backups,
allowing you to track the SCN associated with each backup set.
25
Oracle Database Refresh and Backups
GET THE SCN FROM THE CONTROL FILE NEEDED FOR THE RESTORE.
Get the SCN from above and use it in the example below script.
Example
RUN {
ALLOCATE CHANNEL ch1 DEVICE TYPE DISK FORMAT '/path/to/backup/%U';
ALLOCATE CHANNEL ch2 DEVICE TYPE DISK FORMAT '/path/to/backup/%U';
ALLOCATE CHANNEL ch3 DEVICE TYPE DISK FORMAT '/path/to/backup/%U';
SET UNTIL SCN 1234567; -- Specify the SCN until which recovery should be
performed
26
Oracle Database Refresh and Backups
release channel d12;
release channel d13;
release channel d14;
release channel d15;
}
Sample output
recovery will be done up to SCN 2345678
Media recovery start SCN is 1234567
Recovery must be done beyond SCN 2345778 to clear datafile fuzziness
Finished restore at MM/DD/YYYY
NOTE:
Take note of the above SCN from "Recovery must be done beyond SCN 2345778 to
clear datafile fuzziness”.
Note: Only use the below sqls to fetch the archives as needed.
In the above,
“rman_catalog_user" is the username for the RMAN catalog.
password123 is the password associated with the rman_catalog_user account.
“tns_entry" is the TNS entry configured in the tnsnames.ora file, which
provides the connection details for the catalog database.
RMAN> run{
allocate channel dev1 type disk;
set archivelog destination to ‘/tmp’;
restore archivelog sequence xxxxx;
}
27
Oracle Database Refresh and Backups
Create a file with the help of a restore file. For this, either touch a file to restore or use “vi”
Touch Command:
$ pwd
$ cd /home/oracle
$ touch dbrestorefile.rman
$ ls -lthr
$ vi dbrestorefile.rman
run
{
allocate channel ch1 type disk;
allocate channel ch2 type disk;
allocate channel ch3 type disk;
allocate channel ch4 type disk;
allocate channel ch5 type disk;
allocate channel ch6 type disk;
allocate channel ch7 type disk;
allocate channel ch8 type disk;
allocate channel ch9 type disk;
allocate channel ch10 type disk;
allocate channel ch11 type disk;
allocate channel ch12 type disk;
allocate channel ch13 type disk;
allocate channel ch14 type disk;
allocate channel ch15 type disk;
set until scn 1234567;
restore database preview device type disk;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
release channel d5;
release channel d6;
release channel d7;
release channel d8;
release channel d9;
release channel d10;
release channel d11;
28
Oracle Database Refresh and Backups
release channel d12;
release channel d13;
release channel d14;
release channel d15;
}
RECOVERY
From the above Sample Output, get the recovery SCN number to recover the database.
run
29
Oracle Database Refresh and Backups
restore database;
OPEN RESETLOGS
SQL> alter database open resetlogs;
30
Oracle Database Refresh and Backups
CHANGE DBID USING DBNEWID UTILITY
The DBNEWID utility lets you change only the DBID, DBNAME, or a database's DBID and
DBNAME.
1. Preparation
• Ensure you have the necessary privileges (SYSDBA) to execute the utility.
• Back up your database as a precaution.
2. Execution
3. Verification
4. Additional steps
31
Oracle Database Refresh and Backups
• Update scripts or configurations relying on the old names.
• Restart the database if required.
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
Step 2: Invoke the DBNEWID utility (nid) specifying the target database name (DBNAME)
from the command line using a user with SYSDBA privilege.
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights
reserved.
/mount_name/directory_name/oradata01/targetdbProd1/control01.ctl
/mount_name/directory_name/oradata02/targetdbProd1/control01.ctl
=> Y
32
Oracle Database Refresh and Backups
Changing database name from sourcedbProd1 to targetdbProd1
Control File
/mount_name/directory_name/oradata01/targetdbProd1/control01.ctl - modified
Control File
/mount_name/directory_name/oradata02/targetdbProd1/control01.ctl - modified
…………………………………………………………………………………………………………………………………………………………………………………
Datafile /mount_name/directory_name/oradata01/targetdbProd1/system01_.db -
…………………………………………………………………………………………………………………………………………………………………………………
Control File
/mount_name/directory_name/oradata01/targetdbProd1/control01.ctl - dbid
Modify parameter file and generate a new password file before restarting.
All previous backups and archived redo logs for this database are unusable.
Area.
33
Oracle Database Refresh and Backups
The "sqlplus /nolog" command is a way to start SQLPlus, which is an interactive command-line
tool for Oracle Database management and development, without immediately connecting to a
specific database. When you run "sqlplus /nolog", it starts SQLPlus without attempting to log in
$ sqlplus /nolog
CONNECT username/password@tns_entry;
If the above doesn’t work, then login to OEM and execute the EUS script from OEM.
1. Login to OEM.
In the context of Oracle Database, "snippets" typically refer to small pieces of SQL code or
PL/SQL code that can be stored and reused for various purposes.
34
Oracle Database Refresh and Backups
run
‘/mount_name/directory_name/local_storage_location/sourcedbProd1<database_name>/RMAN_BAC
KUP_DIRECTORY/sourcedbProd1/spdb_%d_%T_%t_%s_%p’;
format
'/mount_name/directory_name/local_storage_location/sourcedbProd1<database_name>/RMAN_BAC
KUP_DIRECTORY/sourcedbProd1/arlog_%d_%T_%t_%s_%p’;
35
Oracle Database Refresh and Backups
'/mount_name/directory_name/local_storage_location/sourcedbProd1<database_name>/RMAN_BAC
KUP_DIRECTORY/controlfile_%d_%T_%t_%s_%p.ctl’;
Database altered.
Database altered.
36
Oracle Database Refresh and Backups
Database altered.
GLOBAL_NAME
————————————————————————————————
sourcedbProd1.fqdn
Database altered.
GLOBAL_NAME
————————————————————————————————
targetdbProd1.fqdn
CREATE SPFILE
Create spfile from the pfile that was used in the restore.
37
Oracle Database Refresh and Backups
SQL> create spfile from
pfile='/mount_name/directory_name/oradata01/orabin/admin/dbrefreshxxxxxx/inittargetdbPro
d1.ora'
File created.
This command is used to open the keystore in the Oracle database, allowing you to manage
TDE keys.
1. ADMINISTER KEY MANAGEMENT: This clause indicates that you administer the
2. SET KEYSTORE: This subclause specifies that you are setting the keystore.
3. open: This keyword is used to open the keystore. This command is typically used to open
access the keystore. Replace <keystore_password> with the actual password for the
keystore.
After executing this command, you will be able to perform further operations related to
38
Oracle Database Refresh and Backups
DISCLAIMER:
The SQL queries and procedures outlined above are intended solely for educational
purposes. I cannot be held liable for any adverse consequences resulting from their use. It is
essential to conduct thorough research and adapt the SQL queries to align with your
organization's specific requirements and circumstances. Additionally, I recommend
contacting Oracle Support for further guidance on Database Refresh procedures tailored to
your organization's needs and requirements.
39