Skip to content

Commit 7ce91b1

Browse files
authored
Merge pull request #90 from Rendanic/prrman
added role oradb-rman
2 parents 7f034df + 38cb076 commit 7ce91b1

16 files changed

+880
-0
lines changed

roles/oradb-rman/README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# oradb-rman
2+
3+
Manages RMAN Backups
4+
5+
This role is written by Thorsten Bruhns <thorsten.bruhns@opitz-consulting.com>
6+
There is no warranty for any error in the scripts. Please test the Backup/Recovery after setup with ansible-oracle!
7+
This role used rman_backup.sh from https://github.com/Rendanic/oracleToolbox/blob/master/rman/linux/rman_backup.sh
8+
9+
# Backup Strategies
10+
The role has templates for 3 different strategies. Please do not edit this templates, because patches for this role could create conflicts. You can create your own templates and use them within rman_jobs.
11+
12+
13+
* Online Backup to NFS
14+
15+
Use the following names in rman_jobs:
16+
17+
* archivelog
18+
* online_level0
19+
* online_level1
20+
21+
* Backup compressed to Recovery-Area and then to NFS
22+
23+
Use the following names in rman_jobs:
24+
25+
* archivelog_fra_disk
26+
* online_level0_fra_disk
27+
* online_level1_fra_disk
28+
29+
30+
* Offline Backup to NFS
31+
32+
Use the following names in rman_jobs:
33+
34+
* offline_level0
35+
* offline_level1
36+
37+
# Example Playbook
38+
39+
You need root permissions for executing the role!
40+
41+
```
42+
- hosts: servers
43+
roles:
44+
- roles/oradb-rman
45+
```
46+
47+
# Configuration
48+
## Description of rman_jobs
49+
Cronjobs are only created when day, weekday, hour and minute are defined.
50+
51+
* name
52+
53+
Defines the name of the used template from roles/oradb-rman/templates
54+
* disabled
55+
56+
Defines the state of cron entry. The cronentry is only disabled but not removed!
57+
* immediate
58+
59+
This allows an immediate execution of RMAN for the named script. Please be aware thatt the order of elements defines the executionorder of the scripts. The RMAN is NOT executed in ASYNC mode of Ansible. This parameter is most used for the 1st configuration of the parameter.
60+
61+
* service
62+
63+
This parameter is only used in RAC Environments!
64+
rman_backup.sh will only start a backup when the service is active on te current node. This allows a cronjob on every clusternode with a failoverservice to make sure, that a backup is running when the 'normal' node has failed. The services must be added with srvctl add service for the Database.
65+
66+
* day / weekday / hour / minute
67+
68+
Variables for the cronjob.
69+
70+
* rman_retention_policy
71+
72+
This could be used to overwrite the global default of `rman_retention_policy`at database level.
73+
74+
*
75+
## Example
76+
77+
The backup is configured in oracle_databases with rman_jobs:
78+
79+
```
80+
oracle_databases:
81+
- home: db_home1
82+
oracle_db_name: TEST
83+
84+
rman_jobs:
85+
- name: parameter
86+
- name: archivelog
87+
disabled: False
88+
day: "*"
89+
weekday: "*"
90+
hour: "*"
91+
minute: "10"
92+
- name: online_level0
93+
disabled: False
94+
day: "*"
95+
weekday: "0"
96+
hour: "02"
97+
minute: "30"
98+
- name: online_level1
99+
disabled: False
100+
day: "*"
101+
weekday: "1-6"
102+
hour: "02"
103+
minute: "30"
104+
```
105+
106+
## Variables
107+
The following variables are global. They are not part of oracle_databases!
108+
109+
* rman_cronfile
110+
111+
Defines the name of the cronfile in /etc/cron.d. Setting rman_cronfile: "" will use the cron of the oracle_user instead of /etc/cron.d
112+
113+
* rman_cron_logdir
114+
115+
Destination for cron execution which is redirected with `>> rman_cron_logdir 2>&1`
116+
Default is `/var/log/oracle`
117+
118+
* rman_retention_policy
119+
120+
Use rman_retention_policy_default when not defined. This variable could be used inside rman_jobs for individual retention policies for every Database.
121+
122+
* rman_channel_disk
123+
124+
This parameter must be defined. Otherwise the assert of the role will fail, because there is no usable default for this directory.
125+
126+
* rman_retention_policy_default
127+
128+
This values is used when rman_retention_policy is not defined inside rman_jobs:.
129+
`Default: "RECOVERY WINDOW OF 14 DAYS"`
130+
131+
* rman_channel_disk_default
132+
133+
`Default value: "DISK FORMAT '/u10/rmanbackup/%d/%d_%T_%U'"`
134+
135+
* rman_controlfile_autobackup_disk_default
136+
137+
This parameter must be defined. Otherwise the assert of the role will fail, because there is no usable default for this directory.
138+
139+
## Howtos
140+
### How to configure the RMAN scripts?
141+
The role copies the templatefiles from role/oradb-rman/templates to $ORACLE_BASE/admin/<DB_NAME>/rman. The name in the list defines the name of the template with .j2 as extension.
142+
143+
### How to configure the cron?
144+
145+
The dictionary elements name, disabled, day, weekday, hour, minute are mandatory. The creation of cron only starts when every element is defined.
146+
147+
### How to use custom RMAN scripts?
148+
Copy the script into the template directory `role/oradb-rman/templates` and add a `- name: <filename>` at `rman_jobs`. The filename must end with `.rman.j2` regardless of Junja2 in the file. You could use your own variables in the custom files and add entries to `rman_jobs`. They will be added as item.1.<dictionaryelement> to the template.
149+
Please do not edit existing files. They could be changed in future releases of oradb-rman.
150+

roles/oradb-rman/defaults/main.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
master_node: true
3+
oracle_user: oracle
4+
oracle_base: /u01/app/oracle
5+
6+
rman_cronfile: oracle_rman_ansible
7+
rman_cron_logdir: /var/log/oracle/rman/log
8+
9+
rman_script_dir: "{% if item is defined and item.0.rman_script_dir is defined %}{{item.0.rman_script_dir}}{% else %}{{oracle_base}}/rman/{% endif %}"
10+
rman_log_dir: "{% if item is defined and item.0.rman_log_dir is defined %}{{item.0.rman_log_dir}}{% else %}{{oracle_base}}/rman/log/{% endif %}"
11+
12+
rman_tns_admin: /u01/app/oracle/rman/network/admin
13+
rman_wallet_loc: "{{oracle_base}}/rman/network/wallet"
14+
rman_wallet_password: "oracleWallet1"
15+
16+
rmanautofs: false
17+
18+
rman_cron_mkjob: False
19+
20+
rman_retention_policy_default: "RECOVERY WINDOW OF 14 DAYS"
21+
rman_channel_disk_default: "'/u10/rmanbackup/%d/%d_%T_%U'"
22+
rman_controlfile_autobackup_disk_default: "'/u10/rmanbackup/%d/%d_%F'"
23+
rman_device_type_disk_default: 'PARALLELISM 1 BACKUP TYPE TO COMPRESSED BACKUPSET'
24+
25+
rman_retention_policy: "{% if item.0.rman_retention_policy is defined %}{{item.0.rman_retention_policy}}{% else %}{{rman_retention_policy_default}}{% endif %}"
26+
rman_channel_disk: "{% if item.0.rman_channel_disk is defined %}{{item.0.rman_channel_disk}}{% else %}{{rman_channel_disk_default}}{% endif %}"
27+
rman_controlfile_autobackup_disk: "{% if item.0.rman_controlfile_autobackup_disk is defined %}{{item.0.rman_controlfile_autobackup_disk}}{% else %}{{rman_controlfile_autobackup_disk_default}}{% endif %}"
28+
29+
rman_service_param: "{% if item.1.service is defined %}--service {{item.1.service}}{% else %}{% endif %}"
30+
31+
check_mk_mkjob: "{% if rman_cron_mkjob %}/usr/bin/mk-job rman_{{item.0.oracle_db_name}}_{{item.1.name}} {% endif %}"
32+
33+
rmanbackuplogdir: "{% if item.0.rman_log_dir is defined %}-l {{item.0.rman_log_dir}}{% else %}{% endif %}"
34+
rmanbackupscriptdir: "{% if item.0.rman_script_dir is defined %}-r {{item.0.rman_script_dir}}{% else %}{% endif %}"
35+
rman_catalog_param: "{% if item.0.rman_wallet is defined and item.0.rman_wallet %}-c /@{{item.0.rman_tnsalias}}{% else %}{% if item.0.rman_user is defined %}-c {{item.0.rman_user}}/{{item.0.rman_password}}@{{item.0.rman_tnsalias}}{% endif %}{% endif %}"

0 commit comments

Comments
 (0)