2 Intern

 • 

2K Posts

February 6th, 2015 09:00

I don't believe this can be done using a single command but you may find it helpful to retrieve the first output in xml format (by specifying the --xml flag) so you don't have to do screen-scraping or RegEx matching. Here is an example of the XML format:

admin@testavamar:~/#: mccli retention show --recursive --verbose --xml

 

    0

    23000

    CLI command completed successfully.

 

 

   

      Default Retention

      /

      60 days

      Yes

   

   

      End User On Demand Retention

      /

      60 days

      No

   

   

      Ian_Test

      /

      65 days

      No

   

   

      Minimal Retention

      /

      No expiration

      No

   

   

      Monthly Retention

      /

      1 month

      No

   

   

      Weekly Retention

      /

      1 week

      No

   

 

February 6th, 2015 12:00

The way I do it is I query the PostgreSQL database with a python script, and loop over the result of the first query.

But Ian is right, using XML would make more sense. All of these answer assume your scripting skills are up to date =)

22 Posts

February 8th, 2015 05:00

Hi JWeinsheimer,

You can use this command. But only works if retention name have not spaces. This is a good starting point for improvement.

mccli retention show --domain=/ --recursive=true | grep "/" | awk '{print $1,$2}' | while read c d; do echo "$d/$c"; mccli retention show --domain=$d --name=$c --verbose; done

Regards, César

2 Intern

 • 

176 Posts

February 8th, 2015 20:00

Try this ::--->

############# Cut Here #############

#### Set the necessary Variables ::--->
OLDIFS=$IFS

IFS=$'\n'

DataFile=`hostname`_retentions.txt`

#### Generate retention xml file ::--->

mccli retention show --recursive --verbose --xml > `hostname`_ret.xml

#### Parse out xml info info ::--->

awk -F'' '{for(i=2;i<=NF;i++) print $i}' `hostname`_ret.xml |sed '/^$/d'  >one.txt

awk -F'' '{for(i=2;i<=NF;i++) print $i}' `hostname`_ret.xml |sed '/^$/d' >two.txt

#### Combine both files created ::--->

paste -d/ one.txt two.txt|sed 's/\/\//\//g' > $DataFile

#### Loop tru the final collected data ::--->

for i in `cat $DataFile`; do echo "*** $i ***";mccli retention show --name=$i --verbose|sed '1,1d'; done


#### Unset the necessary Variables ::--->

IFS=$OLDIFS


############# Cut Here #############


Thanks....


Joe Despres

91 Posts

February 12th, 2015 10:00

Doesn't full work, but it should put me on the right path. Thanks!    

2 Intern

 • 

176 Posts

February 12th, 2015 12:00

#### Example output ::--->

:~/DataFiles/>: ret

*** /Default Retention ***

Attribute              Value

---------------------- -----------------

Name                   Default Retention

Domain                 /

Basic Expiration Date  60 days

Override               Yes

Keep DAYS of Daily     60

Keep WEEKS of Weekly   0

Keep MONTHS of Monthly 0

Keep YEARS of Yearly   0

*** /End User On Demand Retention ***

Attribute             Value

--------------------- ----------------------------

Name                  End User On Demand Retention

Domain                /

Basic Expiration Date 60 days

*** /Minimal Retention ***

Attribute             Value

--------------------- -----------------

Name                  Minimal Retention

Domain                /

Basic Expiration Date No expiration

Disabled              Yes

*** /Monthly Retention ***

Attribute              Value

---------------------- -----------------

Name                   Monthly Retention

Domain                 /

Basic Expiration Date  1 month

Override               No

Keep DAYS of Daily     60

Keep WEEKS of Weekly   0

Keep MONTHS of Monthly 0

Keep YEARS of Yearly   0

*** /Repl Group 1 Repl Expiration ***

Attribute              Value

---------------------- ----------------------------------

Name                   Repl Group 1 Repl Expiration

Domain                 /

Basic Expiration Date  No change (keep backup expiration)

Override               No

Keep DAYS of Daily     60

Keep WEEKS of Weekly   0

Keep MONTHS of Monthly 0

Keep YEARS of Yearly   0

2 Intern

 • 

176 Posts

February 12th, 2015 12:00

I learned two pieces of info here....

1:  How to handle spaces ...

2:  How to parse a xml file...

Joe Despres

2 Intern

 • 

176 Posts

February 12th, 2015 12:00

Try this function ::--->

ret () {
OLDIFS=$IFS
IFS=$'\n'
DataFile=`hostname`_retentions.txt
mccli retention show --recursive --verbose --xml > `hostname`_ret.xml
awk -F'' '{for(i=2;i<=NF;i++) print $i}' `hostname`_ret.xml |sed '/^$/d'  >one.txt
awk -F'' '{for(i=2;i<=NF;i++) print $i}' `hostname`_ret.xml |sed '/^$/d' >two.txt
paste -d/ one.txt two.txt|sed 's/\/\//\//g' > $DataFile
for i in `cat $DataFile`; do echo "*** $i ***";mccli retention show --name=$i --verbose|sed '1,1d'; done
IFS=$OLDIFS
}

Then run it ::--->
ret

2 Intern

 • 

2K Posts

February 12th, 2015 12:00

Relevant, re: parsing XML:

http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags

I always recommend using a real XML parser for XML but I understand why quick and dirty is appealing (and I have occasionally committed this sin myself when I'm in a hurry).

I'd recommend using an XML parsing module in a scripting language like Perl, Python, Ruby, etc. if you plan to rely on this tool for anything "production-y".

Language XML Parsers
Perl XML::Parser, XML::Simple
Python xml.dom, xml.sax
Ruby ReXML, Nokogiri

91 Posts

February 12th, 2015 12:00

I was able to get it working using xml parsing and the following...

LINE=0

cat file1 | while read VAR1

  do

    let LINE=$LINE+1

    VAR2=$(cat file2 | sed -n ${LINE}p)

    echo $VAR1 $VAR2

done

Where file1 and file2 are the parsed xml outputs.

Thanks a ton!

2 Intern

 • 

176 Posts

February 12th, 2015 13:00

I like quick & dirty.....

But you do have a point! 

I will need to learn how to interface Avamar's API's....

good luck to me

Thanks

Joe Despres

No Events found!

Top