10-25-2018 09:23 AM
Hello,
I'm looking to use the command line to create a report of policies that have run within the last couple of days. It seems like bppllist lists all of the policies and their associated information, but I can't figure out how to manipulate it to filter only the times I want.
Thanks in advance!
Solved! Go to Solution.
10-26-2018 05:34 AM
Try 'bperror -backstat -d <start-date> -e <end-date> -l '
Field 11 = Policy name
See: https://www.veritas.com/support/en_US/doc/123533878-127136857-0/v123537594-127136857
10-25-2018 11:42 AM - edited 10-25-2018 11:43 AM
A co-worker wrote this python script using "bperror -U -backstat -hoursago ", it checks backups and find ones that failed. It does a check to see if it retried and completed, I check this every day for failed backups
That is NOT a smiley embedded!
#!/usr/bin/python
#############################################################
#
# Script written by Adam Wyandt
# to run the netbackup bperror command and parse it
# and email to emailgrp value
# 20171025
#
#############################################################
import __future__
import subprocess
import shlex
import multiprocessing
import datetime
import smtplib
import sys
import email
import os
import shutil
import glob
import time
#####
# Functions
#####
def addexit(row):
returncode.append(outsplit[row])
def errorstatus(error,svrs):
global msg
errorcmd = subprocess.Popen(shlex.split('/usr/openv/netbackup/bin/admincmd/bperror -S {0}'.format(error)),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
cmdraw, cmdrawerrors = errorcmd.communicate()
errorcmdraw = cmdraw.splitlines()
msg += '\tError:{0} - {1:>16}\n\n'.format(error,errorcmdraw[0])
cnt = 1
msg += '\tServers:'
for svr in svrs:
if svr in successful_second_try:
svr += '\t:RETRY Successful!!'
if cnt == 1:
msg += ' {0} - {1} \n'.format(cnt,svr)
else:
msg += '\t\t {0} - {1} \n'.format(cnt,svr)
cnt += 1
msg += '\n{0}\n\n'.format('*'*60)
def logreport(msg):
# Report file name
file = '/usr/openv/tmp/bperrorreport'
# Backup old reports
todaystring = datetime.date.today()
count = 0
while os.path.exists(('{0}.{1}.{2}').format(file,todaystring,count)):
count += 1
try:
shutil.copy(file,('{0}.{1}.{2}').format(file,todaystring,count))
except:
pass
with open(file,'w') as msgfile:
msgfile.write(msg)
# Clean old log files
logkeepdays = 7
daysinsec = logkeepdays * 24 * 60**2
for file in glob.glob('{0}*'.format(file)):
deltatime = time.time() - os.stat(file).st_mtime
if int(deltatime) >= daysinsec:
try:
os.remove(file)
except:
pass
#####
# Main
#####
#### Check for input
if len(sys.argv) == 2:
mailall = 1
try:
hour = int(sys.argv[1])
except:
print('Usage {0} 73 <- Time in hours.'.format(sys.argv[0]))
quit()
else:
mailall = 0
#### Monday "0" run for weekend
if datetime.datetime.now().weekday() == 0:
hour = 72
else:
hour = 24
enddate = datetime.datetime.today()
startdate = enddate - datetime.timedelta(hours=hour)
#####
# Build report header
#####
msg = '{0}\n'.format('*'*60)
msg += '*\n'
msg += '*\t{0}\n'.format('Netbackup error report.') + '*\n'
msg += '*\t{0} {1}\n'.format('Start:',startdate.strftime("%A, %d. %B %Y %I:%M %p")) + '*\n'
msg += '*\t{0} {1}\n'.format('End: ',enddate.strftime("%A, %d. %B %Y %I:%M %p")) + '*\n'
msg += '{0}\n\n'.format('*'*60)
#####
# Pull the bperror report
#####
cmd = subprocess.Popen(shlex.split('/usr/openv/netbackup/bin/admincmd/bperror -U -backstat -hoursago {0} -by_statcode'.format(hour)),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
cmdrawstdout = cmd.communicate()[0].splitlines()
returncode = []
### Sort the exit codes
for output in cmdrawstdout:
outsplit = output.split(' ')
if outsplit[0] != '':
addexit(0)
elif outsplit[1] != '':
addexit(1)
elif outsplit[2] != '':
addexit(2)
svrsort = {}
### Sort the exit codes
for excode in returncode:
svrsort[excode] = []
start = 0
for output in cmdrawstdout:
outsplit = output.split(' ')
if start == 1:
if outsplit[0] in returncode:
start = 2
elif outsplit[1] in returncode:
start = 2
elif outsplit[2] in returncode:
start = 2
else:
while '' in outsplit:
outsplit.remove('')
svrsort[excode].extend(outsplit)
if start == 0:
if outsplit[0] == excode:
start = 1
elif outsplit[1] == excode:
start = 1
elif outsplit[2] == excode:
start = 1
def job_error_check(input):
client,jobs = input
jobstat = subprocess.Popen(shlex.split('/usr/openv/netbackup/bin/admincmd/bperror -jobid {0} -client {1}'.format(' '.join(jobs),client)),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
for checkline in jobstat.communicate()[0].splitlines():
if 'EXIT STATUS 0' in checkline:
return(client)
job_ids_server = {}
successful_second_try = []
p = multiprocessing.Pool(10)
client_jobs = []
nothingfound = 0
ignorecode = ['0','1','71','150','191','288','800','2074'] # this is a list of return codes to ignore
for code in sorted(svrsort.keys(),key=len):
if code in ignorecode:
pass
else:
for svr in svrsort[code]:
job_ids_server[svr] = []
bperror_backupstat = subprocess.Popen(shlex.split('/usr/openv/netbackup/bin/admincmd/bperror -hoursago {0} -t backstat -client {1}'.format(hour,svr)),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
for backupstat_line in bperror_backupstat.communicate()[0].splitlines():
if 'EXIT STATUS 0' not in backupstat_line:
if backupstat_line.split()[6] not in job_ids_server[svr]:
job_ids_server[svr].append(backupstat_line.split()[6])
client_jobs = job_ids_server.items()
successful_second_try = p.map(job_error_check, client_jobs)
errorstatus(code,svrsort[code])
nothingfound = 1
if nothingfound == 0:
msg += '\tNo errors found.\n'
#####
# Email report
#####
if mailall == 0:
scriptmsg = 'Report generated by script {0} on server {1}.'.format(sys.argv[0],os.uname()[1])
emailgrp = ['user@company.com','Operator@company.com','linuxteam@company.com','windows@company.com']
emailmsg = email.mime.Text.MIMEText(msg + scriptmsg)
emailmsg['Subject'] = 'Netbackup error report: {0}'.format(enddate.strftime("%A, %d. %B %Y"))
emailmsg['To'] = ', '.join(emailgrp)
emailmsg['From'] = 'unix@company.com'
mail = smtplib.SMTP('localhost')
mail.sendmail('root', emailgrp, emailmsg.as_string())
mail.quit()
else:
print msg
logreport(msg)
10-26-2018 05:34 AM
Try 'bperror -backstat -d <start-date> -e <end-date> -l '
Field 11 = Policy name
See: https://www.veritas.com/support/en_US/doc/123533878-127136857-0/v123537594-127136857
10-26-2018 06:01 AM
Command listed by @Marianne will do the job for you. It will list all the backups ran in the environment and will show even failed ones so you have all the list of backups ran against the policy that you are looking for.
If you further need backup details (only successfull and partially & not failed ones) you can use bpimagelist command
Single Policy - bpimagelist -policy policy_name -d mm/dd/yyyy HH:MM:SS -e mm/dd/yyyy HH:MM:SS -U
All backup details - bpimagelist -d mm/dd/yyyy HH:MM:SS -e mm/dd/yyyy HH:MM:SS -U
10-26-2018 07:22 AM
Thank you!