RMAN backup details using Python scripting

Dear Readers,

In my previous posts, I discussed about tablespace/FRA monitoring using python. Here comes my new python code to report RMAN backup job details from last 7 days in Oracle DB.

Note: This code is ready to use. But you can definitely refer it & modify wherever as per your need.


  • python binaries with version 3
  • cx_Oracle module

What this program does:

This program needs following inputs from user side:

  • SYSTEM password
  • TNS entry to connect to DB.

At the end of execution, it provides following details about RMAN backups done in last 7 days for a Oracle DB:

  • Backup Start Time
  • Backup End Time
  • Backup Device Type (Disk, Tape etc)
  • Backup Type (Full, Archivelog, Incre etc)
  • Backup Status
  • Time taken to complete backup in seconds

Note: Any failed backup will be highlighted in RED color, while others will be in GREEN color. Also it will standard message in case RMAN backups are not done in last 7 days.

Actual code:

# Script Name: rman.py
# Description: RMAN backup details in an Oracle DB
# Usage: python rman.py
# Author: Adityanath Dewoolkar
# Version: 1

# importing required modules
import cx_Oracle
import getpass
import os

# For conditional coloring
class style():
RED = '\033[31m'
GREEN = '\033[32m'
RESET = '\033[0m'

# Prompt the user for a password without echoing
password = getpass.getpass(prompt = 'Enter SYSTEM password: ', stream=None)
# Enter TNS string to connect
db_name = input("Enter DB name: ")

# Code for getting RMAN backup details in an Oracle DB
con = cx_Oracle.connect("SYSTEM",password,db_name)
head = ("StartTime","EndTime","BkpDevType","BkpType","Status","TimeTakenSeconds")
cur = con.cursor()
cur.execute("select to_char(start_time,'DD-Mon-YYYY HH24:MI:SS'),to_char(end_time,'DD-Mon-YYYY HH24:MI:SS'),output_device_type,INPUT_TYPE,status,elapsed_seconds from v$rman_backup_job_details where start_time>sysdate-7 order by 1")
res = cur.fetchall()
if not res:
print(style.RED + "No RMAN backup in last 7 days"+ style.RESET)
for row in res:
if "FAIL" not in status:
print(style.GREEN + row.format(head) + style.RESET)
print(style.RED + row.format(head) + style.RESET)

except cx_Oracle.DatabaseError as err:
print("Script execution failed: ", err)

Here comes the result:

Also we get below message in case RMAN backups are not done in last 7 days.:

You can download sample files from below location:


Hope u will find this post very useful.

You can find python program to create RMAN backup report by reading old logfiles can be found here.



4 replies

  1. Like!! I blog quite often and I genuinely thank you for your information. The article has truly peaked my interest.

  2. Thanks Aditya 🙂 I really like that idea to convert tuple to string which can be manipulated nicely. Just a suggestion for query. Please use order by trunc(sysdate) otherwise sort result will not be proper.

    select to_char(start_time,’DD-Mon-YYYY HH24:MI:SS’),to_char(end_time,’DD-Mon-YYYY HH24:MI:SS’),output_device_type,INPUT_TYPE,status,elapsed_seconds from v$rman_backup_job_details where start_time>sysdate-7 order by trunc(start_time)

  3. Greetings! Very helpful advice within this post! It is the little changes that make the most important changes. Thanks for sharing!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s