Copy all nodes from one material to another?

You can try to make a copy of the Source material, then replace all object slots that have Target material with the Copied material. Then delete Target material and rename Copied material to Target material

import bpy
context = bpy.context

# get materials
source_mat = bpy.data.materials["Source"]
target_mat = bpy.data.materials["Target"]

# make copy
copied_mat = source_mat.copy()

# replace material
for ob in context.scene.objects:
    if ob.type in ('MESH', 'CURVE'):
        if ob.data.materials:
            for slot in ob.material_slots:
                if slot.material.name == "Target":
                    slot.material = copied_mat


# delete initial target material
def purge_materials():
    """Remove materials with 0 users from scene."""
    for me in bpy.data.meshes:
        if not me.users:
            me.materials.clear()

    for material in bpy.data.materials:
        if not material.users:
            bpy.data.materials.remove(material)
            
purge_materials()

# rename copy 
copied_mat.name = "Target"