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.

Prerequisites:

  • 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
os.system("")
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
try:
con = cx_Oracle.connect("SYSTEM",password,db_name)
cursor=con.cursor()
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)
else:
print(head)
for row in res:
#print(row)
row=str(row)
pieces=row.split()
status=pieces[-2]
if "FAIL" not in status:
print(style.GREEN + row.format(head) + style.RESET)
else:
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:

rman

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.

Cheers

Regards,
Adityanath

Advertisements

21 responses to “RMAN backup details using Python scripting”

  1. RMAN backup report reading old logfiles using Python – Adityanath's Oracle Blog Avatar

    […] You can find python program to report RMAN backup details by querying v$rman_backup_job_details can be found here. […]

  2. ปั้มไลค์ Avatar
    ปั้มไลค์

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

  3. Chetan Patil Avatar
    Chetan Patil

    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)

  4. Isidro Marstaller Avatar
    Isidro Marstaller

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

  5.  Avatar
    Anonymous

    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

  6.  Avatar

    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.

  7. Gale Kneser Avatar
    Gale Kneser

    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.

  8. Glinda Hallihan Avatar
    Glinda Hallihan

    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!

  9. Shaquana Stewardson Avatar
    Shaquana Stewardson

    I don’t normally comment but I gotta say thanks for the post on this amazing one : D.

  10.  Avatar
    Anonymous

    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

  11.  Avatar
    Anonymous

    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. . . . . .

  12.  Avatar
    Anonymous

    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.

  13. Freebies Avatar
    Freebies

    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

  14. Shalanda Ciubal Avatar
    Shalanda Ciubal

    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.

  15. Janelle Avatar
    Janelle

    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.

  16.  Avatar
    Anonymous

    Hi! I could have sworn I’ve been to this site before but after reading through some of the post I realized it’s new to me. Nonetheless, I’m definitely delighted I found it and I’ll be book-marking and checking back often!

  17.  Avatar
    Anonymous

    Thank you for every other magnificent article. Where else could anyone get that type of information in such a perfect manner of writing? I have a presentation next week, and I am on the look for such information.

  18. Mary Moore Avatar
    Mary Moore

    Great, thanks for sharing this post. Keep writing.

  19.  Avatar
    Anonymous

    Great, thanks for sharing this blog.Thanks Again. Great.

  20. 足球比赛时间 Avatar
    足球比赛时间

    Really enjoyed this article post.Really thank you! Much obliged.

  21. nomor shio ular Avatar
    nomor shio ular

    Major thanks for the article.Really thank you! Much obliged.

Leave a reply to RMAN backup report reading old logfiles using Python – Adityanath's Oracle Blog Cancel reply

Advertisements
Blog Stats

562,571 hits

Advertisements
Advertisements