0% found this document useful (0 votes)
204 views4 pages

Schedule RMAN Backups Using Ansible

Uploaded by

vignesh murugan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
204 views4 pages

Schedule RMAN Backups Using Ansible

Uploaded by

vignesh murugan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Date: 22-Oct-24 Zaheer Abbas Mitaigiri,

Oracle Database Consultant.

Ansible - automation tool

Ansible is a powerful open-source automation tool used for various IT tasks like
configuration management, application deployment, and task execution. It allows you to
define tasks in simple YAML files (called "playbooks") and execute those tasks across
multiple servers or devices simultaneously.

To schedule RMAN backups using Ansible, you can create an Ansible playbook to configure
RMAN backup scripts and then schedule the backup using Linux's cron service on the target
Oracle database server. This setup involves deploying the RMAN backup script, creating a
shell script to invoke RMAN, and scheduling it via cron jobs.
Ansible Playbook: Schedule RMAN Backups:
Here’s an example of an Ansible playbook to set up scheduled RMAN backups:
---
- name: Schedule RMAN Backups on Oracle Database
hosts: oracle_db_servers

become: yes # Ensures privilege escalation to root or the oracle user


vars:
oracle_user: oracle # The Oracle user on the system
oracle_home: /u01/app/oracle/product/19.0.0/dbhome_1 # Adjust based on your Oracle
home path
oracle_sid: orcl # Oracle SID (Instance name)
rman_backup_dir: /backup/rman # Directory to store RMAN backups
rman_backup_script: /backup/rman/backup_full.rman # Path to the RMAN backup script
rman_shell_script: /backup/rman/rman_backup.sh # Path to the shell script to invoke
RMAN
backup_time: "30 2 * * *" # Time to schedule the backup (Every day at 2:30 AM)

tasks:
- name: Ensure the RMAN backup directory exists
file:
path: "{{ rman_backup_dir }}"
Date: 22-Oct-24 Zaheer Abbas Mitaigiri,
Oracle Database Consultant.

state: directory
owner: "{{ oracle_user }}"
group: "{{ oracle_user }}"

mode: '0755'

- name: Deploy RMAN full backup script


copy:

content: |
RUN {
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;

CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET;


CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1;
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;
BACKUP DATABASE PLUS ARCHIVELOG;
DELETE NOPROMPT OBSOLETE;

CROSSCHECK BACKUP;
DELETE EXPIRED BACKUP;
}
dest: "{{ rman_backup_script }}"

owner: "{{ oracle_user }}"


group: "{{ oracle_user }}"
mode: '0644'

- name: Create shell script to invoke RMAN backup


copy:
content: |
#!/bin/bash

export ORACLE_HOME={{ oracle_home }}


Date: 22-Oct-24 Zaheer Abbas Mitaigiri,
Oracle Database Consultant.

export ORACLE_SID={{ oracle_sid }}


export PATH=$ORACLE_HOME/bin:$PATH
rman target / cmdfile={{ rman_backup_script }} log={{ rman_backup_dir
}}/rman_backup_$(date +\%F_\%T).log
dest: "{{ rman_shell_script }}"
owner: "{{ oracle_user }}"
group: "{{ oracle_user }}"

mode: '0755'

- name: Schedule RMAN backup with cron


cron:

name: "RMAN Full Backup"


user: "{{ oracle_user }}"
minute: "{{ backup_time.split()[0] }}"
hour: "{{ backup_time.split()[1] }}"
day: "{{ backup_time.split()[2] }}"

month: "{{ backup_time.split()[3] }}"


weekday: "{{ backup_time.split()[4] }}"
job: "{{ rman_shell_script }}"

Ensure the RMAN backup directory exists: Creates the directory if it doesn't exist, with the
correct owner and permissions.
Deploy RMAN full backup script: The actual RMAN script that configures the retention policy
and runs the full backup along with archivelog backups.

Create shell script to invoke RMAN: Creates a shell script that sets the necessary
environment variables and invokes RMAN to run the backup using the .rman script.
Schedule RMAN backup with cron: Uses the cron module to schedule the backup job. The
backup_time variable controls the schedule, and the job is run as the oracle_user.
Date: 22-Oct-24 Zaheer Abbas Mitaigiri,
Oracle Database Consultant.

Example RMAN Backup Script:


The RMAN script configured in the playbook (backup_full.rman) performs the following
operations:

• Configures a retention policy of 7 days.


• Configures controlfile autobackup to ensure the controlfile is backed up with the
database.
• Backs up the database and archive logs.

• Deletes obsolete backups (older than 7 days) and expired backups (backups not
found in the catalog).
• Crosschecks existing backups to verify their validity.

Running the Playbook:


1. Save the playbook as schedule_rman_backup.yml.
2. Run the playbook with the following command:
ansible-playbook schedule_rman_backup.yml -i inventory_file
3. The inventory_file should list the Oracle database servers (oracle_db_servers) where
you want to run the playbook.
Example of Inventory File:
[oracle_db_servers]
dbserver1 ansible_host=192.168.1.10 ansible_user=admin

Notes:
• The RMAN logs will be stored in the backup directory (/backup/rman), with
filenames including the date and time of the backup.
• You can adjust the backup timing in the backup_time variable by modifying the cron
format (minute, hour, day, month, weekday).
This playbook schedules RMAN backups on your Oracle database servers using cron and
automates the entire process to avoid manual intervention. The backup is configured to run
daily, but you can modify the schedule as per your requirements.

You might also like