There are some other posts on the site that cover the topic of moving a copy of Prod to Test (or some variation), but here’s the script I posted before - TestEnvironment on same server as Production - #7 by MikeGross
There might need to be some tweaks for recent modules - Collaborate, QuickShip, etc…