You may find that under certain conditions duplicate CIs can be created in various dataset and you might find your self in a situation where you need to delete them in bulk but you can't use the SQL back end, AR User Tool or CMDBDIAG. Most data issues can be resolved with an escalation where a qualification takes care of the target data. Deleting CI records in bulk with SQL does not invoke workflow for orphans even with Cascade Delete option on. They must be purged with an API that goes through the AR Server Action Request System and hence invoke workflow related to CMDB data. CMDBDRIVER is that API. Other situations could also have a need for data correction where . For example if you've been importing data from ADDM and all CIs in the interim dataset BMC.ADDM have been deleted, but the MarkAsDeleted flag of Yes has not been propagated (merged) to its matching CI in BMC.ASSET. There is help, but before you proceed, first look up information on Cascade Delete option for Weak Relationships (AtriumCore Class Manager Relationship class) to become familiar with the concept. More on this later in this article. |
This knowledge article may contain information that does not apply to version 21.05 or later which runs in a container environment. Please refer to Article Number 000385088 for more information about troubleshooting BMC products in containers. Legacy ID:KA369464 You can use the CMDBDRIVER program to delete CIs in bulk from the command line using a combination of a SQL statement, shell script and a cmdbdriver command script file. The challenging part is getting the list of duplicate CIs but if you already have a query that will produce a list of dups then you can use that query to extract them into a file. You'll also need to enable Cascade Delete for Weak-type relationships where CI's are hosted. You'd need to do this if you want delete the Computer System CIs and its Hosted Components and Hosted Access Points. As the SQL below shows and you'll need to use the workflow which only works if AR Clients are used such as CMDBDRIVER. Direct deletion from database using SQL commands would leave orphaned CIs behind that would still need to be cleaned later. This query could help, but keep in mind that this SQL will also include duplicated CIs in BMC.ASSET that have the same ReconciliationIdentity (REID). This condition where two CIs in same dataset have same REID is no longer possible after AtriumCore 7604 SP4, however, it may exist from prior versions of the CMDB. SQL Query: select Name,InstanceId from BMC_CORE_BMC_ComputerSystem where ClassId = 'BMC_ComputerSystem' and DatasetId = 'BMC.ASSET' and ReconciliationIdentity NOT IN Results of just the InstanceId list should be put into a file that can be then used to run cmdbriver to delete them sequentially. To delete a CI you must have the file formatted as follows. This is only an example. init term clearcmdb.sh:
#!/bin/sh echo "" echo "Welcome to data clean up script!" echo "This version of the script is for bash shell running in Cygwin in Windows" echo "" echo "Enter the DatasetId where the data clean up will occur:" read dataset echo "" echo "Enter the ClassId where the clean up is about to be done." echo "NOTE: You to need use the actual class container. Not BMC_BaseElement." echo "For example type BMC_Person, or BMC_ComputerSystem etc. " echo "" read class echo "" echo "Here is list of files in this directory:" echo "" ls -l echo "" echo "Enter filename with the list of InstanceId's:" echo "" read deleteme deleteset=`cat $deleteme` echo "init" > deleteset.txt counter=`wc -l $deleteme` echo "" echo "OK. Thank you!" echo "Let's process these $counter entries." echo "" counter=1 sleep 3 for i in $deleteset do echo " " >> deleteset.txt echo "di" >> deleteset.txt echo "Creating entry: $counter" echo "BMC.CORE" >> deleteset.txt #echo "BMC.CORE" echo "$class" >> deleteset.txt #echo "$class" echo "$dataset" >> deleteset.txt #echo "$dataset" echo "$i" >> deleteset.txt #echo "Instance ID to be deleted :$i" echo "2" >> deleteset.txt echo "" >> deleteset.txt counter=`expr $counter + 1` done echo "term" >> deleteset.txt echo "q" >> deleteset.txt export LD_LIBRARY_PATH=`pwd` echo " " echo "Here is your file: " echo " " ls -l deleteset.txt echo " " echo "Now to the actual deleting of CIs!! " echo "" echo "1. Copy the deleteset.txt to \"\$ATRIUMCORE_HOME/cmdb/server/bin\" " echo " " echo "2. Make sure your prompt is in that directory as well and run cmdbriver using this syntax: " echo " " echo "export LD_LIBRARY_PATH=`pwd`" echo "./cmdbdriver -s localhost -u <AR User> -p <AR Password> -t <AR Port> -x deleteset.txt" echo " " echo "Thank you!" echo " " NOTE: BASH (bourne again shell) is a virtual machine shell available with any Linux release but can also be made available by using the CYGWIN install for Windows. This script will need some inputs from a file. You will need a file "deleteme" which would have a list of just instanceIds to be deleted. OI-9b0c38eb12454af2ab5b7c0172b2f6de This list is the export of just the InstanceIds we would want to delete in bulk. The result of running the script would look like this: bash-4.1$ ./clearcmdb.sh Enter the DatasetId where the data clean up will occur: BMC_Person -rwxr-xr-x+ 1 currentuser 947607 Aug 27 13:03 Duplicates.txt Enter filename with the list of InstanceId's: Duplicates.txt OK. Thank you! Creating entry: 1 Here is your file: -rw-r--r--+ 1 currentuser 6598 Aug 27 14:55 deleteset.txt Now to the actual deleting of CIs!! ./cmdbdriver.sh -s localhost -u <AR User> -p <AR Password> -t <AR Port> -x deleteset.txt The rate of deletion will vary. It should be about 40-100 CIs per second. Keep in mind that the cascade delete will take care of the hosted components and endpoints. So, one ComputerSystem deletion results in a sum of all records related to it as well as the relationship themselves. That could be anywhere from few records to hundreds per ComputerSystem instance. What may seem like slow progress is actually a steady pace of records being deleted by workflow and this could take a while to complete. Don't stop or kill the CMDBDRIVER if it is not returning the prompt. It will eventually exit once all records had been processed.
|