Copying entities between DBs while maintaining relationships

I would recommend that you always have some kind of external ID for entities in you system.
Once you have this, you can do what you describe by ensuring that the new entities you ‘copy’ over include the correct references via the external ID, not the entity ID.