RMAN Backup Oracle Database to Local Disk
Introduction
For our Oracle Database environment on Google Cloud Platform we are going to setup RMAN to be able to backup and restore our instances when required for our testing.
We are going to configure RMAN
options so the database backup will be redirected to our RMAN disk and also minimizing the space needed to store the backups.
Prerequisites
We have a recently created Oracle 19c multitenant instance patodb
with one pluggable database taller
running in a Virtual Machine Instance on Google Cloud Platform.
For creation steps check Create Oracle Multitenant Database in Silent Mode.
RMAN Configuration
We need to setup the RMAN configuration parameters in order to store our backups into the Google Compute Engine Disk for RMAN attached to our Virtual Machine patoracle
.
Show Current Configuration
First we need to review the current configuration with the command show all
:
[oracle@patoracle respaldo]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Wed May 27 20:11:41 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: PATODB (DBID=1820073908)
RMAN> show all;
RMAN configuration parameters for database with db_unique_name PATODB 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
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE RMAN OUTPUT TO KEEP FOR 7 DAYS; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/opt/oracle/product/19c/dbhome_1/dbs/snapcf_patodb.f'; # default
We can see our backup is already directed to disk CONFIGURE DEFAULT DEVICE TYPE TO DISK
so no changes here.
Configure Datafile Backup Directory
Now we will setup the destination directory and name format for our backups.
Our directory in our attached disk is /rman/respaldo
and we are going to name our backupsets with:
%d
database name%T
year, month, day YYYYMMDD%u
backupset unique id
RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/rman/respaldo/%d_%T_%u.bkp';
new RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/rman/respaldo/%d_%T_%u.bkp';
new RMAN configuration parameters are successfully stored
For more information on naming check the documentation about RMAN substitution variables.
Configure Controlfile Backup Directory
We do the same with the controlfile autobackup.
The directory in our attached disk is /rman/controlfile
and we are going to name our backupsets with %F
as it is the only accepted substitution.
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/rman/controlfile/%F.bkp';
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/rman/controlfile/%F.bkp';
new RMAN configuration parameters are successfully stored
Configure Compression
In order to save disk space we are going to configure our backupsets to be compressed:
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET;
new RMAN configuration parameters are successfully stored
Configure Backup Optimization
Finally we are going to configure optimization to skip data files already backed up which content has not changed.
RMAN> CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters:
CONFIGURE BACKUP OPTIMIZATION ON;
new RMAN configuration parameters are successfully stored
Validate RMAN Setup
We are going to run a backup of the system
tablespace in order to validate both the datafile and controlfile backup:
[oracle@patoracle ~]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Wed May 27 21:09:40 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: PATODB (DBID=1820073908)
RMAN> backup datafile 1;
Starting backup at 27-MAY-20
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 compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oradata/cdbs/PATODB/system01.dbf
channel ORA_DISK_1: starting piece 1 at 27-MAY-20
channel ORA_DISK_1: finished piece 1 at 27-MAY-20
piece handle=/rman/respaldo/PATODB_20200527_1uv23mdo.bkp tag=TAG20200527T211016 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
Finished backup at 27-MAY-20
Starting Control File and SPFILE Autobackup at 27-MAY-20
piece handle=/rman/controlfile/c-1820073908-20200527-0d.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 27-MAY-20
RMAN> exit
Recovery Manager complete.
From the output we can see the backup pieces were redirected to our RMAN disk.
piece handle=/rman/respaldo/PATODB_20200527_1uv23mdo.bkp
piece handle=/rman/controlfile/c-1820073908-20200527-0d.bkp
Let’s check directly in the operating system:
[oracle@patoracle ~]$ ls /rman/controlfile
c-1820073908-20200527-0d.bkp
[oracle@patoracle ~]$ ls /rman/respaldo
PATODB_20200527_1uv23mdo.bkp
We have configured successfully RMAN to redirect the backups to our disk!
Conclusion
Configuring the RMAN parameters help us to transparently save our backup pieces to our Google Disk into the directories designated for each type and also reduce the space needed to store the database backups.