clone preserve: System Properties and dealing with System Property versions

stevemac
Tera Guru

Like many customers we have environment specific settings stored in System Properties.  These properties are included in Clone Data Preserver rules.

 

Last week we had a problem in one of our non-prods.  Turns out it was a result of an intentional change to one of these properties and then shortly after reverting to the most recent prior version.   We found out the hard way that the System Property version records [in sys_update_version] are not preserved in the clone and therefore are a copy of the clone source.  The most recent version had the value for another instance

 

How do you deal with this?   Is a clone data preserver record safe to use in this case?  Something like

  • Table is Update Versions [sys_update_versions]
  • Type is System Property
  • Record Name starts with {what ever the matching string is}

Not sure the index on sys_update_versions is sufficient and generally concerned about unknown ramifications.

 

Appreciate your input,

 

Steve

 

8 REPLIES 8

The clone is intended to make the target identical (in most respects) to the source instance.  Seems your idea of a cleanup script can achieve your goals. I don't see the value in creating version records for the desired records preserved on the target.

the creating of the version record means we'd have one version record available with the current (preserved) value.   That would enable the ability to revert to a previous version record if we changed the value of the property after a clone

If you change a sys_property record after a clone, you get a 'previous' version record on the instance. You can revert to that version if you don't like the change made.

 

I guess I'm missing something.

Bert_c1
Kilo Patron

@stevemac 

 

After re-reading your posts. Here's a script that will collect the records matching the data preservers present for 'sys_properties' records.  You can use the script in a post clone cleanup script, to delete sys_update_version records matching those sys_properties records.  You can test in scripts background, a 'dry_run' variable is defined so that you can see what records will be deleted when running in scripts background. set dry_run to false in the cleanup script. Use the "Script Log Statements' module after the clone to see what was deleted but searching 'message', 'starts with', '

DeleteSysPropertiesUpdateVersions:'.
var dry_run = true;
var sysPropQuery = [];
var cdp = new GlideRecord('clone_data_preserver');
cdp.addEncodedQuery('include_in_system_clone=true^table=sys_properties');
cdp.query();
while (cdp.next()) {
	sysPropQuery.push(cdp.condition.toString());
}
for (i = 0; i < sysPropQuery.length; i++ ) {
//	gs.info('Conditions: ' + sysPropQuery[i]);
}

// now get the sys_id for each record to create a version for
var sp = new GlideRecord('sys_properties');
var sysIds = [];
var recXML = [];	// for creating udate version records if needed
for (i = 0; i < sysPropQuery.length; i++ ) {
	var sp = new GlideRecord('sys_properties');
	sp.addEncodedQuery(sysPropQuery[i]);
	sp.query();
	while (sp.next()) {
		sysIds.push(sp.sys_id.toString());
//		gs.info('sys_properties name: ' + sp.name);
	}
}

// Check update version records
for (i = 0; i < sysIds.length; i++) {
//	gs.info('sys_properties_' + sysIds[i]);
	var suv = new GlideRecord('sys_update_version');
	suv.addQuery('name', 'sys_properties_' + sysIds[i]);
	suv.query();
	gs.info('DeleteSysPropertiesUpdateVersions: Found ' + suv.getRowCount() + ' update versions for sys_properties_' + sysIds[i]);
	if (!dry_run)
		suv.deleteMultiple();
}

I do not believe you need to re-create any version records in the target instance, as if one of those sys_properties records is updated after a clone, a new version record should be created reflecting the record's prior value. If not, then create a Support Case to understand why you don't get a version record when updating a sys_properties record.

 

[I did try logic to create sys_update_version records for the processed sys_properties records, but found myself going down a rathole it seemed. If you think you need this, I'll post that logic.]