@echo off setlocal enabledelayedexpansion REM **************************************************************************************************** REM * File: search-backups.bat REM * Desc: Search backups for files, and report the backup image and media and files found. REM * REM * Vers Date Who Description REM * ---- ---- --- ----------- REM * v0.01 10-JUL-2015 sdo Start development, first listings. REM * v0.02 10-JUL-2015 sdo Check policy type name and policy type number. REM * v0.03 10-JUL-2015 sdo Build correct switches for three different commands. REM * v0.04 10-JUL-2015 sdo Loop around clients. Add section headers to code. REM * v0.05 10-JUL-2015 sdo Loop around backups images. REM * v0.06 11-JUL-2015 sdo Only add image details if files are found. Cease using bpflist. REM * v0.07 11-JUL-2015 sdo List media for all copies. Don't also log to the report file. REM * v0.08 11-JUL-2015 sdo Delete temp files during clean exit. Don't mix log and report. REM * v0.09 11-JUL-2015 sdo Added usage, and add more comments. REM * v0.10 11-JUL-2015 sdo Detect NetBackup path, build CLI paths and check. REM * v0.11 11-JUL-2015 sdo Added about notes, and check that not all six search are empty. REM * v0.12 11-JUL-2015 sdo Detect NetBackup installation type. REM * v0.13 11-JUL-2015 sdo Begin mods to be able to run from the client. REM * v0.14 12-JUL-2015 sdo Use image dates not image names. REM * v0.15 12-JUL-2015 sdo Added debug flag. Added and updated notes, usage, comments. REM * v0.16 12-JUL-2015 sdo Updates to run on client side, report section spacing. REM * v0.17 12-JUL-2015 sdo Attempt to handle inaccurate policy type names. REM **************************************************************************************************** REM * About this script REM * ----------------- REM * 1) This script is free to copy and or modify, as long the version table and all notes are REM * maintained. And any changes to the code are also reflected in the version table and, where REM * necessary, the notes and usage. REM * 2) Was written and tested on Windows 2012 R2 using NetBackup v7.6.1.2 but should work on any REM * version of Windows since Windows Server 2003, and any version v7.x of NetBackup. REM * 3) Can run on master, media, client and also on pre v7.7 Windows admin console type installs. REM * 4) When run on a server, the script is able to run with an empty client name, causing the REM * script to check backups across all clients. REM * 5) When run on a server, the script will list basic image summary, image header detail, and all REM * media for all copies, and also the discovered matched folder and/or file names. REM * 6) When run on a client, script will only list a basic image summary, and match folder/file REM * names found. REM * 7) The script tries to keep the querying of the catalog to a minimum, and always tries to REM * reduce the number of backup images which might be searched. REM * 8) If you do not specify any search criteria, i.e. leave many of the search items blank, then REM * this script could take a very long time to run and could generate a very big report file. REM * 9) Several temporary files are created within the same folder as the script whilst the script REM * is running, and will be removed by the script if/when the script successfully completes. REM * 10) Two files created by this script will remain when it successfully completes. REM * script-name.log A text file log of the script run. REM * script-name.txt A text file report of files found and the related backup images. REM **************************************************************************************************** REM * How to use this script REM * ---------------------- REM * 1) Save a copy of this script somewhere, e.g: REM * D:\NBU-SCRIPTS\search-backups\search-backups.bat REM * 2) Open the script in "notepad". REM * 3) Search for the 'CHANGE_ME' section. REM * 4) Then amend one or more of the six search criteria. REM * 5) Always try to narrow down the search as much as possible, and only widen the search if the REM * required files are not being found. REM * 6) Only the "set z_match=" line can have wild-card characters, of: REM * ? match any one single character REM * * match zero or more of any character REM * 7) Or REM out a line, which will cause a wider range of backups to be searched. REM * 8) Within "notepad", save your amendments, and close. REM * 9) Double click the script to run it. REM * REM * Usage tips REM * ---------- REM * i) This script should be fit for use by 'server admins' (i.e. technical users of NetBackup) to REM * help them locate files, but if they send you the output of what they want restored, then you REM * (as a backup admin) won't be able to see in their report, which copies are where, or the REM * backup image header (in the report). REM * So, get the server admin to send his/her copy of the script and the output, and then you REM * (as a backup admin) could run their version of the script, to generate a more detailed report REM * which will include the image header details, and a list of all copies, and where those copies REM * are. REM **************************************************************************************************** REM * Risks REM * ----- REM * 1) This script has not been tested by Symantec, nor is it endorsed by Symantec. REM * 2) Use, and/or mis-use, of this script is entirely at the end user's own risk. REM * 3) Having said all that, I've tried to make it error free, and it checks the status of every REM * command that it isseues, and should stop if errors are encountered. REM * 4) This script writes all of its temporary, and output, files within the folder that the script REM * lives in. REM * 5) If the search is very wide, then this script can take a long time to run, and will issue a REM * large number of queries to the NetBackup Master server catalog. REM * 6) If the search paramters are too wide, then this script may generate some very large files REM * which may consume a lot, or all, disk space from the volume upon which the script resides. REM **************************************************************************************************** REM * Ideas for development REM * --------------------- REM * 1) Accept the search criteria as parameters? REM **************************************************************************************************** set z_path=%~dp0 set z_name=%~n0 set z_debug=no REM set z_debug=YES set z_file_bid=!z_path!!z_name!.bid set z_file_cli=!z_path!!z_name!.cli set z_file_lis=!z_path!!z_name!.lis set z_file_log=!z_path!!z_name!.log set z_file_tmp=!z_path!!z_name!.tmp set z_file_txt=!z_path!!z_name!.txt if exist "!z_file_bid!" del "!z_file_bid!" if exist "!z_file_cli!" del "!z_file_cli!" if exist "!z_file_lis!" del "!z_file_lis!" if exist "!z_file_log!" del "!z_file_log!" if exist "!z_file_tmp!" del "!z_file_tmp!" if exist "!z_file_txt!" del "!z_file_txt!" call :log "" call :log "Script started..." set z_script_started=!date! !time:~0,8! REM ************************************************************************** REM *** Determine NetBackup installation... call :log "" call :log "Determining NetBackup installation..." reg query "HKLM\Software\Veritas\NetBackup\CurrentVersion" /v "InstallDir" >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if not !z_sts!==0 ( call :log "...failed to determine install directory for NetBackup, status `!z_sts!`, script aborting..." goto :end ) for /f "tokens=1,2,* skip=1" %%a in ('type "!z_file_tmp!"') do (set z_installdir=%%c) reg query "HKLM\Software\Veritas\NetBackup\CurrentVersion" /v "Install Type" >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if not !z_sts!==0 ( call :log "...failed to determine install type for NetBackup, status `!z_sts!`, script aborting..." goto :end ) for /f "tokens=1,2,3,* skip=1" %%a in ('type "!z_file_tmp!"') do (set z_install_type=%%d) if /i "!z_install_type!"=="NetBackup Client" ( set z_type=client ) else ( set z_type=server ) call :log "...NetBackup installed path is: !z_installdir!" call :log "...NetBackup installation type is: !z_install_type!" call :log "...done..." REM ************************************************************************** REM *** Checking for CLI commands... call :log "" call :log "Checking for presence of NetBackup command line tools..." set z_okay=yes set z_bpclimagelist=!z_installdir!NetBackup\bin\bpclimagelist.exe set z_bpimagelist=!z_installdir!NetBackup\bin\admincmd\bpimagelist.exe set z_bplist=!z_installdir!NetBackup\bin\bplist.exe set z_bpverify=!z_installdir!NetBackup\bin\admincmd\bpverify.exe if not exist "!z_bpclimagelist!" ( call :log "...unable to locate `bpclimagelist` command..." set z_okay=no ) if not exist "!z_bpimagelist!" ( if /i "!z_type!"=="server" ( call :log "...unable to locate `bpimagelist` command..." set z_okay=no ) ) if not exist "!z_bplist!" ( call :log "...unable to locate `bplist` command..." set z_okay=no ) if not exist "!z_bpverify!" ( if /i "!z_type!"=="server" ( call :log "...unable to locate `bpverify` command..." set z_okay=no ) ) if /i not "!z_okay!"=="yes" ( call :log "...one or more commands are missing, script aborting..." goto :end ) call :log "...done..." REM ************************************************************************** REM *** Do NOT amend these next six lines... REM *** ...these are here so that you can simply REM out what you... REM *** ...don't need in the next section... set z_client= set z_policy= set z_policy_type= set z_search_stt= set z_search_end= set z_match= REM ************************************************************************** REM *** CHANGE_ME REM *** FYI - the pattern match wild card characters are: REM *** ? match any one character REM *** * match zero or more of any character REM *** ...this script uses case in-sensitive searching... REM *** ...and will match anywhere within the whole folder and file name path... REM *** ...change any of the six items below to narrow down the search... REM *** ...or "REM" out one or more (but not all) to widen the search... REM set z_client=master01 REM set z_policy=TEST001 set z_policy_type=windows set z_search_stt=01/07/2015 00:00:00 set z_search_end=31/07/2015 23:59:59 set z_match=*uP*gRaDe*.?Df REM ************************************************************************** REM *** Report and check the search criteria... REM *** ...do NOT change this... if /i "!z_type!"=="client" ( if "!z_client!"=="" ( call :log "" call :log "Running on a client, but no client name specified, will attempt to default the client name..." reg query "HKLM\Software\Veritas\NetBackup\CurrentVersion\Config" /v "Client_Name" >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if not !z_sts!==0 ( call :log "...failed to determine install directory for NetBackup, status `!z_sts!`, script aborting..." goto :end ) for /f "tokens=1,2,* skip=1" %%a in ('type "!z_file_tmp!"') do (set z_client=%%c) call :log "...client name defaulted to `!z_client!`..." call :log "...done..." ) ) call :log "" call :log "Listing search parameters..." call :log "...client name: !z_client!" call :log "...policy name: !z_policy!" call :log "...policy type: !z_policy_type!" call :log "...start date: !z_search_stt!" call :log "...end date: !z_search_end!" call :log "...match path name: !z_match!" if "!z_client!"=="" ( if "!z_policy!"=="" ( if "!z_policy_type!"=="" ( if "!z_search_stt!"=="" ( if "!z_search_end!"=="" ( if "!z_match!"=="" ( call :log "...cannot run with all search criteria blank, script aborting..." goto :end ) ) ) ) ) ) call :log "...done..." REM ************************************************************************** REM *** Some things do still need to be set, and when blank do still to have REM *** ...a value. Do NOT change these two... if "!z_search_stt!"=="" set z_search_stt=01/01/1970 00:00:00 if "!z_match!"=="" set z_match=* REM ************************************************************************** REM *** Check policy type... call :log "" call :log "Checking policy type..." REM attempt to fix up inaccurate policy type names... if /i "!z_policy_type!"=="ms-windows" set z_policy_type=MS-Windows if /i "!z_policy_type!"=="mswindows" set z_policy_type=MS-Windows if /i "!z_policy_type!"=="mswin" set z_policy_type=MS-Windows if /i "!z_policy_type!"=="windows" set z_policy_type=MS-Windows if /i "!z_policy_type!"=="win2012" set z_policy_type=MS-Windows if /i "!z_policy_type!"=="win2008" set z_policy_type=MS-Windows if /i "!z_policy_type!"=="win2003" set z_policy_type=MS-Windows if /i "!z_policy_type!"=="win" set z_policy_type=MS-Windows if /i "!z_policy_type!"=="standard" set z_policy_type=Standard if /i "!z_policy_type!"=="aix" set z_policy_type=Standard if /i "!z_policy_type!"=="centos" set z_policy_type=Standard if /i "!z_policy_type!"=="debian" set z_policy_type=Standard if /i "!z_policy_type!"=="hpux" set z_policy_type=Standard if /i "!z_policy_type!"=="linux" set z_policy_type=Standard if /i "!z_policy_type!"=="mac" set z_policy_type=Standard if /i "!z_policy_type!"=="macintosh" set z_policy_type=Standard if /i "!z_policy_type!"=="macosx" set z_policy_type=Standard if /i "!z_policy_type!"=="openvms" set z_policy_type=Standard if /i "!z_policy_type!"=="osx" set z_policy_type=Standard if /i "!z_policy_type!"=="redhat" set z_policy_type=Standard if /i "!z_policy_type!"=="rhel" set z_policy_type=Standard if /i "!z_policy_type!"=="rs6000" set z_policy_type=Standard if /i "!z_policy_type!"=="solaris" set z_policy_type=Standard if /i "!z_policy_type!"=="suse" set z_policy_type=Standard if /i "!z_policy_type!"=="ubuntu" set z_policy_type=Standard if /i "!z_policy_type!"=="unix" set z_policy_type=Standard if /i "!z_policy_type!"=="vms" set z_policy_type=Standard if /i "!z_policy_type!"=="ndmp" set z_policy_type=NDMP if /i "!z_policy_type!"=="cdot" set z_policy_type=NDMP if /i "!z_policy_type!"=="celera" set z_policy_type=NDMP if /i "!z_policy_type!"=="celerra" set z_policy_type=NDMP if /i "!z_policy_type!"=="cellera" set z_policy_type=NDMP if /i "!z_policy_type!"=="cellerra" set z_policy_type=NDMP if /i "!z_policy_type!"=="emc" set z_policy_type=NDMP if /i "!z_policy_type!"=="hnas" set z_policy_type=NDMP if /i "!z_policy_type!"=="isilon" set z_policy_type=NDMP if /i "!z_policy_type!"=="nas" set z_policy_type=NDMP if /i "!z_policy_type!"=="netapp" set z_policy_type=NDMP if /i "!z_policy_type!"=="ontap" set z_policy_type=NDMP if /i "!z_policy_type!"=="vnx" set z_policy_type=NDMP if /i "!z_policy_type!"=="enterprise-vault" set z_policy_type=Enterprise-Vault if /i "!z_policy_type!"=="e-vault" set z_policy_type=Enterprise-Vault if /i "!z_policy_type!"=="evault" set z_policy_type=Enterprise-Vault if /i "!z_policy_type!"=="ev" set z_policy_type=Enterprise-Vault if /i "!z_policy_type!"=="lotusnotes" set z_policy_type=LotusNotes if /i "!z_policy_type!"=="domino" set z_policy_type=LotusNotes if /i "!z_policy_type!"=="lotus" set z_policy_type=LotusNotes if /i "!z_policy_type!"=="notes" set z_policy_type=LotusNotes if /i "!z_policy_type!"=="ms-exchange-server" set z_policy_type=MS-Exchange-Server if /i "!z_policy_type!"=="ms-exchange" set z_policy_type=MS-Exchange-Server if /i "!z_policy_type!"=="msexchange" set z_policy_type=MS-Exchange-Server if /i "!z_policy_type!"=="exchange" set z_policy_type=MS-Exchange-Server if /i "!z_policy_type!"=="mailstore" set z_policy_type=MS-Exchange-Server if /i "!z_policy_type!"=="mailbox" set z_policy_type=MS-Exchange-Server if /i "!z_policy_type!"=="mail" set z_policy_type=MS-Exchange-Server if /i "!z_policy_type!"=="email" set z_policy_type=MS-Exchange-Server if /i "!z_policy_type!"=="ms-sharepoint" set z_policy_type=MS-SharePoint if /i "!z_policy_type!"=="sharepoint" set z_policy_type=MS-SharePoint if /i "!z_policy_type!"=="sp" set z_policy_type=MS-SharePoint if /i "!z_policy_type!"=="ms-sql-server" set z_policy_type=MS-SQL-Server if /i "!z_policy_type!"=="ms-sql" set z_policy_type=MS-SQL-Server if /i "!z_policy_type!"=="mssql" set z_policy_type=MS-SQL-Server if /i "!z_policy_type!"=="sql" set z_policy_type=MS-SQL-Server if /i "!z_policy_type!"=="sqldb" set z_policy_type=MS-SQL-Server if /i "!z_policy_type!"=="vmware" set z_policy_type=VMware if /i "!z_policy_type!"=="esx" set z_policy_type=VMware if /i "!z_policy_type!"=="esxi" set z_policy_type=VMware if /i "!z_policy_type!"=="vm" set z_policy_type=VMware if /i "!z_policy_type!"=="vcenter" set z_policy_type=VMware if /i "!z_policy_type!"=="vsphere" set z_policy_type=VMware if /i "!z_policy_type!"=="ms-hyper-v" set z_policy_type=MS-Hyper-V if /i "!z_policy_type!"=="ms-hyperv" set z_policy_type=MS-Hyper-V if /i "!z_policy_type!"=="hyper-v" set z_policy_type=MS-Hyper-V if /i "!z_policy_type!"=="hyperv" set z_policy_type=MS-Hyper-V if /i "!z_policy_type!"=="msvm" set z_policy_type=MS-Hyper-V if /i "!z_policy_type!"=="db2" set z_policy_type=DB2 if /i "!z_policy_type!"=="flashbackup" set z_policy_type=FlashBackup if /i "!z_policy_type!"=="flashbackup-windows" set z_policy_type=FlashBackup-Windows if /i "!z_policy_type!"=="netware" set z_policy_type=Netware if /i "!z_policy_type!"=="oracle" set z_policy_type=Oracle if /i "!z_policy_type!"=="sap" set z_policy_type=SAP set z_policy_type_okay=no if "!z_policy_type!"=="Enterprise-Vault" set z_policy_type_okay=yes if "!z_policy_type!"=="FlashBackup" set z_policy_type_okay=yes if "!z_policy_type!"=="FlashBackup-Windows" set z_policy_type_okay=yes if "!z_policy_type!"=="LotusNotes" set z_policy_type_okay=yes if "!z_policy_type!"=="MS-Exchange-Server" set z_policy_type_okay=yes if "!z_policy_type!"=="MS-Hyper-V" set z_policy_type_okay=yes if "!z_policy_type!"=="MS-SharePoint" set z_policy_type_okay=yes if "!z_policy_type!"=="MS-SQL-Server" set z_policy_type_okay=yes if "!z_policy_type!"=="MS-Windows" set z_policy_type_okay=yes if "!z_policy_type!"=="NDMP" set z_policy_type_okay=yes if "!z_policy_type!"=="Netware" set z_policy_type_okay=yes if "!z_policy_type!"=="DB2" set z_policy_type_okay=yes if "!z_policy_type!"=="Oracle" set z_policy_type_okay=yes if "!z_policy_type!"=="SAP" set z_policy_type_okay=yes if "!z_policy_type!"=="Standard" set z_policy_type_okay=yes if "!z_policy_type!"=="Sybase" set z_policy_type_okay=yes if "!z_policy_type!"=="VMware" set z_policy_type_okay=yes if /i not "!z_policy_type_okay!"=="yes" ( call :log "...policy type `!z_policy_type!` not known, script aborting..." goto :end ) call :log "...policy type `!z_policy_type!` is known..." call :log "...done..." REM ************************************************************************** REM *** Determine policy type number... call :log "" call :log "Converting policy type string to policy type number..." set z_policy_type_number= if "!z_policy_type!"=="Standard" set z_policy_type_number=0 if "!z_policy_type!"=="Oracle" set z_policy_type_number=4 if "!z_policy_type!"=="Sybase" set z_policy_type_number=7 if "!z_policy_type!"=="MS-SharePoint" set z_policy_type_number=8 if "!z_policy_type!"=="NetWare" set z_policy_type_number=10 if "!z_policy_type!"=="MS-Windows" set z_policy_type_number=13 if "!z_policy_type!"=="MS-SQL-Server" set z_policy_type_number=15 if "!z_policy_type!"=="MS-Exchange-Server" set z_policy_type_number=16 if "!z_policy_type!"=="SAP" set z_policy_type_number=17 if "!z_policy_type!"=="DB2" set z_policy_type_number=18 if "!z_policy_type!"=="NDMP" set z_policy_type_number=19 if "!z_policy_type!"=="FlashBackup" set z_policy_type_number=20 if "!z_policy_type!"=="Lotus Notes" set z_policy_type_number=25 if "!z_policy_type!"=="FlashBackup-Windows" set z_policy_type_number=29 if "!z_policy_type!"=="Enterprise-Vault" set z_policy_type_number=39 if "!z_policy_type!"=="VMware" set z_policy_type_number=40 if "!z_policy_type!"=="MS-Hyper-V" set z_policy_type_number=41 if "!z_policy_type_number!"=="" ( call :log "...unable to determine policy type number for bplist, script aborting..." goto :end ) call :log "...policy type name `!z_policy_type!` is policy type number `!z_policy_type_number!`..." call :log "...done..." REM ************************************************************************** REM *** Are there any backups at all for the client... if not "!z_client!"=="" ( call :log "" call :log "Checking for any backups at all for client `!z_client!`..." "!z_bpclimagelist!" -d 01/01/1970 00:00:00 -client !z_client! >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if not !z_sts!==0 ( call :log "...could not find any backups at all, client name is possibly incorrect, script aborting..." goto :end ) call :log "...found at least one backup..." call :log "...done..." ) REM ************************************************************************** REM *** Are there any backups for the client since the specified start date... if not "!z_client!"=="" ( call :log "" call :log "Checking for any backups at all for client `!z_client!` since `!z_start_date!`..." "!z_bpclimagelist!" -d !z_search_stt! -client !z_client! >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if not !z_sts!==0 ( call :log "...could not find any backups since date, script aborting..." goto :end ) call :log "...found at least one backup since date..." call :log "...done..." ) REM ************************************************************************** REM *** If we have a client name and a policy name... REM *** ...then are there any backups at all for this policy name... if not "!z_client!"=="" ( if not "!z_policy!"=="" ( call :log "" call :log "Checking for any backups at all for client `!z_client!` for policy `!z_policy!`..." "!z_bpclimagelist!" -d 01/01/1970 00:00:00 -client !z_client! -policy !z_policy! >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if not !z_sts!==0 ( call :log "...could not find any backups at all, therefore policy name is bad, script aborting..." goto :end ) call :log "...found at least one backup for client and policy..." call :log "...done..." ) ) REM ************************************************************************** REM *** Show the CLI switches that we'll be using... call :r_set_switches call :log "" call :log "Determined CLI switches are..." call :log "...bpclimagelist: !z_bpclimagelist_switches!" call :log "...bpimagelist: !z_bpimagelist_switches!" call :log "...bplist: !z_bplist_switches!" call :log "...bpflist: !z_bpflist_switches!" call :log "...bpverify: !z_bpverify_switches!" call :log "...done..." REM ************************************************************************** REM *** Are we going to have to check all clients... REM *** ...if so, find out how many clients there are in total... call :log "" call :log "Determining how many clients will be searched..." if not "!z_client!"=="" ( call :log "...only one client will be searched, named `!z_client!`..." (echo !z_client!)>"!z_file_cli!" ) else ( if /i "!z_type!"=="client" ( call :log "...client name must be specified when running on a client, script aborting..." goto :end ) call :r_build_clients if /i "!z_quit!"=="yes" goto :end ) call :log "...done..." REM ************************************************************************** REM *** The main section... REM *** ...here we loop around the clients, then loop around the backup images... for /f "tokens=*" %%a in ('type "!z_file_cli!"') do ( set z_client=%%a call :log "" call :log "Listing backups for client `!z_client!`..." set z_image_datetime= call :r_set_switches "!z_bpclimagelist!" !z_bpclimagelist_switches! >"!z_file_bid!" 2>&1 set z_sts=!errorlevel! if not !z_sts!==0 ( call :log "...no backups found, status `!z_sts!`, continuing..." ) else ( call :log "...backups found for client..." for /f "tokens=1,2,3,4,5 skip=2" %%a in ('type "!z_file_bid!"') do ( set z_image_datetime=%%a %%b call :log "...found backup from `!z_image_datetime!`..." call :r_set_switches call :log "......search for files..." if /i "!z_debug!"=="yes" call :log "...DEBUG: bplist !z_bplist_switches!" "!z_bplist!" !z_bplist_switches! >"!z_file_lis!" 2>&1 set z_sts=!errorlevel! if not !z_sts!==0 ( call :log "......no files found..." ) else ( call :txt "" call :txt "********************************************************" call :txt "********************************************************" call :txt "" call :txt "Client: !z_client!" call :log "......listing backup image summary..." "!z_bpclimagelist!" !z_bpclimagelist_switches! -U >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if !z_sts!==0 ( call :txt "" call :txt "" type "!z_file_tmp!" >>"!z_file_txt!" call :txt "" ) else ( call :log "......unexpected unable to list backup summary, status `!z_sts!`, continuing..." ) if /i "!z_type!"=="server" ( call :log "......listing backup image details..." set z_copies=no if /i "!z_debug!"=="yes" call :log "...DEBUG: bpimagelist !z_bpimagelist_switches! -L" "!z_bpimagelist!" !z_bpimagelist_switches! -L >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if !z_sts!==0 ( call :txt "" set z_show=yes for /f "tokens=*" %%a in ('type "!z_file_tmp!"') do ( set z_line=%%a if /i "!z_line:~0,9!"=="histogram" set z_show=no if /i "!z_show!"=="yes" ( echo %%a >>"!z_file_txt!" ) if /i "!z_line:~0,16!"=="number of copies" ( if not "!z_line:~-2!"==" 1" ( set z_copies=yes ) ) ) ) else ( call :log "......unexpected unable to list backup details, status `!z_sts!`, continuing..." if /i "!z_debug!"=="yes" type "!z_file_tmp!" ) ) if /i "!z_type!"=="server" ( call :log "......listing media for backup image, primary copy..." "!z_bpverify!" !z_bpverify_switches! -primary >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if !z_sts!==0 ( call :txt "" call :txt "" call :txt "Primary copy:" type "!z_file_tmp!" >>"!z_file_txt!" ) else ( call :log "......unexpected unable to list media details for primary copy, status `!z_sts!`, continuing..." ) if /i "!z_copies!"=="yes" ( call :log "......listing media for backup image, multiple copies..." for /l %%a in (1,1,10) do ( set z_copy=%%a "!z_bpverify!" !z_bpverify_switches! -cn !z_copy! >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if !z_sts!==0 ( call :txt "" call :txt "Copy number: !z_copy!" type "!z_file_tmp!" >>"!z_file_txt!" ) ) ) ) call :log "......listing files found..." call :txt "" call :txt "" type "!z_file_lis!" >>"!z_file_txt!" call :txt "" ) ) ) call :log "...done client..." ) call :txt "" call :txt "********************************************************" call :txt "********************************************************" REM ************************************************************************** REM *** If we get here, then the script appears to have worked, so clean-up... if exist "!z_file_bid!" del "!z_file_bid!" if exist "!z_file_cli!" del "!z_file_cli!" if exist "!z_file_lis!" del "!z_file_lis!" if exist "!z_file_tmp!" del "!z_file_tmp!" call :log "" call :log "List of files created..." call :log "...report file: !z_file_txt!" call :log "...done..." REM ************************************************************************** REM *** Script failures can jump to this point too... :end set z_script_finished=!date! !time:~0,8! call :log "" call :log "Script exiting..." call :log "...script started: !z_script_started!" call :log "...script finished: !z_script_finished!" echo+ pause exit /b REM ************************************************************************** REM *** Different style switches for different commands... :r_set_switches if "!z_image_datetime!"=="" ( set z_switch_stt=!z_search_stt! set z_switch_end=!z_search_end! ) else ( set z_switch_stt=!z_image_datetime! set z_switch_end=!z_image_datetime! ) set z_bpclimagelist_switches= if not "!z_switch_stt!"=="" set z_bpclimagelist_switches=!z_bpclimagelist_switches! -d !z_switch_stt! if not "!z_switch_end!"=="" set z_bpclimagelist_switches=!z_bpclimagelist_switches! -e !z_switch_end! if not "!z_client!"=="" set z_bpclimagelist_switches=!z_bpclimagelist_switches! -client !z_client! if not "!z_policy!"=="" set z_bpclimagelist_switches=!z_bpclimagelist_switches! -policy !z_policy! if not "!z_policy_type!"=="" set z_bpclimagelist_switches=!z_bpclimagelist_switches! -ct !z_policy_type_number! set z_bpclimagelist_switches=!z_bpclimagelist_switches! -Listseconds set z_bpimagelist_switches= if not "!z_switch_stt!"=="" set z_bpimagelist_switches=!z_bpimagelist_switches! -d !z_switch_stt! if not "!z_switch_end!"=="" set z_bpimagelist_switches=!z_bpimagelist_switches! -e !z_switch_end! if not "!z_client!"=="" set z_bpimagelist_switches=!z_bpimagelist_switches! -client !z_client! if not "!z_policy!"=="" set z_bpimagelist_switches=!z_bpimagelist_switches! -policy !z_policy! if not "!z_policy_type!"=="" set z_bpimagelist_switches=!z_bpimagelist_switches! -pt !z_policy_type! set z_bplist_switches= if not "!z_switch_stt!"=="" set z_bplist_switches=!z_bplist_switches! -s !z_switch_stt! if not "!z_switch_end!"=="" set z_bplist_switches=!z_bplist_switches! -e !z_switch_end! if not "!z_client!"=="" set z_bplist_switches=!z_bplist_switches! -C !z_client! if not "!z_policy!"=="" set z_bplist_switches=!z_bplist_switches! -k !z_policy! if not "!z_policy_type!"=="" set z_bplist_switches=!z_bplist_switches! -t !z_policy_type_number! set z_bplist_switches=!z_bplist_switches! -PI -I -R 999 !z_match! set z_bpflist_switches= if not "!z_switch_stt!"=="" set z_bpflist_switches=!z_bpflist_switches! -d !z_switch_stt! if not "!z_switch_end!"=="" set z_bpflist_switches=!z_bpflist_switches! -e !z_switch_end! if not "!z_client!"=="" set z_bpflist_switches=!z_bpflist_switches! -client !z_client! if not "!z_policy!"=="" set z_bpflist_switches=!z_bpflist_switches! -policy !z_policy! if not "!z_policy_type!"=="" set z_bpflist_switches=!z_bpflist_switches! -pt !z_policy_type! set z_bpflist_switches=!z_bpflist_switches! -option GET_ALL_FILES IGNORE_CASE -rl 999 -pattern !z_match! set z_bpverify_switches= if not "!z_switch_stt!"=="" set z_bpverify_switches=!z_bpverify_switches! -s !z_switch_stt! if not "!z_switch_end!"=="" set z_bpverify_switches=!z_bpverify_switches! -e !z_switch_end! if not "!z_client!"=="" set z_bpverify_switches=!z_bpverify_switches! -client !z_client! if not "!z_policy!"=="" set z_bpverify_switches=!z_bpverify_switches! -policy !z_policy! if not "!z_policy_type!"=="" set z_bpverify_switches=!z_bpverify_switches! -pt !z_policy_type! set z_bpverify_switches=!z_bpverify_switches! -pb goto :eof REM ************************************************************************** REM *** Generate a list of unique client names from backup image names... :r_build_clients call :log "...building list of clients, this may take a few minutes..." set z_quit=no if exist "!z_file_cli!" del "!z_file_cli!" if exist "!z_file_tmp!" del "!z_file_tmp!" set z_my_stt= set z_my_end= if not "!z_search_stt!"=="" set z_my_stt= -d !z_search_stt! if not "!z_search_end!"=="" set z_my_end= -e !z_search_end! set z_build_switches= if not "!z_policy_type!"=="" set z_build_switches=!z_build_switches! -pt !z_policy_type! "!z_bpimagelist!" -idonly !z_my_stt! !z_my_end! !z_build_switches! >"!z_file_tmp!" 2>&1 set z_sts=!errorlevel! if not !z_sts!==0 ( call :log "...quick listing failed, status `!z_sts!`..." call :log "...there are no backups to be found at all, script cannot continue, aborting..." set z_quit=yes goto :eof ) call :log "...counting clients..." set /a z_count=0 set z_client_curr= for /f "tokens=1,2,3,4,5" %%a in ('type "!z_file_tmp!"') do ( set z_client_prev=!z_client_curr! set z_image=%%e set z_client= if "!z_client!"=="" (if "!z_image:~-2,1!"=="_" (set z_client=!z_image:~0,-2!)) if "!z_client!"=="" (if "!z_image:~-3,1!"=="_" (set z_client=!z_image:~0,-3!)) if "!z_client!"=="" (if "!z_image:~-4,1!"=="_" (set z_client=!z_image:~0,-4!)) if "!z_client!"=="" (if "!z_image:~-5,1!"=="_" (set z_client=!z_image:~0,-5!)) if "!z_client!"=="" (if "!z_image:~-6,1!"=="_" (set z_client=!z_image:~0,-6!)) if "!z_client!"=="" (if "!z_image:~-7,1!"=="_" (set z_client=!z_image:~0,-7!)) if "!z_client!"=="" (if "!z_image:~-8,1!"=="_" (set z_client=!z_image:~0,-8!)) if "!z_client!"=="" (if "!z_image:~-9,1!"=="_" (set z_client=!z_image:~0,-9!)) if "!z_client!"=="" (if "!z_image:~-10,1!"=="_" (set z_client=!z_image:~0,-10!)) if "!z_client!"=="" (if "!z_image:~-11,1!"=="_" (set z_client=!z_image:~0,-11!)) if "!z_client!"=="" ( call :log "...uexpected error, was not able to determine client name from image name `!z_image!`, script aborting..." set z_quit=yes goto :end ) set z_client_curr=!z_client! if not "!z_client_curr!"=="!z_client_prev!" ( (echo !z_client_curr!)>>"!z_file_cli!" set /a z_count+=1 ) ) call :log "...found `!z_count!` clients to search through..." goto :eof REM ************************************************************************** REM *** Logging... :log (echo !date! !time:~0,8! %~1) (echo !date! !time:~0,8! %~1)>>"!z_file_log!" goto :eof REM ************************************************************************** REM *** Writing to the report file... :txt if "%~1"=="" ( echo+>>"!z_file_txt!" ) else ( (echo %~1)>>"!z_file_txt!" ) goto :eof