Strategy for cleaning up
To give a high level answer to your question, there basically isn’t a way to achieve this completely cleanly with WordPress. The reason for this is that WordPress doesn’t enforce a ‘contract’ for the data structure with its themes or plugins. There’s no way WordPress core can say ‘Plugin, tell me exactly what database tables and fields you use’ so that it could then know exactly what data to move or delete for that plugin. So there’s no way you can know this either in a quick, clean way.
Because of this, cleaning up will always be a manual and imperfect task in WordPress, unless you review the code of your plugins and theme in detail to figure out where the data is and how it’s connected, but this would probably take a long time.
You might remove something that you need, or you might leave behind something you don’t need.
With this in mind, I would suggest making your life as easy as possible. Figure out some goals that are important to you and optimise your time to those. Otherwise you may spend a lot of time to make small changes that don’t actually give you much benefit for your situation.
For example, things you might want to:
- Reduce disk space used
- Reduce size of database
- Decrease page load time
- Decrease server load
- Remove plugins which cause errors
- Remove unused items from Media Library UI
If you get your site in a broken state you may have a huge piece of work to fix it, which is why I’d strongly recommend making a perfect copy, then optimising just the things you actually need to.
How to do transfer in your case
I would recommend firstly doing a complete transfer of your site to a temporary location where you can work on it safely. As you said, dump and restore the whole database, or perhaps use a plugin for transferring sites, copy the entire file system, do the settings updates required to make your site work on a temporary URL. There are lots of resource on how to do this.
Then fix whatever you need to fix and don’t worry about anything else and keep things in a working state. Test often after you make changes and be able to revert easily so you can make small incremental changes, test quickly, go back if it’s broken.
I suggest it a lot, but Query Monitor will get you a good quick view of what’s loaded and when.
Then for other specific goals you can probably find answers here for specific things quickly. E.g. removing unused media items
I hope that’s helpful, and perhaps others will have answers on being able to cleanly remove / optimise other parts of your WordPress install.