Schedule RMAN Backups Using Ansible
Schedule RMAN Backups Using Ansible
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
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'
content: |
RUN {
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CROSSCHECK BACKUP;
DELETE EXPIRED BACKUP;
}
dest: "{{ rman_backup_script }}"
mode: '0755'
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.
• Deletes obsolete backups (older than 7 days) and expired backups (backups not
found in the catalog).
• Crosschecks existing backups to verify their validity.
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.