Veritas-bu

[Veritas-bu] How to present vault.xml in a text format

2005-05-09 23:40:34
Subject: [Veritas-bu] How to present vault.xml in a text format
From: David Rock <dave-bu AT graniteweb DOT com> (David Rock)
Date: Mon, 9 May 2005 22:40:34 -0500
--lc9FT7cWel8HagAv
Content-Type: multipart/mixed; boundary="m51xatjYGsM+13rf"
Content-Disposition: inline


--m51xatjYGsM+13rf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

* Michael L. Barrow <michael AT michaelbarrow DOT name> [2005-05-09 18:38]:
> David Rock wrote:
> >I think the main point is you as a user should not _have_ to resort to
> >your own scripting to get basic data like "what is the vaulting for
> >client A".
> >
>=20
> True, but things are the way that they are. Maybe it'll be fixed in some=
=20
> later version. In the mean time, I just wanted to give a suggestion that=
=20
> would get the job done, which is what we're all trying to do, right?

We are all trying to just get by with the same albatross hanging around
our necks ;-)

Actually, I am working on another python script to deal with this
problem. It's a hack right now, so I consider it beta at best. It takes
the policy information and cross-references the vault.xml file to give
you a listing per client that shows policy, schedule, day of week, start
window, retention, filelist, vault profile and vault retention.=20

There are a couple caveats with this that I can think of right now. This
was intended to deal with vault profiles that have only one copy being
created, multiple inline tape copies likely won't work (yet). This is
beta, so use at your own risk. It won't hurt anything, but the data may
be a little strange. I highly recommend testing before depending on it.

I will be working on this quite a bit over the next few weeks, so
comments, suggestions, improvements are definitely welcome.

The usage is pretty straightforward. It takes a wordlist of policy names
as input on the commandline. I usually do something like this (in UNIX):

pol_report.py  policy1 policy2 policy3
or
pol_report.py `bppllist | grep something`

--=20
David Rock
david AT graniteweb DOT com

--m51xatjYGsM+13rf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pol_report.py"
Content-Transfer-Encoding: quoted-printable

#!/usr/local/bin/python

import sys
import commands
import datetime
import xml.dom.minidom
=66rom xml.dom import Node

schedType =3D { '0':'Full',
                '1': 'Differential Incremental',
                '4': 'Cumulative Incremental',
                '3': 'User Archive',
                '2': 'User Backup'
                }

retLevel=3D{
    '-1': 'No Change',
    '0': '1 week',
    '1': '2 weeks',
    '2': '1 month',
    '3': '35 days',
    '4': '2 months',
    '5': '3 months',
    '6': '6 months',
    '7': '12 months',
    '8': '2 years',
    '9': 'infinity',
    '10': '3 years',
    '11': '3 days',
    '12': '13 months',
    '13': '5 years',
    '14': '7 years',
    '15': '10 years',
    '16': 'infinity',
    '17': 'infinity',
    '18': 'infinity',
    '19': 'infinity',
    '20': 'infinity',
    '21': 'infinity',
    '22': 'infinity',
    '23': 'infinity',
    '24': 'infinity'
    }

# Policy INFO line
# 1   2 3 4 5   6    7 8      9    10 11 12 13 14 15 16 17 18 19   20      =
    21                           22=20
#INFO 6 0 0 0 *NULL* 0 0 2147483647 0  0  0  0  0  0  0  0  0  0 1088520139=
 85BD1B0A1DD211B2AE2C0800208094C0 1
#
# 1 Tag
# 2 Policy Type
# 3 Follow NFS/Backup Network Drives (0 no/1 yes)
# 4 Compression (0 no/1 yes)
# 5 Job Priority (int value)
# 6=20
# 7=20
# 8 Collect DR Info (0 no/1 yes)
# 9 Limit Jobs Per Policy (int value)
#10 Cross Mount Points (0 no/ 1 yes)
#11
#12 Active (0 yes / 1 no)
#13 Collect TIR (0 no/1 yes/2 yes with move detection)
#14
#15
#16
#17 Allow Multiple Data Streams
#18
#19
#20 Active Date
#21
#22

fileName =3D "/usr/openv/netbackup/db/vault/vault.xml"
file =3D open(fileName, 'r')
document =3D xml.dom.minidom.parse(file)
clientList =3D []

customerList =3D sys.argv[1:]
bppllist =3D {}
for p in customerList:
    bppllist.setdefault(p,{})
    bppllist[p].setdefault('data', commands.getoutput('/usr/openv/netbackup=
/bin/admincmd/bppllist '+p))
    bppllist[p].setdefault('schedules',{})
    #print >>sys.stderr, p, bppllist[p]['data']

# parse bppllist data
for policy in bppllist.keys():
    buffer =3D bppllist[policy]['data'].split('\n')
    for item in buffer:
        itemSplit =3D item.split()
        #if CLASS
        if itemSplit[0] =3D=3D 'INFO':
            bppllist[policy].setdefault('info',{})
            bppllist[policy]['info']['policyType'] =3D itemSplit[1]
            bppllist[policy]['info']['followNFS'] =3D itemSplit[2]
            if itemSplit[11] =3D=3D '0':=20
                bppllist[policy]['info']['active'] =3D True
            else:
                bppllist[policy]['info']['active'] =3D False
        #if RES
        #if POOL
        # Don't forget that it is possible for a policy to have=20
        # NO clients, filelists OR schedules
        if itemSplit[0] =3D=3D 'CLIENT':
            bppllist[policy].setdefault('clients',[]).append(itemSplit[1])
        if itemSplit[0] =3D=3D 'INCLUDE':
            bppllist[policy].setdefault('filelist',[]).append(item.split(No=
ne,1)[1])
        if itemSplit[0] =3D=3D 'SCHED':
            schedName =3D itemSplit[1]
            bppllist[policy]['schedules'].setdefault(schedName,{})
            bppllist[policy]['schedules'][schedName]['type'] =3D schedType[=
itemSplit[2]]
            bppllist[policy]['schedules'][schedName]['freq'] =3D itemSplit[=
4]
            bppllist[policy]['schedules'][schedName]['retention'] =3D retLe=
vel[itemSplit[5]]
        if itemSplit[0] =3D=3D 'SCHEDWIN':
            bppllist[policy]['schedules'][schedName].setdefault('windows',{=
})
            idx =3D 1
            for day in ['sunday','monday','tuesday','wednesday','thursday',=
'friday','saturday']:
                bppllist[policy]['schedules'][schedName]['windows'].setdefa=
ult(day,{})
                bppllist[policy]['schedules'][schedName]['windows'][day]['s=
tart'] =3D int(itemSplit[idx])
                idx +=3D 1
                bppllist[policy]['schedules'][schedName]['windows'][day]['e=
nd'] =3D int(itemSplit[idx])
                idx +=3D 1
                if bppllist[policy]['schedules'][schedName]['windows'][day]=
['start'] =3D=3D 0 and \
                    bppllist[policy]['schedules'][schedName]['windows'][day=
]['end'] =3D=3D 0:
                    bppllist[policy]['schedules'][schedName]['windows'][day=
]['run'] =3D False
                else:
                    bppllist[policy]['schedules'][schedName]['windows'][day=
]['run'] =3D True
    try:
        for client in bppllist[policy]['clients']:
            if client not in clientList: clientList.append(client)
    except:
        bppllist[policy].setdefault('clients',[])

clientInfo =3D {}
for client in clientList:
    for policy in bppllist.keys():
        if client in bppllist[policy]['clients']:
            clientInfo.setdefault(client,{})
            clientInfo[client].setdefault('policies',[]).append(policy)


def getStartTime (input):
    d =3D datetime.datetime(1900,1,1)
    delta =3D datetime.timedelta(seconds=3Dinput)
    start =3D d+delta
    return start.strftime('%H:%M:%S')

def activeVaults():
    pass

def vaults(policy,sched):
    classes =3D []
    vault =3D []
    retention =3D ''
    v =3D ''

    for node in document.getElementsByTagName("CLASS"):
        if node.childNodes[0].nodeValue.find(policy) > -1:
            classes.append(node)

    # find sched siblings
    for cNode in classes:
        copies =3D []
        hasSchedule =3D False
        selNode =3D cNode.parentNode
        vaultNode =3D selNode.parentNode

        for node in document.getElementsByTagName("COPY"):
            if node.parentNode.parentNode.parentNode =3D=3D vaultNode:
                copies.append(node)
        if copies:
            copyAttrs =3D {}
            for idx in range(0,copies[0].attributes.length):
                copyAttrs.setdefault(copies[0].attributes.item(idx).name, c=
opies[0].attributes.item(idx).value)
            retention =3D retLevel[copyAttrs['Retention']]
        else:
            retention =3D 'Vault Originals'

        for selNodeChild in selNode.childNodes:
            if selNodeChild.nodeName =3D=3D 'SCHEDULE':
                hasSchedule =3D True
                if selNodeChild.childNodes[0].nodeValue =3D=3D sched:
                    #vault.append(vaultNode.attributes.item(0).value)
                    v =3D vaultNode.attributes.item(0).value
                    #return v
                    #print policy, sched, vaultNode.attributes.item(0).valu=
e, 'Found Sched in vault'
        if not hasSchedule:
            v =3D vaultNode.attributes.item(0).value
            #return v
            #print policy, sched, vaultNode.attributes.item(0).value, 'NO s=
chedules in vault'
    return v,retention
   =20

print 'CLIENT,POLICY,ACTIVE,SCHEDULE,WINDOW_START,SCHEDULE_TYPE,DAY_OF_WEEK=
,ORIGINAL_RETENTION,FILELIST,VAULT_PROFILE,VAULT_RETENTION'
for client in clientInfo.keys():
    for policy in clientInfo[client]['policies']:
        if bppllist[policy]['info']['active']:
            try:
                filelist =3D '|'.join(bppllist[policy]['filelist'])
            except:
                filelist =3D ''
            for sched in bppllist[policy]['schedules']:
                vault,vaultRetention =3D vaults(policy,sched)
                for day in bppllist[policy]['schedules'][sched]['windows']:
                    if bppllist[policy]['schedules'][sched]['windows'][day]=
['run']:
                        print '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % \
                        (   client,
                            policy,
                            'Yes',  #Policy active
                            sched,
                            getStartTime(bppllist[policy]['schedules'][sche=
d]['windows'][day]['start']),
                            bppllist[policy]['schedules'][sched]['type'],
                            day,
                            bppllist[policy]['schedules'][sched]['retention=
'],
                            filelist,
                            vault,
                            #vaultSchedule,
                            vaultRetention
                        )
        else:
            try:
                filelist =3D '|'.join(bppllist[policy]['filelist'])
            except:
                filelist =3D ''
            for sched in bppllist[policy]['schedules']:
                vault,vaultRetention =3D vaults(policy,sched)
                for day in bppllist[policy]['schedules'][sched]['windows']:
                    if bppllist[policy]['schedules'][sched]['windows'][day]=
['run']:
                        print '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % \
                        (   client,
                            policy,
                            'No',  #Policy not active
                            sched,
                            getStartTime(bppllist[policy]['schedules'][sche=
d]['windows'][day]['start']),
                            bppllist[policy]['schedules'][sched]['type'],
                            day,
                            bppllist[policy]['schedules'][sched]['retention=
'],
                            filelist,
                            vault,
                            #vaultSchedule,
                            vaultRetention
                        )
           =20
           =20

# modeline vim:set ts=3D4 sw=3D4 et:

--m51xatjYGsM+13rf--

--lc9FT7cWel8HagAv
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCgC0yMrO4/Yb/xwYRAh/vAKDhM5QfQ5+3EB/gxekydhTRXvdTEQCgmRUF
jI1UqnpzSlPMY7d17/pz104=
=N9Lr
-----END PGP SIGNATURE-----

--lc9FT7cWel8HagAv--