Create temporary exact copy of scene for manipulation in code

I am creating a custom exporter and there are times where I need to do things that will affect the object in the scene, such as setting an objects animation_data.action and then running through all the frames to get the bone transforms for exporting animations.
The problem with doing that on the scene itself is all the objects seem to go crazy depending on the actions.

I am currently looking through the FBX binary exporter and I see this area for the animations.

def fbx_animations(scene_data):
    #....Some code here.....


    def restore_object(ob_to, ob_from):
        # Restore org state of object (ugh :/ ).
        #....Some code here.....
                
    for ob_obj in scene_data.objects:
        
        #....Some code here.....
        
        # We can't play with animdata and actions and get back to org state easily.
        # So we have to add a temp copy of the object to the scene, animate it, and remove it... :/
        ob_copy = ob.copy()
        # Great, have to handle bones as well if needed...
        pbones_matrices = [pbo.matrix_basis.copy() for pbo in ob.pose.bones] if ob.type == 'ARMATURE' else ...


        #....Some code here.....


        for act in bpy.data.actions:
        
            #....Set frames and record transformations.....
            
            # Ugly! :/
            if pbones_matrices is not ...:
                for pbo, mat in zip(ob.pose.bones, pbones_matrices):
                    pbo.matrix_basis = mat.copy()
            ob.animation_data.action = None if org_act is ... else org_act
            restore_object(ob, ob_copy)


        if pbones_matrices is not ...:
            for pbo, mat in zip(ob.pose.bones, pbones_matrices):
                pbo.matrix_basis = mat.copy()
        if org_act is ...:
            ob.animation_data_clear()
        else:
            ob.animation_data.action = org_act


        bpy.data.objects.remove(ob_copy)

It seems that the direction this code takes is to copy all the data, manipulate the object, and then try your best to restore it. It also seems that whoever coded this is very unhappy with having to do this, expressed by their notes lol.

There is also the use of the object.dupli_list_create method, which I am not too sure as to what that is used for.

I dont even know how to properly copy an object since as far as I know I would need to use deepcopy, but blender seems to just have copy, which means I’d need to go through each object within objects and copy those as well.

Is there not a simpler/safer way to handle this? I do not want to risk screwing up the whole scene T.T