10 01 * * 0 oracle /u01/app/oracle/bin/rman_backup.sh -a online_level0 -s DB1 > /dev/null 2>&1
RMAN Backups with oradb_rman
This guide describes the configuration of RMAN backups with the role oradb_rman
and the backup script rman_backup.sh.
1. Overview
oradb_rman is executed by the playbook opitzconsulting.ansible_oracle.manage_db (last role).
It configures for every database in oracle_databases with rman_jobs:
| File | Description |
|---|---|
|
Backup script, executes an RMAN script |
|
RMAN script of a job, from the template |
|
Configuration of |
|
Crontab with one entry per job ( |
|
Connection to the RMAN catalog ( |
|
Wallet with the credential of the RMAN catalog ( |
The crontab contains no passwords and no directories:
All other settings are read by rman_backup.sh from rman_backup.cfg.
The output is written by rman_backup.sh to a logfile per execution, see Logfiles.
2. Inventory
2.1. rman_jobs
rman_jobs is a list in an entry of oracle_databases.
Every job executes the RMAN script <name>.rman.
| Attribute | Mandatory | Description |
|---|---|---|
|
yes |
Name of the job = name of the template |
|
no |
|
|
for cron |
Schedule of the crontab entry. A job without schedule gets no crontab entry (e.g. |
|
no |
|
|
no |
|
|
no |
Backup only on the node where the service is running (Grid Infrastructure / Oracle Restart), |
|
no |
|
|
Important
|
service and role are mutually exclusive in a job, an assert stops the role when both are defined.
Both select the member or node which executes the backup, a combination makes no sense.
For Data Guard use role.
|
2.2. Attributes of oracle_databases
| Attribute | Description |
|---|---|
|
List of jobs, see above |
|
|
|
|
|
|
|
Directory of the RMAN scripts of the database, default: |
|
Directory of the RMAN logfiles of the database, default: |
|
TNS alias of the RMAN catalog (entry in |
|
Owner of the RMAN catalog, password from |
|
|
|
Directory of |
rman_password in oracle_databases is deprecated. Use dbpasswords instead.
2.3. control_file_record_keep_time
Best practice: control_file_record_keep_time is defined in init_parameters of every database with rman_jobs.
The controlfile keeps the records of the backups for this number of days.
Without catalog, RMAN knows only the backups in the controlfile.
oradb_rman asserts:
-
control_file_record_keep_timeis defined ininit_parameters(state: present,sid: '*'), and -
the value is >=
<n>for the retention policyRECOVERY WINDOW OF <n> DAYS.
init_parameters:
- {name: control_file_record_keep_time, value: '30', scope: both, state: present}
The assert can be disabled with oradb_rman_assert_control_file_record_keep_time: false.
2.4. Global variables
The variables of the role are described in the README of oradb_rman.
| Variable | Default | Description |
|---|---|---|
|
|
RMAN scripts ( |
|
|
Logfiles of |
|
|
Days to keep the logfiles ( |
|
|
File in |
|
|
|
|
|
Prefix |
|
Important
|
The template parameter uses rman_device_type_disk
(e.g. 'PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET'),
the templates *_fra_disk use rman_fra_backupdir.
The role has no default for these variables, define them in the inventory when the templates are used.
|
2.5. RMAN templates
| Name | Description |
|---|---|
|
RMAN configuration: retention policy, controlfile autobackup, channel |
|
Like |
|
Online incremental level 0 backup, archive logs, |
|
Online incremental level 1 backup, archive logs, |
|
Offline level 0 backup: the database is restarted in |
|
Backup of the archive logs, deletes the archive logs backed up 1 time |
|
Variants for backups of the FRA to disk and for RAC. The snapshot controlfile is created in |
Own templates <name>.rman.j2 are found by Ansible in the templates directory of the playbook
(Ansible search path), the job uses the same name.
2.6. Example
oracle_databases:
- oracle_db_name: DB1
oracle_db_unique_name: DB1_SITE1
...
rman_retention_policy: 'RECOVERY WINDOW OF 14 DAYS'
rman_tnsalias: RMANCAT
rman_user: rman_db1
rman_jobs:
- {name: parameter, role: primary, immediate: true}
- {name: parameter_standby, role: standby, immediate: true}
- {name: online_level0, role: standby, weekday: "0", hour: "01", minute: "10", day: "*"}
- {name: online_level1, role: standby, weekday: "1-6", hour: "01", minute: "10", day: "*"}
- {name: archivelog, weekday: "*", hour: "*", minute: "30", day: "*"}
rman_device_type_disk: 'PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET'
dbpasswords:
RMANCAT:
rman_db1: <password>
3. rman_backup.sh
3.1. Usage
rman_backup.sh -a <action> [-s <ORACLE_SID|DB_NAME>] [--admin <Directory>]
[-r <Directory>] [-l <Directory>] [-c <CATALOGCONNECT>] [-t <TARGETCONNECT>]
[--service <Service>] [--role <PRIMARY|STANDBY>] [--nocatalog]
rman_backup.sh -h
-a is the only mandatory parameter.
All other settings are read from the command line, the environment or the configuration file.
export ORACLE_SID=DB1 $ORACLE_BASE/bin/rman_backup.sh -a archivelog $ORACLE_BASE/bin/rman_backup.sh -a online_level0 --nocatalog
3.2. Order of the settings
The first value wins:
-
parameter on the command line
-
environment variable
-
configuration file
<ORACLE_ADMIN>/rman/rman_backup.cfg -
default of
rman_backup.sh
| Parameter | Environment / rman_backup.cfg | Default | Description |
|---|---|---|---|
|
- |
- |
RMAN script |
|
|
- |
ORACLE_SID, DB_NAME in RAC environments (the instance is determined with |
|
|
see below |
Directory of |
|
|
|
RMAN scripts |
|
|
|
Directory of the logfiles, see Logfiles |
- |
|
|
Remove logfiles older than |
|
|
no catalog |
|
|
- |
- |
No catalog, even when |
|
|
|
|
|
|
- |
Backup only when the service runs on the current node (GI / Oracle Restart) |
|
|
- |
|
- |
|
- |
|
The old environment variables RMANSCRIPTDIR, RMANLOGDIR, CATALOGCONNECT, TARGETCONNECT
and RMANTNS_ADMIN are still supported.
|
Warning
|
Parameters are visible in the process list. Use rman_backup.cfg for the password of the catalog,
not -c.
|
3.3. ORACLE_ADMIN
rman_backup.sh determines ORACLE_ADMIN in the following order:
-
--adminor the environment variableORACLE_ADMIN -
$ORACLE_BASE/admin/<db_unique_name>:db_unique_nameis read from the running instance (v$parameter,sqlplus / as sysdba, works inNOMOUNT) -
$ORACLE_BASE/admin/<ORACLE_SID>, when the instance is not running
The db_unique_name makes the configuration unique on every member of a Data Guard configuration:
the ORACLE_SID is identical on all members, the db_unique_name is different.
3.4. rman_backup.cfg
The configuration file contains lines with KEY=VALUE.
It is read line by line and not sourced: shell code is not executed.
# Managed by Ansible RMAN_SCRIPTDIR=/u01/app/oracle/rman RMAN_LOGDIR=/u01/app/oracle/rman/log RMAN_LOG_RETENTION=30 RMAN_TNS_ADMIN=/u01/app/oracle/rman/network/admin RMAN_CATALOGCONNECT=rman_db1/<password>@RMANCAT
-
Allowed keys:
RMAN_SCRIPTDIR,RMAN_LOGDIR,RMAN_LOG_RETENTION,RMAN_TARGETCONNECT,RMAN_CATALOGCONNECT,RMAN_SERVICE,RMAN_ROLE,RMAN_TNS_ADMIN. Unknown keys and invalid lines are ignored with a warning. -
One pair of quotes around the value is removed.
-
Empty lines and lines starting with
#are ignored. -
The file could contain the password of the catalog: mode
0600.rman_backup.shwarns, when the file is readable by other users. -
oradb_rmancreates the file. Manual changes are overwritten by the next execution of the role.
RMAN_SERVICE and RMAN_ROLE are set per job in the crontab (--service, --role) and not in the file,
because the jobs of a database could use different values.
3.5. Catalog
rman_backup.sh checks the connection to the catalog before the backup.
The backup runs without catalog, when the catalog is not reachable.
3.6. Logfiles
rman_backup.sh writes all output of the script, sqlplus and RMAN to stdout and to a logfile per execution.
Manual executions are logged the same way as the cron jobs, the crontab redirects the output to /dev/null.
<RMAN_LOGDIR>/<db_unique_name>_<action>_<YYYYmmdd>_<HHMMSS>_<pid>.log <RMAN_LOGDIR>/<db_unique_name>_<action>.log -> logfile of the last execution
-
Every execution has its own logfile: parallel executions do not mix their output.
-
The symlink points to the logfile of the last execution of the action (for monitoring and
tail). -
Messages before the logfile is opened (e.g. reading
rman_backup.cfg) are written to the logfile afterwards. -
Logfiles of the database and action older than
RMAN_LOG_RETENTIONdays are removed. -
Errors before the logfile is opened (e.g. ORACLE_HOME of the ORACLE_SID not found) and the major actions are logged in syslog (tag
rman_backup.sh). -
<db_unique_name>is the name of the directoryORACLE_ADMIN, when the instance is not running.
3.7. Parallel executions
Only one execution of an action is allowed for a database (lock file <RMAN_LOGDIR>/.<db_unique_name>_<action>.lock, flock).
A 2nd execution of the same action stops immediately with exit code 30, e.g. an hourly archivelog
while the last execution is still running.
Different actions of a database run in parallel, e.g. archivelog during online_level0.
3.8. Exit codes
| Code | Description |
|---|---|
0 |
RMAN successful, or backup skipped ( |
1 |
Wrong parameters, service not existing |
10, 11, 12 |
ORACLE_HOME of the ORACLE_SID not found ( |
13 |
Database role could not be determined ( |
14 |
|
21, 22, 23 |
Log directory, RMAN script or logfile not existing |
30 |
The action is running already for the database |
99 |
RMAN failed |
4. Data Guard
All members of a Data Guard configuration get the same rman_jobs.
role decides, on which member a job executes the backup:
-
role: standby: backups of the database on the physical standby, the primary is not loaded -
role: primary: backups on the primary only -
without
role: the job runs on every member
The CONFIGURE commands are stored in the controlfile of each member and must be executed on all members:
-
parameterwithrole: primary -
parameter_standbywithrole: standby: withoutCONFIGURE RETENTION POLICY, the retention policy is not configurable on a standby database
online_level0 uses rman_retention_policy in delete obsolete.
Therefore it works on a standby database, whose controlfile (e.g. from RMAN DUPLICATE)
does not contain the retention policy, and on a new primary after a switchover.
After a switchover the backups follow the role automatically, the inventory is not changed.
oracle_databases:
- oracle_db_name: DB1
rman_jobs:
# executed during the playbook: parameter on the primary, parameter_standby on the standby
- {name: parameter, role: primary, immediate: true}
- {name: parameter_standby, role: standby, immediate: true}
# role primary: crontab entry on every member, rman_backup.sh --role primary skips it on the standby
- {name: online_level0, role: primary, weekday: "0", hour: "01", minute: "10", day: "*"}
- {name: archivelog, role: primary, weekday: "*", hour: "*", minute: "30", day: "*"}
All members get the same crontab entries.
rman_backup.sh checks database_role in v$database at every execution
and skips the backup with exit code 0, when the role does not match.
Valid values of role are primary and standby (checked by an assert).
|
Important
|
Use an RMAN catalog for Data Guard. Backups of a physical standby database can be used for the primary database (and vice versa), the catalog makes the backups known to all members. |
|
Note
|
archivelog deletes all archive logs that were backed up once.
The ARCHIVELOG DELETION POLICY (e.g. APPLIED ON ALL STANDBY) is configured by oradb_standby
with the mandatory attribute archivelog_deletion_policy in db_standby_config,
see Standby Databases - Archivelog deletion policy,
to prevent the deletion of archive logs which are not yet applied on the standby database.
|
5. Migration from older versions
-
The crontab entries contained the directories and the catalog connect (
-r,-l,-c) or the environment variablesRMANLOGDIR,RMANSCRIPTDIRandRMANTNS_ADMINin/etc/cron.d.oradb_rmanremoves the environment variables and recreates the crontab entries. The values are inrman_backup.cfgnow. -
Existing calls of
rman_backup.shwith all parameters still work. -
The logfiles are written to
RMAN_LOGDIRper execution. An existing logfile<RMAN_LOGDIR>/<name>_<action>.logof older versions is renamed to*.log.oldby the first execution. The cron output in/var/log/oracle/rman/log(oradb_rman_cron_logdir) is no longer written, the directory can be removed. -
Before this change, the attributes
service,rman_retention_policy,rman_channel_disk,rman_controlfile_autobackup_disk,rman_log_dir,rman_script_dirand the catalog connect of a database were ignored byoradb_rman(bug). They are used now: check the values in the inventory before the update.