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.



15 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!

  4. Enjoyed reading the content above, really explains everything in detail, the article is very interesting and effective.
    Thank you and good luck in the articles.
    King regards,
    Demir Raahauge

  5. Just want to say your article is as astonishing. The clarity in your post is just nice and i can assume you are an expert on this subject. Well with your permission let me to grab your feed to keep updated with forthcoming post. Thanks a million and please carry on the gratifying work.

  6. After checking out a number of the blog posts on your web site, I seriously like your way of writing a blog. I bookmarked it to my bookmark webpage list and will be checking back in the near future. Please check out my website as well and tell me what you think.

  7. Hello! This is my first visit to your blog! We are a collection of volunteers and starting a new project in a community in the same niche. Your blog provided us useful information to work on. You have done a outstanding job!

  8. I really appreciate this post. I have been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thank you again

  9. Hey very nice web site!! Man .. Beautiful .. Amazing .. I’ll bookmark your website and take the feeds also厈I am happy to find a lot of useful information here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .

  10. Thanks for sharing excellent informations. Your web-site is so cool. I am impressed by the details that you抳e on this site. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for more articles. You, my friend, ROCK! I found simply the info I already searched all over the place and simply could not come across. What a perfect website.

  11. I think this is among the most significant information for me. And i am glad reading your article. But should remark on few general things, The site style is ideal, the articles is really excellent : D. Good job, cheers

  12. Howdy! Do you use Twitter? I’d like to follow you if that would be okay. I’m undoubtedly enjoying your blog and look forward to new updates.

  13. Howdy! Someone in my Myspace group shared this website
    with us so I came to look it over. I’m definitely loving the information. I’m bookmarking and will be tweeting this to my followers!

    Great blog and terrific design.

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 )

Facebook photo

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

Connecting to %s