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