Hello everyone. I was recently in need of a way to search through my Amanda indexes, so I wrote a bash script to do just that. I have seen a few other people on this list looking for a way to search the index, to I figured I'd post my script. It works well for me, but YMMV.
I'm just going to attach the script to this message, since it isn't very large, but for future reference, is there a better way to post this sort of thing? Anthony Valentine
#!/bin/bash ### Start of Script ########################################################################### amindexsearch - Searches through and Amanda index directory searching for specified patterns and (optionally) a date ------------------- begin : Thu Jul 25 09:02:56 AKDT 2002 copyright : (C) 2002 by Anthony Valentine email : [EMAIL PROTECTED] ########################################################################### ########################################################################### # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; either version 2 of the License, or # # (at your option) any later version. # # # ########################################################################### ### This next line is needed on my systems to set certain environment ### variables. Everyone else should leave it commented out. #. /etc/profile.gemini ## Turn on debugging DEBUG=off if [ ! "${DEBUG}" = "off" ]; then set -x fi if [ $# -lt 2 ] || [ "${1}" = "--help" ] || [ "${1}" = "-h" ]; then echo " " echo "Usage: `basename $0` <configname> [-d datestring] <pattern1> [pattern2] ... [paternN]" echo " " echo "Where: configname is an Amanda configuration name." echo " datestring is a string in YYYYMMDD format (ex. 20020725)." echo " patternX are the grep regexp patterns to search for." echo " " echo "Note that Config name is case sensitive, but the search patterns are not." echo " " echo " " exit 1 fi ### Set TEMPFILE variables; remove the files before we start TEMPFILE1=/tmp/amindextmp1.$$ rm -f ${TEMPFILE1} ### Find the amanda home directory in the password file AMANDAHOME=`cat /etc/passwd |grep "^amanda:" | cut -d: -f 6` ### Check for a valid config directory if [ -d ${AMANDAHOME}/${1} ]; then ### Check first in Amanda's home dir (that's where I keep mine) AMCONFIG=${AMANDAHOME}/${1} elif [ -d "/usr/local/etc/amanda/${1}" ]; then ### Then check default location AMCONFIG="/usr/local/etc/amanda/${1}" else echo " " echo "Invalid Config Name" ### If not found, exit with an error echo " " exit 2 fi ### Check for datestring; note that DATESTRING is NOT validated as an actual date if [ "${2}" = "-d" ]; then DATESTRING=${3} shift 2 else DATESTRING="." fi ### Get the index directory from the amanda.conf file INDEXDIR=`cat ${AMCONFIG}/amanda.conf | grep "^indexdir" | awk '{print $2}' | sed 's/"//g'` ### Create a file of search patterns entered on the command line shift 1 while [ $# -gt 0 ] do echo ${1} >> ${TEMPFILE1} shift 1 done ### Print a header echo "LVL HOST DATE DISK FILE" echo "--- --------- -------- ------------------------ ---------------------------------" ### Search through index dir for matches. cd ${INDEXDIR} for INDEX in `find . -print` do ### Search inside each compressed index file; for FILE in `zcat ${INDEX} 2>/dev/null | grep -if ${TEMPFILE1} 2>/dev/null` do ### get the HOST and pad it out to 10 chars long (for neater printing) SETHOSTTMP=`echo ${INDEX} | awk -F/ '{print $2}'` SETHOST=`echo "${SETHOSTTMP}"'""""""""""' | sed 's/^\(..........\).*$/\1/'` ### get the DISKLIST and pad it out to 25 chars (for neater printing) SETDISKTMP=`echo ${INDEX} | awk -F/ '{print $3}' | sed 's/_/\//'` SETDISK=`echo "${SETDISKTMP}"'"""""""""""""""""""""""""' | sed 's/^\(.........................\).*$/\1/'` ### get the DATE and BACKUP LEVEL DATELEVEL=`echo ${INDEX} | awk -F/ '{print $4}'` SETDATE=`echo ${DATELEVEL} | awk -F_ '{print $1}'` LEVEL=`echo ${DATELEVEL} | awk -F_ '{print $2}' | awk -F. '{print $1}'` ### Print all that, the name of the file and replace the pad char " with spaces echo "${LEVEL} ${SETHOST}${SETDATE} ${SETDISK}${FILE}"| sed 's/\"/ /g' | grep ${DATESTRING} done done ### Clean up rm ${TEMPFILE1} ### End of Script exit 0