CMDB Data Deletion and Downstream Processes

shane_davis
Tera Expert

We are working on a proof of concept in our SandBox instance and deleting all records from the Base Configuration Item [cmdb] table via the scheduled job below.   This deletion causes all of the background processes to execute and delete all table information downstream from the other tables.   Our issue is that the Service Offering (service_offering) and Business Service (cmdb_ci_service) tables are in this structure and we do NOT want to delete their data.

Does anyone know:

1. How to configure the scheduled job script below to exclude deleting the data in the Service Offering (service_offering) and Business Service (cmdb_ci_service) tables?

2. What behind the scenes actions are taking place when the scheduled job executes which caused the downstream deletions?

doit("cmdb");

function doit(cmdb) {

var gr = new GlideRecord(cmdb);

gr.deleteMultiple();

}

Thank you!

1 ACCEPTED SOLUTION

Alikutty A
Tera Sage

Hi Shane,



For your question 1, You can use the script added. The encoded query prevents deletion of records from business service and service offering CI tables. I believe these classes do not have child CI classes



doit("cmdb_ci");



function doit(cmdb) {


  var gr = new GlideRecord(cmdb);


  gr.addEncodedQuery("sys_class_name!=cmdb_ci_service^sys_class_name!=service_offering");


  gr.deleteMultiple();


}



For your question 2, Once the job starts to run it is assigned to a schedule worker that executes the job as a background process. It will take some time for deletion depending on the number of records you have in the base table. We have used cmdb_ci as the table in query since it is the parent of all tables and has an entry for all child records in it. The record once deleted from cmdb_ci is also deleted from its child CI tables. The additional query added will prevent deletion of these records from the classes which you want to prevent deletion.




Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

4 REPLIES 4

Alikutty A
Tera Sage

Hi Shane,



For your question 1, You can use the script added. The encoded query prevents deletion of records from business service and service offering CI tables. I believe these classes do not have child CI classes



doit("cmdb_ci");



function doit(cmdb) {


  var gr = new GlideRecord(cmdb);


  gr.addEncodedQuery("sys_class_name!=cmdb_ci_service^sys_class_name!=service_offering");


  gr.deleteMultiple();


}



For your question 2, Once the job starts to run it is assigned to a schedule worker that executes the job as a background process. It will take some time for deletion depending on the number of records you have in the base table. We have used cmdb_ci as the table in query since it is the parent of all tables and has an entry for all child records in it. The record once deleted from cmdb_ci is also deleted from its child CI tables. The additional query added will prevent deletion of these records from the classes which you want to prevent deletion.




Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


Alikutty,



        Thank you for your terrific explanation.   I will mark your answer as correct.   For question 2, do you know what the processes are that cause the downstream deletions?   With wiping out our CMDB, we want to make sure there are no tables (like service_offering) outside of the cmdb_ci table structure that would also be impacted.   Again, I appreciate your help very much.



Shane


Shane,



I would like to add couple of other points



1) When a record is deleted, any delete business rules on the related table will be executed.


2) When a record is deleted, all related records in it will be deleted.


3) If there are any child tables for business service or service offering, then data from those tables will also be deleted as we have not included them in the query.



You can apply a filter on cmdb_ci table to view the records that will be deleted. Add filter that says Class is not 'Business Service' and Class is not 'Service Offering' and group by Class column. This will give you a better idea on the CI classes that you will clean up. If you copy the query for above filter, it is exactly same as our query "sys_class_name!=cmdb_ci_service^sys_class_name!=service_offering". So you can guarantee that records from these classes wont be deleted.



Also it is a best practice to take XML backups of records that you require and perform the testing on lower instances before you do it on a production environment.



Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


Alikutty,



      Thank you very much.   This is exactly what I needed.   I appreciate your help.



Shane